-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.s
355 lines (355 loc) · 5.96 KB
/
main2.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
.file "main.c"
.intel_syntax noprefix
.text
.globl S
.bss
.align 32
.type S, @object
.size S, 1000000
S:
.zero 1000000
.globl EX
.align 32
.type EX, @object
.size EX, 1000
EX:
.zero 1000
.section .rodata
.LC0:
.string "w"
.LC1:
.string "random_input.txt"
.align 8
.LC2:
.string "Random input was generated and is in file \"random_input.txt\""
.align 8
.LC3:
.string "Random substring was generated: "
.LC4:
.string "random_output.txt"
.align 8
.LC5:
.string "The result is in file \"random_output.txt\""
.align 8
.LC6:
.string "size of string to find is too big"
.LC7:
.string "r"
.LC8:
.string "Wrong filename"
.LC9:
.string "output.txt"
.LC10:
.string "size of input is too big"
.LC11:
.string "%d"
.LC12:
.string "Working time: %ld ms\n"
.text
.globl main
.type main, @function
main:
endbr64
push rbp
mov rbp, rsp
push rbx
sub rsp, 88
mov DWORD PTR -84[rbp], edi
mov QWORD PTR -96[rbp], rsi
cmp DWORD PTR -84[rbp], 1
jne .L2
lea rax, .LC0[rip]
mov rsi, rax
lea rax, .LC1[rip]
mov rdi, rax
call fopen@PLT
mov QWORD PTR -24[rbp], rax
mov DWORD PTR -36[rbp], 1000000
mov DWORD PTR -48[rbp], 0
jmp .L3
.L4:
call rand@PLT
movsx rbx, eax
call clock@PLT
add rax, rbx
cqo
shr rdx, 59
add rax, rdx
and eax, 31
sub rax, rdx
add eax, 32
mov ecx, eax
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, S[rip]
mov BYTE PTR [rax+rdx], cl
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, S[rip]
movzx eax, BYTE PTR [rax+rdx]
movsx eax, al
mov rdx, QWORD PTR -24[rbp]
mov rsi, rdx
mov edi, eax
call fputc@PLT
add DWORD PTR -48[rbp], 1
.L3:
mov eax, DWORD PTR -48[rbp]
cmp eax, DWORD PTR -36[rbp]
jl .L4
lea rax, .LC2[rip]
mov rdi, rax
call puts@PLT
call rand@PLT
movsx rbx, eax
call clock@PLT
lea rcx, [rbx+rax]
movabs rdx, 7378697629483820647
mov rax, rcx
imul rdx
mov rax, rdx
sar rax
mov rdx, rcx
sar rdx, 63
sub rax, rdx
mov rdx, rax
sal rdx, 2
add rdx, rax
mov rax, rcx
sub rax, rdx
add eax, 1
mov DWORD PTR -40[rbp], eax
lea rax, .LC3[rip]
mov rdi, rax
mov eax, 0
call printf@PLT
mov DWORD PTR -48[rbp], 0
jmp .L5
.L6:
call rand@PLT
movsx rbx, eax
call clock@PLT
add rax, rbx
cqo
shr rdx, 59
add rax, rdx
and eax, 31
sub rax, rdx
add eax, 32
mov ecx, eax
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, EX[rip]
mov BYTE PTR [rax+rdx], cl
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, EX[rip]
movzx eax, BYTE PTR [rax+rdx]
movsx eax, al
mov edi, eax
call putchar@PLT
add DWORD PTR -48[rbp], 1
.L5:
mov eax, DWORD PTR -48[rbp]
cmp eax, DWORD PTR -40[rbp]
jl .L6
mov edi, 10
call putchar@PLT
lea rax, .LC0[rip]
mov rsi, rax
lea rax, .LC4[rip]
mov rdi, rax
call fopen@PLT
mov QWORD PTR -32[rbp], rax
lea rax, .LC5[rip]
mov rdi, rax
call puts@PLT
jmp .L7
.L2:
cmp DWORD PTR -84[rbp], 999
jle .L8
lea rax, .LC6[rip]
mov rdi, rax
call puts@PLT
mov eax, 1
jmp .L9
.L8:
mov rax, QWORD PTR -96[rbp]
add rax, 8
mov rax, QWORD PTR [rax]
lea rdx, .LC7[rip]
mov rsi, rdx
mov rdi, rax
call fopen@PLT
mov QWORD PTR -24[rbp], rax
cmp QWORD PTR -24[rbp], 0
jne .L10
lea rax, .LC8[rip]
mov rdi, rax
call puts@PLT
mov eax, 1
jmp .L9
.L10:
lea rax, .LC0[rip]
mov rsi, rax
lea rax, .LC9[rip]
mov rdi, rax
call fopen@PLT
mov QWORD PTR -32[rbp], rax
mov DWORD PTR -48[rbp], 2
jmp .L11
.L16:
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, 0[0+rax*8]
mov rax, QWORD PTR -96[rbp]
add rax, rdx
mov rax, QWORD PTR [rax]
mov rdi, rax
call strlen@PLT
mov DWORD PTR -56[rbp], eax
mov DWORD PTR -52[rbp], 0
jmp .L12
.L14:
cmp DWORD PTR -40[rbp], 1000
jne .L13
lea rax, .LC6[rip]
mov rdi, rax
call puts@PLT
mov eax, 1
jmp .L9
.L13:
mov eax, DWORD PTR -48[rbp]
cdqe
lea rdx, 0[0+rax*8]
mov rax, QWORD PTR -96[rbp]
add rax, rdx
mov rdx, QWORD PTR [rax]
mov eax, DWORD PTR -52[rbp]
cdqe
add rax, rdx
movzx edx, BYTE PTR [rax]
mov eax, DWORD PTR -40[rbp]
cdqe
lea rcx, EX[rip]
mov BYTE PTR [rax+rcx], dl
add DWORD PTR -40[rbp], 1
add DWORD PTR -52[rbp], 1
.L12:
mov eax, DWORD PTR -52[rbp]
cmp eax, DWORD PTR -56[rbp]
jl .L14
cmp DWORD PTR -40[rbp], 999
jg .L15
mov eax, DWORD PTR -84[rbp]
sub eax, 1
cmp DWORD PTR -48[rbp], eax
je .L15
mov eax, DWORD PTR -40[rbp]
cdqe
lea rdx, EX[rip]
mov BYTE PTR [rax+rdx], 32
add DWORD PTR -40[rbp], 1
.L15:
add DWORD PTR -48[rbp], 1
.L11:
mov eax, DWORD PTR -48[rbp]
cmp eax, DWORD PTR -84[rbp]
jl .L16
mov DWORD PTR -36[rbp], 0
jmp .L17
.L18:
mov eax, DWORD PTR -52[rbp]
mov ecx, eax
mov eax, DWORD PTR -36[rbp]
cdqe
lea rdx, S[rip]
mov BYTE PTR [rax+rdx], cl
add DWORD PTR -36[rbp], 1
cmp DWORD PTR -36[rbp], 1000000
jne .L17
lea rax, .LC10[rip]
mov rdi, rax
call puts@PLT
mov eax, 1
jmp .L9
.L17:
cmp DWORD PTR -36[rbp], 999999
jg .L7
mov rax, QWORD PTR -24[rbp]
mov rdi, rax
call fgetc@PLT
mov DWORD PTR -52[rbp], eax
cmp DWORD PTR -52[rbp], -1
jne .L18
.L7:
call clock@PLT
mov QWORD PTR -64[rbp], rax
mov DWORD PTR -48[rbp], 0
jmp .L19
.L20:
mov edx, DWORD PTR -40[rbp]
mov eax, DWORD PTR -36[rbp]
mov esi, edx
mov edi, eax
call find_substring@PLT
mov DWORD PTR -44[rbp], eax
add DWORD PTR -48[rbp], 1
.L19:
cmp DWORD PTR -48[rbp], 999
jle .L20
call clock@PLT
mov QWORD PTR -72[rbp], rax
mov edx, DWORD PTR -44[rbp]
mov rax, QWORD PTR -32[rbp]
lea rcx, .LC11[rip]
mov rsi, rcx
mov rdi, rax
mov eax, 0
call fprintf@PLT
mov rax, QWORD PTR -32[rbp]
mov rdi, rax
call fclose@PLT
mov rax, QWORD PTR -24[rbp]
mov rdi, rax
call fclose@PLT
mov rax, QWORD PTR -72[rbp]
sub rax, QWORD PTR -64[rbp]
mov rcx, rax
movabs rdx, 2361183241434822607
mov rax, rcx
imul rdx
mov rax, rdx
sar rax, 7
sar rcx, 63
mov rdx, rcx
sub rax, rdx
mov rsi, rax
lea rax, .LC12[rip]
mov rdi, rax
mov eax, 0
call printf@PLT
mov eax, 0
.L9:
mov rbx, QWORD PTR -8[rbp]
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4: