1 ; RUN: llvm-as < %s | opt -instcombine -disable-output
4 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"
5 target triple = "i686-apple-darwin8"
6 %struct.ZZIP_FILE = type { %struct.zzip_dir*, i32, i32, i32, i32, i32, i32, i64, i8*, i64, %struct.z_stream, %struct.zzip_plugin_io* }
7 %struct.anon = type { %struct.ZZIP_FILE*, i8* }
8 %struct.internal_state = type { i32 }
9 %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 }
10 %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* }
11 %struct.zzip_dir_hdr = type { i32, i32, i32, i32, i16, i16, i8, i16, [1 x i8] }
12 %struct.zzip_dirent = type { i32, i32, i32, i16, i8*, i32, i32 }
13 %struct.zzip_plugin_io = type { i32 (i8*, i32, ...)*, i32 (i32)*, i32 (i32, i8*, i32)*, i64 (i32, i64, i32)*, i64 (i32)*, i32 }
15 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) {
17 %basename = alloca [1024 x i8], align 16 ; <[1024 x i8]*> [#uses=5]
18 %e = alloca i32, align 4 ; <i32*> [#uses=4]
19 icmp eq %struct.ZZIP_FILE* %stream, null ; <i1>:0 [#uses=1]
20 br i1 %0, label %cond_next22, label %cond_true
22 cond_true: ; preds = %entry
23 %tmp3 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
24 %tmp4 = load %struct.zzip_dir** %tmp3 ; <%struct.zzip_dir*> [#uses=1]
25 icmp eq %struct.zzip_dir* %tmp4, null ; <i1>:1 [#uses=1]
26 br i1 %1, label %cond_next22, label %cond_true5
28 cond_true5: ; preds = %cond_true
29 icmp eq i8** %ext, null ; <i1>:2 [#uses=1]
30 br i1 %2, label %cond_true7, label %cond_next
32 cond_true7: ; preds = %cond_true5
33 %tmp9 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
34 %tmp10 = load %struct.zzip_dir** %tmp9 ; <%struct.zzip_dir*> [#uses=1]
35 %tmp11 = getelementptr %struct.zzip_dir* %tmp10, i32 0, i32 10 ; <i8***> [#uses=1]
36 %tmp12 = load i8*** %tmp11 ; <i8**> [#uses=1]
39 cond_next: ; preds = %cond_true7, %cond_true5
40 %ext_addr.0 = phi i8** [ %ext, %cond_true5 ], [ %tmp12, %cond_true7 ] ; <i8**> [#uses=2]
41 icmp eq %struct.zzip_plugin_io* %io, null ; <i1>:3 [#uses=1]
42 br i1 %3, label %cond_true14, label %cond_next22
44 cond_true14: ; preds = %cond_next
45 %tmp16 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
46 %tmp17 = load %struct.zzip_dir** %tmp16 ; <%struct.zzip_dir*> [#uses=1]
47 %tmp18 = getelementptr %struct.zzip_dir* %tmp17, i32 0, i32 11 ; <%struct.zzip_plugin_io**> [#uses=1]
48 %tmp19 = load %struct.zzip_plugin_io** %tmp18 ; <%struct.zzip_plugin_io*> [#uses=1]
51 cond_next22: ; preds = %cond_true14, %cond_next, %cond_true, %entry
52 %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]
53 %ext_addr.1 = phi i8** [ %ext, %entry ], [ %ext, %cond_true ], [ %ext_addr.0, %cond_next ], [ %ext_addr.0, %cond_true14 ] ; <i8**> [#uses=2]
54 icmp eq %struct.zzip_plugin_io* %io_addr.0, null ; <i1>:4 [#uses=1]
55 br i1 %4, label %cond_true24, label %cond_next26
57 cond_true24: ; preds = %cond_next22
58 %tmp25 = call %struct.zzip_plugin_io* @zzip_get_default_io( ) ; <%struct.zzip_plugin_io*> [#uses=1]
61 cond_next26: ; preds = %cond_true24, %cond_next22
62 %io_addr.1 = phi %struct.zzip_plugin_io* [ %io_addr.0, %cond_next22 ], [ %tmp25, %cond_true24 ] ; <%struct.zzip_plugin_io*> [#uses=4]
63 %tmp28 = and i32 %o_modes, 81920 ; <i32> [#uses=1]
64 icmp eq i32 %tmp28, 0 ; <i1>:5 [#uses=1]
65 br i1 %5, label %try_real, label %try_zzip
67 try_real: ; preds = %bb223, %cond_next26
68 %fd160.2 = phi i32 [ undef, %cond_next26 ], [ %fd160.0, %bb223 ] ; <i32> [#uses=1]
69 %len.2 = phi i32 [ undef, %cond_next26 ], [ %len.0, %bb223 ] ; <i32> [#uses=1]
70 %o_flags_addr.1 = phi i32 [ %o_flags, %cond_next26 ], [ %o_flags_addr.0, %bb223 ] ; <i32> [#uses=2]
71 %tmp33348 = and i32 %o_modes, 262144 ; <i32> [#uses=1]
72 icmp eq i32 %tmp33348, 0 ; <i1>:6 [#uses=1]
73 br i1 %6, label %cond_next38, label %cond_true35
75 cond_true35: ; preds = %try_real
76 %tmp36 = call %struct.zzip_plugin_io* @zzip_get_default_io( ) ; <%struct.zzip_plugin_io*> [#uses=1]
79 cond_next38: ; preds = %cond_true35, %try_real
80 %iftmp.21.0 = phi %struct.zzip_plugin_io* [ %tmp36, %cond_true35 ], [ %io_addr.1, %try_real ] ; <%struct.zzip_plugin_io*> [#uses=3]
81 %tmp41 = getelementptr %struct.zzip_plugin_io* %iftmp.21.0, i32 0, i32 0 ; <i32 (i8*, i32, ...)**> [#uses=1]
82 %tmp42 = load i32 (i8*, i32, ...)** %tmp41 ; <i32 (i8*, i32, ...)*> [#uses=1]
83 %tmp45 = call i32 (i8*, i32, ...)* %tmp42( i8* %filename, i32 %o_flags_addr.1 ) ; <i32> [#uses=3]
84 icmp eq i32 %tmp45, -1 ; <i1>:7 [#uses=1]
85 br i1 %7, label %cond_next67, label %cond_true47
87 cond_true47: ; preds = %cond_next38
88 %tmp48 = call i8* @cli_calloc( i32 1, i32 108 ) ; <i8*> [#uses=2]
89 %tmp4849 = bitcast i8* %tmp48 to %struct.ZZIP_FILE* ; <%struct.ZZIP_FILE*> [#uses=3]
90 icmp eq i8* %tmp48, null ; <i1>:8 [#uses=1]
91 br i1 %8, label %cond_true51, label %cond_next58
93 cond_true51: ; preds = %cond_true47
94 %tmp53 = getelementptr %struct.zzip_plugin_io* %iftmp.21.0, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
95 %tmp54 = load i32 (i32)** %tmp53 ; <i32 (i32)*> [#uses=1]
96 %tmp56 = call i32 %tmp54( i32 %tmp45 ) ; <i32> [#uses=0]
97 ret %struct.ZZIP_FILE* null
99 cond_next58: ; preds = %cond_true47
100 %tmp60 = getelementptr %struct.ZZIP_FILE* %tmp4849, i32 0, i32 1 ; <i32*> [#uses=1]
101 store i32 %tmp45, i32* %tmp60
102 %tmp63 = getelementptr %struct.ZZIP_FILE* %tmp4849, i32 0, i32 11 ; <%struct.zzip_plugin_io**> [#uses=1]
103 store %struct.zzip_plugin_io* %iftmp.21.0, %struct.zzip_plugin_io** %tmp63
104 ret %struct.ZZIP_FILE* %tmp4849
106 cond_next67: ; preds = %cond_next38
107 %tmp70716 = and i32 %o_modes, 16384 ; <i32> [#uses=1]
108 icmp eq i32 %tmp70716, 0 ; <i1>:9 [#uses=1]
109 br i1 %9, label %try_zzip, label %return
111 try_zzip: ; preds = %cond_next67, %cond_next26
112 %fd160.3 = phi i32 [ %fd160.2, %cond_next67 ], [ undef, %cond_next26 ] ; <i32> [#uses=6]
113 %len.3 = phi i32 [ %len.2, %cond_next67 ], [ undef, %cond_next26 ] ; <i32> [#uses=3]
114 %o_flags_addr.3 = phi i32 [ %o_flags_addr.1, %cond_next67 ], [ %o_flags, %cond_next26 ] ; <i32> [#uses=4]
115 %tmp76 = and i32 %o_flags_addr.3, 513 ; <i32> [#uses=1]
116 icmp eq i32 %tmp76, 0 ; <i1>:10 [#uses=1]
117 br i1 %10, label %cond_next80, label %cond_true77
119 cond_true77: ; preds = %try_zzip
120 %tmp78 = call i32* @__error( ) ; <i32*> [#uses=1]
121 store i32 22, i32* %tmp78
122 ret %struct.ZZIP_FILE* null
124 cond_next80: ; preds = %try_zzip
125 %tmp83844 = and i32 %o_flags_addr.3, 2 ; <i32> [#uses=1]
126 icmp eq i32 %tmp83844, 0 ; <i1>:11 [#uses=1]
127 %tmp87 = xor i32 %o_flags_addr.3, 2 ; <i32> [#uses=1]
128 %o_flags_addr.0 = select i1 %11, i32 %o_flags_addr.3, i32 %tmp87 ; <i32> [#uses=2]
129 %basename90 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
130 %tmp92 = call i8* @strcpy( i8* %basename90, i8* %filename ) ; <i8*> [#uses=0]
131 icmp eq %struct.ZZIP_FILE* %stream, null ; <i1>:12 [#uses=1]
132 br i1 %12, label %bb219, label %cond_true94
134 cond_true94: ; preds = %cond_next80
135 %tmp96 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
136 %tmp97 = load %struct.zzip_dir** %tmp96 ; <%struct.zzip_dir*> [#uses=1]
137 icmp eq %struct.zzip_dir* %tmp97, null ; <i1>:13 [#uses=1]
138 br i1 %13, label %bb219, label %cond_true98
140 cond_true98: ; preds = %cond_true94
141 %tmp100 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
142 %tmp101 = load %struct.zzip_dir** %tmp100 ; <%struct.zzip_dir*> [#uses=1]
143 %tmp102 = getelementptr %struct.zzip_dir* %tmp101, i32 0, i32 9 ; <i8**> [#uses=1]
144 %tmp103 = load i8** %tmp102 ; <i8*> [#uses=1]
145 icmp eq i8* %tmp103, null ; <i1>:14 [#uses=1]
146 br i1 %14, label %bb219, label %cond_true104
148 cond_true104: ; preds = %cond_true98
149 %tmp106 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
150 %tmp107 = load %struct.zzip_dir** %tmp106 ; <%struct.zzip_dir*> [#uses=1]
151 %tmp108 = getelementptr %struct.zzip_dir* %tmp107, i32 0, i32 9 ; <i8**> [#uses=1]
152 %tmp109 = load i8** %tmp108 ; <i8*> [#uses=1]
153 %tmp110 = call i32 @strlen( i8* %tmp109 ) ; <i32> [#uses=7]
154 %tmp112 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
155 %tmp113 = load %struct.zzip_dir** %tmp112 ; <%struct.zzip_dir*> [#uses=1]
156 %tmp114 = getelementptr %struct.zzip_dir* %tmp113, i32 0, i32 9 ; <i8**> [#uses=1]
157 %tmp115 = load i8** %tmp114 ; <i8*> [#uses=1]
158 %tmp118 = call i32 @memcmp( i8* %filename, i8* %tmp115, i32 %tmp110 ) ; <i32> [#uses=1]
159 icmp eq i32 %tmp118, 0 ; <i1>:15 [#uses=1]
160 br i1 %15, label %cond_true119, label %bb219
162 cond_true119: ; preds = %cond_true104
163 %tmp122 = getelementptr i8* %filename, i32 %tmp110 ; <i8*> [#uses=1]
164 %tmp123 = load i8* %tmp122 ; <i8> [#uses=1]
165 icmp eq i8 %tmp123, 47 ; <i1>:16 [#uses=1]
166 br i1 %16, label %cond_true124, label %bb219
168 cond_true124: ; preds = %cond_true119
169 %tmp126 = add i32 %tmp110, 1 ; <i32> [#uses=1]
170 %tmp128 = getelementptr i8* %filename, i32 %tmp126 ; <i8*> [#uses=1]
171 %tmp129 = load i8* %tmp128 ; <i8> [#uses=1]
172 icmp eq i8 %tmp129, 0 ; <i1>:17 [#uses=1]
173 br i1 %17, label %bb219, label %cond_true130
175 cond_true130: ; preds = %cond_true124
176 %tmp134.sum = add i32 %tmp110, 1 ; <i32> [#uses=1]
177 %tmp135 = getelementptr i8* %filename, i32 %tmp134.sum ; <i8*> [#uses=1]
178 %tmp137 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
179 %tmp138 = load %struct.zzip_dir** %tmp137 ; <%struct.zzip_dir*> [#uses=1]
180 %tmp140 = call %struct.ZZIP_FILE* @zzip_file_open( %struct.zzip_dir* %tmp138, i8* %tmp135, i32 %o_modes, i32 -1 ) ; <%struct.ZZIP_FILE*> [#uses=3]
181 icmp eq %struct.ZZIP_FILE* %tmp140, null ; <i1>:18 [#uses=1]
182 br i1 %18, label %cond_true142, label %return
184 cond_true142: ; preds = %cond_true130
185 %tmp144 = getelementptr %struct.ZZIP_FILE* %stream, i32 0, i32 0 ; <%struct.zzip_dir**> [#uses=1]
186 %tmp145 = load %struct.zzip_dir** %tmp144 ; <%struct.zzip_dir*> [#uses=1]
187 %tmp146 = getelementptr %struct.zzip_dir* %tmp145, i32 0, i32 1 ; <i32*> [#uses=1]
188 %tmp147 = load i32* %tmp146 ; <i32> [#uses=1]
189 %tmp148 = call i32 @zzip_errno( i32 %tmp147 ) ; <i32> [#uses=1]
190 %tmp149 = call i32* @__error( ) ; <i32*> [#uses=1]
191 store i32 %tmp148, i32* %tmp149
192 ret %struct.ZZIP_FILE* %tmp140
196 store i8 0, i8* %tmp221
197 %basename162 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
198 %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]
199 icmp eq i32 %tmp166, -1 ; <i1>:19 [#uses=1]
200 br i1 %19, label %bb219, label %cond_next169
202 cond_next169: ; preds = %bb
203 %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]
204 %tmp174 = load i32* %e ; <i32> [#uses=1]
205 icmp eq i32 %tmp174, 0 ; <i1>:20 [#uses=1]
206 br i1 %20, label %cond_next185, label %cond_true175
208 cond_true175: ; preds = %cond_next169
209 %tmp176 = load i32* %e ; <i32> [#uses=1]
210 %tmp177 = call i32 @zzip_errno( i32 %tmp176 ) ; <i32> [#uses=1]
211 %tmp178 = call i32* @__error( ) ; <i32*> [#uses=1]
212 store i32 %tmp177, i32* %tmp178
213 %tmp180 = getelementptr %struct.zzip_plugin_io* %io_addr.1, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
214 %tmp181 = load i32 (i32)** %tmp180 ; <i32 (i32)*> [#uses=1]
215 %tmp183 = call i32 %tmp181( i32 %tmp166 ) ; <i32> [#uses=0]
216 ret %struct.ZZIP_FILE* null
218 cond_next185: ; preds = %cond_next169
219 %tmp186187 = ptrtoint i8* %tmp221 to i32 ; <i32> [#uses=1]
220 %basename188189 = ptrtoint [1024 x i8]* %basename to i32 ; <i32> [#uses=1]
221 %tmp190 = sub i32 %tmp186187, %basename188189 ; <i32> [#uses=1]
222 %tmp192.sum = add i32 %tmp190, 1 ; <i32> [#uses=1]
223 %tmp193 = getelementptr i8* %filename, i32 %tmp192.sum ; <i8*> [#uses=1]
224 %tmp196 = call %struct.ZZIP_FILE* @zzip_file_open( %struct.zzip_dir* %tmp173, i8* %tmp193, i32 %o_modes, i32 -1 ) ; <%struct.ZZIP_FILE*> [#uses=4]
225 icmp eq %struct.ZZIP_FILE* %tmp196, null ; <i1>:21 [#uses=1]
226 br i1 %21, label %cond_true198, label %cond_false204
228 cond_true198: ; preds = %cond_next185
229 %tmp200 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 1 ; <i32*> [#uses=1]
230 %tmp201 = load i32* %tmp200 ; <i32> [#uses=1]
231 %tmp202 = call i32 @zzip_errno( i32 %tmp201 ) ; <i32> [#uses=1]
232 %tmp203 = call i32* @__error( ) ; <i32*> [#uses=1]
233 store i32 %tmp202, i32* %tmp203
234 %tmp2169 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
235 ret %struct.ZZIP_FILE* %tmp196
237 cond_false204: ; preds = %cond_next185
238 %tmp206 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 9 ; <i8**> [#uses=1]
239 %tmp207 = load i8** %tmp206 ; <i8*> [#uses=1]
240 icmp eq i8* %tmp207, null ; <i1>:22 [#uses=1]
241 br i1 %22, label %cond_true208, label %cond_next214
243 cond_true208: ; preds = %cond_false204
244 %basename209 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
245 %tmp210 = call i8* @strdup( i8* %basename209 ) ; <i8*> [#uses=1]
246 %tmp212 = getelementptr %struct.zzip_dir* %tmp173, i32 0, i32 9 ; <i8**> [#uses=1]
247 store i8* %tmp210, i8** %tmp212
248 %tmp21610 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
249 ret %struct.ZZIP_FILE* %tmp196
251 cond_next214: ; preds = %cond_false204
252 %tmp216 = call i32 @zzip_dir_close( %struct.zzip_dir* %tmp173 ) ; <i32> [#uses=0]
253 ret %struct.ZZIP_FILE* %tmp196
255 bb219: ; preds = %bb, %cond_true124, %cond_true119, %cond_true104, %cond_true98, %cond_true94, %cond_next80
256 %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]
257 %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]
258 %basename220 = getelementptr [1024 x i8]* %basename, i32 0, i32 0 ; <i8*> [#uses=1]
259 %tmp221 = call i8* @strrchr( i8* %basename220, i32 47 ) ; <i8*> [#uses=3]
260 icmp eq i8* %tmp221, null ; <i1>:23 [#uses=1]
261 br i1 %23, label %bb223, label %bb
263 bb223: ; preds = %bb219
264 %tmp2262272 = and i32 %o_modes, 16384 ; <i32> [#uses=1]
265 icmp eq i32 %tmp2262272, 0 ; <i1>:24 [#uses=1]
266 br i1 %24, label %cond_next229, label %try_real
268 cond_next229: ; preds = %bb223
269 %tmp230 = call i32* @__error( ) ; <i32*> [#uses=1]
270 store i32 2, i32* %tmp230
271 ret %struct.ZZIP_FILE* null
273 return: ; preds = %cond_true130, %cond_next67
274 %retval.0 = phi %struct.ZZIP_FILE* [ null, %cond_next67 ], [ %tmp140, %cond_true130 ] ; <%struct.ZZIP_FILE*> [#uses=1]
275 ret %struct.ZZIP_FILE* %retval.0
278 declare i32 @zzip_dir_close(%struct.zzip_dir*)
280 declare i8* @strrchr(i8*, i32)
282 declare %struct.ZZIP_FILE* @zzip_file_open(%struct.zzip_dir*, i8*, i32, i32)
284 declare i8* @cli_calloc(i32, i32)
286 declare i32 @zzip_errno(i32)
288 declare i32* @__error()
290 declare %struct.zzip_plugin_io* @zzip_get_default_io()
292 declare i8* @strcpy(i8*, i8*)
294 declare i32 @strlen(i8*)
296 declare i32 @memcmp(i8*, i8*, i32)
298 declare i32 @__zzip_try_open(i8*, i32, i8**, %struct.zzip_plugin_io*)
300 declare %struct.zzip_dir* @zzip_dir_fdopen_ext_io(i32, i32*, i8**, %struct.zzip_plugin_io*)
302 declare i8* @strdup(i8*)