-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.ll
More file actions
325 lines (276 loc) · 7.44 KB
/
Copy pathExample.ll
File metadata and controls
325 lines (276 loc) · 7.44 KB
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
@.LS_vtable = global [4 x i8*] [
i8* bitcast (i32 (i8* , i32)* @LS.Start to i8*),
i8* bitcast (i32 (i8* )* @LS.Print to i8*),
i8* bitcast (i32 (i8* , i32)* @LS.Search to i8*),
i8* bitcast (i32 (i8* , i32)* @LS.Init to i8*)
]
@.LinearSearch_vtable = global [0 x i8*] [
]
declare i8* @calloc(i32, i32)
declare i32 @printf(i8*, ...)
declare void @exit(i32)
@_cint = constant [4 x i8] c"%d\0a\00"
@_cOOB = constant [15 x i8] c"Out of bounds\0a\00"
define void @print_int(i32 %i) {
%_str = bitcast [4 x i8]* @_cint to i8*
call i32 (i8*, ...) @printf(i8* %_str, i32 %i)
ret void
}
define void @throw_oob() {
%_str = bitcast [15 x i8]* @_cOOB to i8*
call i32 (i8*, ...) @printf(i8* %_str)
call void @exit(i32 1)
ret void
}
define i32 @main() {
%_0 = call i8* @calloc(i32 1, i32 20)
%_1 = bitcast i8* %_0 to i8***
%_2 = getelementptr [4 x i8*], [4 x i8*]* @.LS_vtable, i32 0, i32 0
store i8** %_2, i8*** %_1
%_3 = bitcast i8* %_0 to i8***
%_4 = load i8**, i8*** %_3
%_5 = getelementptr i8*, i8** %_4, i32 0
%_6 = load i8*, i8** %_5
%_7 = bitcast i8* %_6 to i32(i8*, i32)*
%_8 = call i32 %_7(i8* %_0, i32 10)
call void (i32) @print_int(i32 %_8)
ret i32 0
}
define i32 @LS.Start(i8* %this, i32 %.sz) {
%sz = alloca i32
store i32 %.sz, i32* %sz
%aux01 = alloca i32
%aux02 = alloca i32
%_9 = bitcast i8* %this to i8***
%_10 = load i8**, i8*** %_9
%_11 = getelementptr i8*, i8** %_10, i32 3
%_12 = load i8*, i8** %_11
%_13 = bitcast i8* %_12 to i32(i8*, i32)*
%_15 = load i32, i32* %sz
%_14 = call i32 %_13(i8* %this, i32 %_15)
store i32 %_14, i32* %aux01
%_16 = bitcast i8* %this to i8***
%_17 = load i8**, i8*** %_16
%_18 = getelementptr i8*, i8** %_17, i32 1
%_19 = load i8*, i8** %_18
%_20 = bitcast i8* %_19 to i32(i8*)*
%_21 = call i32 %_20(i8* %this)
store i32 %_21, i32* %aux02
call void (i32) @print_int(i32 9999)
%_22 = bitcast i8* %this to i8***
%_23 = load i8**, i8*** %_22
%_24 = getelementptr i8*, i8** %_23, i32 2
%_25 = load i8*, i8** %_24
%_26 = bitcast i8* %_25 to i32(i8*, i32)*
%_27 = call i32 %_26(i8* %this, i32 8)
call void (i32) @print_int(i32 %_27)
%_28 = bitcast i8* %this to i8***
%_29 = load i8**, i8*** %_28
%_30 = getelementptr i8*, i8** %_29, i32 2
%_31 = load i8*, i8** %_30
%_32 = bitcast i8* %_31 to i32(i8*, i32)*
%_33 = call i32 %_32(i8* %this, i32 12)
call void (i32) @print_int(i32 %_33)
%_34 = bitcast i8* %this to i8***
%_35 = load i8**, i8*** %_34
%_36 = getelementptr i8*, i8** %_35, i32 2
%_37 = load i8*, i8** %_36
%_38 = bitcast i8* %_37 to i32(i8*, i32)*
%_39 = call i32 %_38(i8* %this, i32 17)
call void (i32) @print_int(i32 %_39)
%_40 = bitcast i8* %this to i8***
%_41 = load i8**, i8*** %_40
%_42 = getelementptr i8*, i8** %_41, i32 2
%_43 = load i8*, i8** %_42
%_44 = bitcast i8* %_43 to i32(i8*, i32)*
%_45 = call i32 %_44(i8* %this, i32 50)
call void (i32) @print_int(i32 %_45)
ret i32 55
}
define i32 @LS.Print(i8* %this) {
%j = alloca i32
store i32 1, i32* %j
br label %loop0
loop0:
%_46 = load i32, i32* %j
%_47 = getelementptr i8, i8* %this, i32 16
%_48 = bitcast i8* %_47 to i32*
%_49 = load i32, i32* %_48
%_50 = icmp slt i32 %_46, %_49
br i1 %_50, label %loop1, label %loop2
loop1:
%_56 = getelementptr i8, i8* %this, i32 8
%_57 = bitcast i8* %_56 to i32**
%_58 = load i32*, i32** %_57
%_59 = load i32, i32* %j
%_51 = load i32, i32* %_58
%_53 = icmp ult i32 %_59, %_51
br i1 %_53, label %oob0, label %oob1
oob0:
%_52 = add i32 %_59, 1
%_54 = getelementptr i32, i32* %_58, i32 %_52
%_55 = load i32, i32* %_54
br label %oob2
oob1:
call void @throw_oob()
br label %oob2
oob2:
call void (i32) @print_int(i32 %_55)
%_60 = load i32, i32* %j
%_61 = add i32 %_60, 1
store i32 %_61, i32* %j
br label %loop0
loop2:
ret i32 0
}
define i32 @LS.Search(i8* %this, i32 %.num) {
%num = alloca i32
store i32 %.num, i32* %num
%j = alloca i32
%ls01 = alloca i1
%ifound = alloca i32
%aux01 = alloca i32
%aux02 = alloca i32
%nt = alloca i32
store i32 1, i32* %j
store i1 0, i1* %ls01
store i32 0, i32* %ifound
br label %loop3
loop3:
%_62 = load i32, i32* %j
%_63 = getelementptr i8, i8* %this, i32 16
%_64 = bitcast i8* %_63 to i32*
%_65 = load i32, i32* %_64
%_66 = icmp slt i32 %_62, %_65
br i1 %_66, label %loop4, label %loop5
loop4:
%_72 = getelementptr i8, i8* %this, i32 8
%_73 = bitcast i8* %_72 to i32**
%_74 = load i32*, i32** %_73
%_75 = load i32, i32* %j
%_67 = load i32, i32* %_74
%_69 = icmp ult i32 %_75, %_67
br i1 %_69, label %oob3, label %oob4
oob3:
%_68 = add i32 %_75, 1
%_70 = getelementptr i32, i32* %_74, i32 %_68
%_71 = load i32, i32* %_70
br label %oob5
oob4:
call void @throw_oob()
br label %oob5
oob5:
store i32 %_71, i32* %aux01
%_76 = load i32, i32* %num
%_77 = add i32 %_76, 1
store i32 %_77, i32* %aux02
%_78 = load i32, i32* %aux01
%_79 = load i32, i32* %num
%_80 = icmp slt i32 %_78, %_79
br i1 %_80, label %if0, label %if1
if0:
store i32 0, i32* %nt
br label %if2
if1:
%_81 = load i32, i32* %aux01
%_82 = load i32, i32* %aux02
%_83 = icmp slt i32 %_81, %_82
%_84 = xor i1 1, %_83
br i1 %_84, label %if3, label %if4
if3:
store i32 0, i32* %nt
br label %if5
if4:
store i1 1, i1* %ls01
store i32 1, i32* %ifound
%_85 = getelementptr i8, i8* %this, i32 16
%_86 = bitcast i8* %_85 to i32*
%_87 = load i32, i32* %_86
store i32 %_87, i32* %j
br label %if5
if5:
br label %if2
if2:
%_88 = load i32, i32* %j
%_89 = add i32 %_88, 1
store i32 %_89, i32* %j
br label %loop3
loop5:
%_90 = load i32, i32* %ifound
ret i32 %_90
}
define i32 @LS.Init(i8* %this, i32 %.sz) {
%sz = alloca i32
store i32 %.sz, i32* %sz
%j = alloca i32
%k = alloca i32
%aux01 = alloca i32
%aux02 = alloca i32
%_91 = getelementptr i8, i8* %this, i32 16
%_92 = bitcast i8* %_91 to i32*
%_93 = load i32, i32* %sz
store i32 %_93, i32* %_92
%_94 = getelementptr i8, i8* %this, i32 8
%_95 = bitcast i8* %_94 to i32**
%_100 = load i32, i32* %sz
%_96 = icmp slt i32 %_100, 0
br i1 %_96, label %arr_alloc0, label %arr_alloc1
arr_alloc0:
call void @throw_oob()
br label %arr_alloc1
arr_alloc1:
%_97 = add i32 %_100, 1
%_98 = call i8* @calloc(i32 4, i32 %_97)
%_99 = bitcast i8* %_98 to i32*
store i32 %_100, i32* %_99
store i32* %_99, i32** %_95
store i32 1, i32* %j
%_101 = getelementptr i8, i8* %this, i32 16
%_102 = bitcast i8* %_101 to i32*
%_103 = load i32, i32* %_102
%_104 = add i32 %_103, 1
store i32 %_104, i32* %k
br label %loop6
loop6:
%_105 = load i32, i32* %j
%_106 = getelementptr i8, i8* %this, i32 16
%_107 = bitcast i8* %_106 to i32*
%_108 = load i32, i32* %_107
%_109 = icmp slt i32 %_105, %_108
br i1 %_109, label %loop7, label %loop8
loop7:
%_110 = load i32, i32* %j
%_111 = mul i32 2, %_110
store i32 %_111, i32* %aux01
%_112 = load i32, i32* %k
%_113 = sub i32 %_112, 3
store i32 %_113, i32* %aux02
%_118 = getelementptr i8, i8* %this, i32 8
%_119 = bitcast i8* %_118 to i32**
%_120 = load i32*, i32** %_119
%_121 = load i32, i32* %j
%_114 = load i32, i32* %_120
%_115 = icmp ult i32 %_121, %_114
br i1 %_115, label %oob6, label %oob7
oob6:
%_122 = load i32, i32* %aux01
%_123 = load i32, i32* %aux02
%_124 = add i32 %_122, %_123
%_116 = add i32 %_121, 1
%_117 = getelementptr i32, i32* %_120, i32 %_116
store i32 %_124, i32* %_117
br label %oob8
oob7:
call void @throw_oob()
br label %oob8
oob8:
%_125 = load i32, i32* %j
%_126 = add i32 %_125, 1
store i32 %_126, i32* %j
%_127 = load i32, i32* %k
%_128 = sub i32 %_127, 1
store i32 %_128, i32* %k
br label %loop6
loop8:
ret i32 0
}