1 ; RUN: llvm-as < %s | opt -instcombine -disable-output
3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
4 target triple = "i686-apple-darwin8"
5 %struct.ZZIP_FILE = type { %struct.zzip_dir*, i32, i32, i32, i32, i32, i32, i64, i8*, i64, %struct.z_stream, %struct.zzip_plugin_io* }
6 %struct.anon = type { %struct.ZZIP_FILE*, i8* }
7 %struct.internal_state = type { i32 }
8 %struct.z_stream = type { i8*, i32, i32, i8*, i32, i32, i8*, %struct.internal_state*, i8* (i8*, i32, i32)*, void (i8*, i8*)*, i8*, i32, i32, i32 }
9 %struct.zzip_dir = type { i32, i32, i32, %struct.anon, %struct.zzip_dir_hdr*, %struct.zzip_dir_hdr*, %struct.ZZIP_FILE*, %struct.zzip_dirent, i8*, i8*, i8**, %struct.zzip_plugin_io* }
10 %struct.zzip_dir_hdr = type { i32, i32, i32, i32, i16, i16, i8, i16, [1 x i8] }
11 %struct.zzip_dirent = type { i32, i32, i32, i16, i8*, i32, i32 }
12 %struct.zzip_plugin_io = type { i32 (i8*, i32, ...)*, i32 (i32)*, i32 (i32, i8*, i32)*, i64 (i32, i64, i32)*, i64 (i32)*, i32 }
14 define %struct.ZZIP_FILE* @zzip_open_shared_io(%struct.ZZIP_FILE* %stream, i8* %filename, i32 %o_flags, i32 %o_modes, i8** %ext, %struct.zzip_plugin_io* %io) {
16 %basename = alloca [1024 x i8], align 16 ; <[1024 x i8]*> [#uses=5]
17 %e = alloca i32, align 4 ; <i32*> [#uses=4]
18 icmp eq %struct.ZZIP_FILE* %stream, null ; <i1>:0 [#uses=1]
19 br i1 %0, label %cond_next22, label %cond_true
21 cond_true: ; preds = %entry
22 %tmp3 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
23 %tmp4 = load %struct.zzip_dir** %tmp3 ; <%struct.zzip_dir*> [#uses=1]
24 icmp eq %struct.zzip_dir* %tmp4, null ; <i1>:1 [#uses=1]
25 br i1 %1, label %cond_next22, label %cond_true5
27 cond_true5: ; preds = %cond_true
28 icmp eq i8** %ext, null ; <i1>:2 [#uses=1]
29 br i1 %2, label %cond_true7, label %cond_next
31 cond_true7: ; preds = %cond_true5
32 %tmp9 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
33 %tmp10 = load %struct.zzip_dir** %tmp9 ; <%struct.zzip_dir*> [#uses=1]
34 %tmp11 = getelementptr %struct.zzip_dir* %tmp10, i32 0, i32 10 ; <i8***> [#uses=1]
35 %tmp12 = load i8*** %tmp11 ; <i8**> [#uses=1]
38 cond_next: ; preds = %cond_true7, %cond_true5
39 %ext_addr.0 = phi i8** [ %ext, %cond_true5 ], [ %tmp12, %cond_true7 ] ; <i8**> [#uses=2]
40 icmp eq %struct.zzip_plugin_io* %io, null ; <i1>:3 [#uses=1]
41 br i1 %3, label %cond_true14, label %cond_next22
43 cond_true14: ; preds = %cond_next
44 %tmp16 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
45 %tmp17 = load %struct.zzip_dir** %tmp16 ; <%struct.zzip_dir*> [#uses=1]
46 %tmp18 = getelementptr %struct.zzip_dir* %tmp17, i32 0, i32 11 ; <%struct.zzip_plugin_io**> [#uses=1]
47 %tmp19 = load %struct.zzip_plugin_io** %tmp18 ; <%struct.zzip_plugin_io*> [#uses=1]
50 cond_next22: ; preds = %cond_true14, %cond_next, %cond_true, %entry
51 %io_addr.0 = phi %struct.zzip_plugin_io* [ %io, %entry ], [ %io, %cond_true ], [ %io, %cond_next ], [ %tmp19, %cond_true14 ] ; <%struct.zzip_plugin_io*> [#uses=2]
52 %ext_addr.1 = phi i8** [ %ext, %entry ], [ %ext, %cond_true ], [ %ext_addr.0, %cond_next ], [ %ext_addr.0, %cond_true14 ] ; <i8**> [#uses=2]
53 icmp eq %struct.zzip_plugin_io* %io_addr.0, null ; <i1>:4 [#uses=1]
54 br i1 %4, label %cond_true24, label %cond_next26
56 cond_true24: ; preds = %cond_next22
57 %tmp25 = call %struct.zzip_plugin_io* @zzip_get_default_io( ) ; <%struct.zzip_plugin_io*> [#uses=1]
60 cond_next26: ; preds = %cond_true24, %cond_next22
61 %io_addr.1 = phi %struct.zzip_plugin_io* [ %io_addr.0, %cond_next22 ], [ %tmp25, %cond_true24 ] ; <%struct.zzip_plugin_io*> [#uses=4]
62 %tmp28 = and i32 %o_modes, 81920 ; <i32> [#uses=1]
63 icmp eq i32 %tmp28, 0 ; <i1>:5 [#uses=1]
64 br i1 %5, label %try_real, label %try_zzip
66 try_real: ; preds = %bb223, %cond_next26
67 %fd160.2 = phi i32 [ undef, %cond_next26 ], [ %fd160.0, %bb223 ] ; <i32> [#uses=1]
68 %len.2 = phi i32 [ undef, %cond_next26 ], [ %len.0, %bb223 ] ; <i32> [#uses=1]
69 %o_flags_addr.1 = phi i32 [ %o_flags, %cond_next26 ], [ %o_flags_addr.0, %bb223 ] ; <i32> [#uses=2]
70 %tmp33348 = and i32 %o_modes, 262144 ; <i32> [#uses=1]
71 icmp eq i32 %tmp33348, 0 ; <i1>:6 [#uses=1]
72 br i1 %6, label %cond_next38, label %cond_true35
74 cond_true35: ; preds = %try_real
75 %tmp36 = call %struct.zzip_plugin_io* @zzip_get_default_io( ) ; <%struct.zzip_plugin_io*> [#uses=1]
78 cond_next38: ; preds = %cond_true35, %try_real
79 %iftmp.21.0 = phi %struct.zzip_plugin_io* [ %tmp36, %cond_true35 ], [ %io_addr.1, %try_real ] ; <%struct.zzip_plugin_io*> [#uses=3]
80 %tmp41 = getelementptr %struct.zzip_plugin_io* %iftmp.21.0, i32 0, i32 0 ; <i32 (i8*, i32, ...)**> [#uses=1]
81 %tmp42 = load i32 (i8*, i32, ...)** %tmp41 ; <i32 (i8*, i32, ...)*> [#uses=1]
82 %tmp45 = call i32 (i8*, i32, ...)* %tmp42( i8* %filename, i32 %o_flags_addr.1 ) ; <i32> [#uses=3]
83 icmp eq i32 %tmp45, -1 ; <i1>:7 [#uses=1]
84 br i1 %7, label %cond_next67, label %cond_true47
86 cond_true47: ; preds = %cond_next38
87 %tmp48 = call i8* @cli_calloc( i32 1, i32 108 ) ; <i8*> [#uses=2]
88 %tmp4849 = bitcast i8* %tmp48 to %struct.ZZIP_FILE* ; <%struct.ZZIP_FILE*> [#uses=3]
89 icmp eq i8* %tmp48, null ; <i1>:8 [#uses=1]
90 br i1 %8, label %cond_true51, label %cond_next58
92 cond_true51: ; preds = %cond_true47
93 %tmp53 = getelementptr %struct.zzip_plugin_io* %iftmp.21.0, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
94 %tmp54 = load i32 (i32)** %tmp53 ; <i32 (i32)*> [#uses=1]
95 %tmp56 = call i32 %tmp54( i32 %tmp45 ) ; <i32> [#uses=0]
96 ret %struct.ZZIP_FILE* null
98 cond_next58: ; preds = %cond_true47
99 %tmp60 = getelementptr %struct.ZZIP_FILE* %tmp4849, i32 0, i32 1 ; <i32*> [#uses=1]
100 store i32 %tmp45, i32* %tmp60
101 %tmp63 = getelementptr %struct.ZZIP_FILE* %tmp4849, i32 0, i32 11 ; <%struct.zzip_plugin_io**> [#uses=1]
102 store %struct.zzip_plugin_io* %iftmp.21.0, %struct.zzip_plugin_io** %tmp63
103 ret %struct.ZZIP_FILE* %tmp4849
105 cond_next67: ; preds = %cond_next38
106 %tmp70716 = and i32 %o_modes, 16384 ; <i32> [#uses=1]
107 icmp eq i32 %tmp70716, 0 ; <i1>:9 [#uses=1]
108 br i1 %9, label %try_zzip, label %return
110 try_zzip: ; preds = %cond_next67, %cond_next26
111 %fd160.3 = phi i32 [ %fd160.2, %cond_next67 ], [ undef, %cond_next26 ] ; <i32> [#uses=6]
112 %len.3 = phi i32 [ %len.2, %cond_next67 ], [ undef, %cond_next26 ] ; <i32> [#uses=3]
113 %o_flags_addr.3 = phi i32 [ %o_flags_addr.1, %cond_next67 ], [ %o_flags, %cond_next26 ] ; <i32> [#uses=4]
114 %tmp76 = and i32 %o_flags_addr.3, 513 ; <i32> [#uses=1]
115 icmp eq i32 %tmp76, 0 ; <i1>:10 [#uses=1]
116 br i1 %10, label %cond_next80, label %cond_true77
118 cond_true77: ; preds = %try_zzip
119 %tmp78 = call i32* @__error( ) ; <i32*> [#uses=1]
120 store i32 22, i32* %tmp78
121 ret %struct.ZZIP_FILE* null
123 cond_next80: ; preds = %try_zzip
124 %tmp83844 = and i32 %o_flags_addr.3, 2 ; <i32> [#uses=1]
125 icmp eq i32 %tmp83844, 0 ; <i1>:11 [#uses=1]
126 %tmp87 = xor i32 %o_flags_addr.3, 2 ; <i32> [#uses=1]
127 %o_flags_addr.0 = select i1 %11, i32 %o_flags_addr.3, i32 %tmp87 ; <i32> [#uses=2]
128 %basename90 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
129 %tmp92 = call i8* @strcpy( i8* %basename90, i8* %filename ) ; <i8*> [#uses=0]
130 icmp eq %struct.ZZIP_FILE* %stream, null ; <i1>:12 [#uses=1]
131 br i1 %12, label %bb219, label %cond_true94
133 cond_true94: ; preds = %cond_next80
134 %tmp96 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
135 %tmp97 = load %struct.zzip_dir** %tmp96 ; <%struct.zzip_dir*> [#uses=1]
136 icmp eq %struct.zzip_dir* %tmp97, null ; <i1>:13 [#uses=1]
137 br i1 %13, label %bb219, label %cond_true98
139 cond_true98: ; preds = %cond_true94
140 %tmp100 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
141 %tmp101 = load %struct.zzip_dir** %tmp100 ; <%struct.zzip_dir*> [#uses=1]
142 %tmp102 = getelementptr %struct.zzip_dir* %tmp101, i32 0, i32 9 ; <i8**> [#uses=1]
143 %tmp103 = load i8** %tmp102 ; <i8*> [#uses=1]
144 icmp eq i8* %tmp103, null ; <i1>:14 [#uses=1]
145 br i1 %14, label %bb219, label %cond_true104
147 cond_true104: ; preds = %cond_true98
148 %tmp106 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
149 %tmp107 = load %struct.zzip_dir** %tmp106 ; <%struct.zzip_dir*> [#uses=1]
150 %tmp108 = getelementptr %struct.zzip_dir* %tmp107, i32 0, i32 9 ; <i8**> [#uses=1]
151 %tmp109 = load i8** %tmp108 ; <i8*> [#uses=1]
152 %tmp110 = call i32 @strlen( i8* %tmp109 ) ; <i32> [#uses=7]
153 %tmp112 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
154 %tmp113 = load %struct.zzip_dir** %tmp112 ; <%struct.zzip_dir*> [#uses=1]
155 %tmp114 = getelementptr %struct.zzip_dir* %tmp113, i32 0, i32 9 ; <i8**> [#uses=1]
156 %tmp115 = load i8** %tmp114 ; <i8*> [#uses=1]
157 %tmp118 = call i32 @memcmp( i8* %filename, i8* %tmp115, i32 %tmp110 ) ; <i32> [#uses=1]
158 icmp eq i32 %tmp118, 0 ; <i1>:15 [#uses=1]
159 br i1 %15, label %cond_true119, label %bb219
161 cond_true119: ; preds = %cond_true104
162 %tmp122 = getelementptr i8* %filename, i32 %tmp110 ; <i8*> [#uses=1]
163 %tmp123 = load i8* %tmp122 ; <i8> [#uses=1]
164 icmp eq i8 %tmp123, 47 ; <i1>:16 [#uses=1]
165 br i1 %16, label %cond_true124, label %bb219
167 cond_true124: ; preds = %cond_true119
168 %tmp126 = add i32 %tmp110, 1 ; <i32> [#uses=1]
169 %tmp128 = getelementptr i8* %filename, i32 %tmp126 ; <i8*> [#uses=1]
170 %tmp129 = load i8* %tmp128 ; <i8> [#uses=1]
171 icmp eq i8 %tmp129, 0 ; <i1>:17 [#uses=1]
172 br i1 %17, label %bb219, label %cond_true130
174 cond_true130: ; preds = %cond_true124
175 %tmp134.sum = add i32 %tmp110, 1 ; <i32> [#uses=1]
176 %tmp135 = getelementptr i8* %filename, i32 %tmp134.sum ; <i8*> [#uses=1]
177 %tmp137 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
178 %tmp138 = load %struct.zzip_dir** %tmp137 ; <%struct.zzip_dir*> [#uses=1]
179 %tmp140 = call %struct.ZZIP_FILE* @zzip_file_open( %struct.zzip_dir* %tmp138, i8* %tmp135, i32 %o_modes, i32 -1 ) ; <%struct.ZZIP_FILE*> [#uses=3]
180 icmp eq %struct.ZZIP_FILE* %tmp140, null ; <i1>:18 [#uses=1]
181 br i1 %18, label %cond_true142, label %return
183 cond_true142: ; preds = %cond_true130
184 %tmp144 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
185 %tmp145 = load %struct.zzip_dir** %tmp144 ; <%struct.zzip_dir*> [#uses=1]
186 %tmp146 = getelementptr %struct.zzip_dir* %tmp145, i32 0, i32 1 ; <i32*> [#uses=1]
187 %tmp147 = load i32* %tmp146 ; <i32> [#uses=1]
188 %tmp148 = call i32 @zzip_errno( i32 %tmp147 ) ; <i32> [#uses=1]
189 %tmp149 = call i32* @__error( ) ; <i32*> [#uses=1]
190 store i32 %tmp148, i32* %tmp149
191 ret %struct.ZZIP_FILE* %tmp140
195 store i8 0, i8* %tmp221
196 %basename162 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
197 %tmp166 = call i32 @__zzip_try_open( i8* %basename162, i32 %o_flags_addr.0, i8** %ext_addr.1, %struct.zzip_plugin_io* %io_addr.1 ) ; <i32> [#uses=4]
198 icmp eq i32 %tmp166, -1 ; <i1>:19 [#uses=1]
199 br i1 %19, label %bb219, label %cond_next169
201 cond_next169: ; preds = %bb
202 %tmp173 = call %struct.zzip_dir* @zzip_dir_fdopen_ext_io( i32 %tmp166, i32* %e, i8** %ext_addr.1, %struct.zzip_plugin_io* %io_addr.1 ) ; <%struct.zzip_dir*> [#uses=7]
203 %tmp174 = load i32* %e ; <i32> [#uses=1]
204 icmp eq i32 %tmp174, 0 ; <i1>:20 [#uses=1]
205 br i1 %20, label %cond_next185, label %cond_true175
207 cond_true175: ; preds = %cond_next169
208 %tmp176 = load i32* %e ; <i32> [#uses=1]
209 %tmp177 = call i32 @zzip_errno( i32 %tmp176 ) ; <i32> [#uses=1]
210 %tmp178 = call i32* @__error( ) ; <i32*> [#uses=1]
211 store i32 %tmp177, i32* %tmp178
212 %tmp180 = getelementptr %struct.zzip_plugin_io* %io_addr.1, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
213 %tmp181 = load i32 (i32)** %tmp180 ; <i32 (i32)*> [#uses=1]
214 %tmp183 = call i32 %tmp181( i32 %tmp166 ) ; <i32> [#uses=0]
215 ret %struct.ZZIP_FILE* null
217 cond_next185: ; preds = %cond_next169
218 %tmp186187 = ptrtoint i8* %tmp221 to i32 ; <i32> [#uses=1]
219 %basename188189 = ptrtoint [1024 x i8]* %basename to i32 ; <i32> [#uses=1]
220 %tmp190 = sub i32 %tmp186187, %basename188189 ; <i32> [#uses=1]
221 %tmp192.sum = add i32 %tmp190, 1 ; <i32> [#uses=1]
222 %tmp193 = getelementptr i8* %filename, i32 %tmp192.sum ; <i8*> [#uses=1]
223 %tmp196 = call %struct.ZZIP_FILE* @zzip_file_open( %struct.zzip_dir* %tmp173, i8* %tmp193, i32 %o_modes, i32 -1 ) ; <%struct.ZZIP_FILE*> [#uses=4]
224 icmp eq %struct.ZZIP_FILE* %tmp196, null ; <i1>:21 [#uses=1]
225 br i1 %21, label %cond_true198, label %cond_false204
227 cond_true198: ; preds = %cond_next185
228 %tmp200 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 1 ; <i32*> [#uses=1]
229 %tmp201 = load i32* %tmp200 ; <i32> [#uses=1]
230 %tmp202 = call i32 @zzip_errno( i32 %tmp201 ) ; <i32> [#uses=1]
231 %tmp203 = call i32* @__error( ) ; <i32*> [#uses=1]
232 store i32 %tmp202, i32* %tmp203
233 %tmp2169 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
234 ret %struct.ZZIP_FILE* %tmp196
236 cond_false204: ; preds = %cond_next185
237 %tmp206 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 9 ; <i8**> [#uses=1]
238 %tmp207 = load i8** %tmp206 ; <i8*> [#uses=1]
239 icmp eq i8* %tmp207, null ; <i1>:22 [#uses=1]
240 br i1 %22, label %cond_true208, label %cond_next214
242 cond_true208: ; preds = %cond_false204
243 %basename209 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
244 %tmp210 = call i8* @strdup( i8* %basename209 ) ; <i8*> [#uses=1]
245 %tmp212 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 9 ; <i8**> [#uses=1]
246 store i8* %tmp210, i8** %tmp212
247 %tmp21610 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
248 ret %struct.ZZIP_FILE* %tmp196
250 cond_next214: ; preds = %cond_false204
251 %tmp216 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
252 ret %struct.ZZIP_FILE* %tmp196
254 bb219: ; preds = %bb, %cond_true124, %cond_true119, %cond_true104, %cond_true98, %cond_true94, %cond_next80
255 %fd160.0 = phi i32 [ %fd160.3, %cond_next80 ], [ %tmp166, %bb ], [ %fd160.3, %cond_true94 ], [ %fd160.3, %cond_true98 ], [ %fd160.3, %cond_true104 ], [ %fd160.3, %cond_true119 ], [ %fd160.3, %cond_true124 ] ; <i32> [#uses=1]
256 %len.0 = phi i32 [ %len.3, %cond_next80 ], [ %len.0, %bb ], [ %len.3, %cond_true94 ], [ %len.3, %cond_true98 ], [ %tmp110, %cond_true104 ], [ %tmp110, %cond_true119 ], [ %tmp110, %cond_true124 ] ; <i32> [#uses=2]
257 %basename220 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
258 %tmp221 = call i8* @strrchr( i8* %basename220, i32 47 ) ; <i8*> [#uses=3]
259 icmp eq i8* %tmp221, null ; <i1>:23 [#uses=1]
260 br i1 %23, label %bb223, label %bb
262 bb223: ; preds = %bb219
263 %tmp2262272 = and i32 %o_modes, 16384 ; <i32> [#uses=1]
264 icmp eq i32 %tmp2262272, 0 ; <i1>:24 [#uses=1]
265 br i1 %24, label %cond_next229, label %try_real
267 cond_next229: ; preds = %bb223
268 %tmp230 = call i32* @__error( ) ; <i32*> [#uses=1]
269 store i32 2, i32* %tmp230
270 ret %struct.ZZIP_FILE* null
272 return: ; preds = %cond_true130, %cond_next67
273 %retval.0 = phi %struct.ZZIP_FILE* [ null, %cond_next67 ], [ %tmp140, %cond_true130 ] ; <%struct.ZZIP_FILE*> [#uses=1]
274 ret %struct.ZZIP_FILE* %retval.0
277 declare i32 @zzip_dir_close(%struct.zzip_dir*)
279 declare i8* @strrchr(i8*, i32)
281 declare %struct.ZZIP_FILE* @zzip_file_open(%struct.zzip_dir*, i8*, i32, i32)
283 declare i8* @cli_calloc(i32, i32)
285 declare i32 @zzip_errno(i32)
287 declare i32* @__error()
289 declare %struct.zzip_plugin_io* @zzip_get_default_io()
291 declare i8* @strcpy(i8*, i8*)
293 declare i32 @strlen(i8*)
295 declare i32 @memcmp(i8*, i8*, i32)
297 declare i32 @__zzip_try_open(i8*, i32, i8**, %struct.zzip_plugin_io*)
299 declare %struct.zzip_dir* @zzip_dir_fdopen_ext_io(i32, i32*, i8**, %struct.zzip_plugin_io*)
301 declare i8* @strdup(i8*)