; LLVM IR from aap/librw :: src/png.ll (ZN2rw8writePNGEPNS_5ImageEPKc)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"class.rw::StreamFile" = type { %"class.rw::Stream", ptr }
%"class.rw::Stream" = type { ptr }
%"struct.rw::Error" = type { i32, i32 }
%struct.LodePNGState = type { %struct.LodePNGDecoderSettings, %struct.LodePNGEncoderSettings, %struct.LodePNGColorMode, %struct.LodePNGInfo, i32 }
%struct.LodePNGDecoderSettings = type { %struct.LodePNGDecompressSettings, i32, i32, i32, i32, i32, i32 }
%struct.LodePNGDecompressSettings = type { i32, i32, ptr, ptr, ptr }
%struct.LodePNGEncoderSettings = type { %struct.LodePNGCompressSettings, i32, i32, i32, ptr, i32, i32, i32 }
%struct.LodePNGCompressSettings = type { i32, i32, i32, i32, i32, i32, ptr, ptr, ptr }
%struct.LodePNGColorMode = type { i32, i32, ptr, i64, i32, i32, i32, i32 }
%struct.LodePNGInfo = type { i32, i32, i32, %struct.LodePNGColorMode, i32, i32, i32, i32, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, %struct.LodePNGTime, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, [3 x ptr], [3 x i64] }
%struct.LodePNGTime = type { i32, i32, i32, i32, i32, i32 }
%"struct.rw::Image" = type { i32, i32, i32, i32, i32, i32, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [55 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [71 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_Z18lodepng_state_initP12LodePNGState(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) #1

declare noundef ptr @_Z18lodepng_error_textj(i32 noundef) #1

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8writePNGEPNS_5ImageEPKc(ptr noundef %0, ptr noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"class.rw::StreamFile", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %"struct.rw::Error", align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.LodePNGState, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca %"struct.rw::Error", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  call void @_ZN2rw10StreamFileC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = invoke noundef ptr @_ZN2rw10StreamFile4openEPKcS2_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef %19, ptr noundef @.str.4)
          to label %21 unwind label %37

21:                                               ; preds = %2
  %22 = icmp ne ptr %20, null
  br i1 %22, label %45, label %23

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %25 = getelementptr inbounds %"struct.rw::Error", ptr %9, i32 0, i32 0
  store i32 0, ptr %25, align 4, !tbaa !9
  %26 = getelementptr inbounds %"struct.rw::Error", ptr %9, i32 0, i32 1
  store i32 -2147483645, ptr %26, align 4, !tbaa !12
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 88) #6
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = invoke noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483645, ptr noundef %30)
          to label %32 unwind label %41

32:                                               ; preds = %24
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.3, ptr noundef %31) #6
  invoke void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %9)
          to label %34 unwind label %41

34:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  store i32 1, ptr %10, align 4
  br label %282

37:                                               ; preds = %2
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %7, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %8, align 4
  br label %287

41:                                               ; preds = %32, %24
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %7, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %287

45:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 504, ptr %14) #6
  invoke void @_Z18lodepng_state_initP12LodePNGState(ptr noundef %14)
          to label %46 unwind label %53

46:                                               ; preds = %45
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.rw::Image", ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  store ptr %49, ptr %13, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.rw::Image", ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 4, !tbaa !15
  switch i32 %52, label %227 [
    i32 4, label %57
    i32 8, label %154
    i32 16, label %216
    i32 24, label %219
    i32 32, label %227
  ]

53:                                               ; preds = %216, %135, %123, %45
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %7, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %8, align 4
  br label %286

57:                                               ; preds = %46
  %58 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %59 = getelementptr inbounds %struct.LodePNGColorMode, ptr %58, i32 0, i32 1
  store i32 4, ptr %59, align 4, !tbaa !16
  %60 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %61 = getelementptr inbounds %struct.LodePNGColorMode, ptr %60, i32 0, i32 0
  store i32 3, ptr %61, align 8, !tbaa !28
  %62 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %63 = getelementptr inbounds %struct.LodePNGInfo, ptr %62, i32 0, i32 3
  %64 = getelementptr inbounds %struct.LodePNGColorMode, ptr %63, i32 0, i32 1
  store i32 4, ptr %64, align 4, !tbaa !29
  %65 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %66 = getelementptr inbounds %struct.LodePNGInfo, ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds %struct.LodePNGColorMode, ptr %66, i32 0, i32 0
  store i32 3, ptr %67, align 8, !tbaa !30
  %68 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 1
  %69 = getelementptr inbounds %struct.LodePNGEncoderSettings, ptr %68, i32 0, i32 1
  store i32 0, ptr %69, align 8, !tbaa !31
  store i32 0, ptr %5, align 4, !tbaa !32
  br label %70

70:                                               ; preds = %116, %57
  %71 = load i32, ptr %5, align 4, !tbaa !32
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.rw::Image", ptr %72, i32 0, i32 3
  %74 = load i32, ptr %73, align 4, !tbaa !15
  %75 = shl i32 1, %74
  %76 = icmp slt i32 %71, %75
  br i1 %76, label %77, label %123

77:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %"struct.rw::Image", ptr %78, i32 0, i32 7
  %80 = load ptr, ptr %79, align 8, !tbaa !33
  %81 = load i32, ptr %5, align 4, !tbaa !32
  %82 = mul nsw i32 %81, 4
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  store ptr %84, ptr %15, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %86 = getelementptr inbounds %struct.LodePNGInfo, ptr %85, i32 0, i32 3
  %87 = load ptr, ptr %15, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 0
  %89 = load i8, ptr %88, align 1, !tbaa !34
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i64 1
  %92 = load i8, ptr %91, align 1, !tbaa !34
  %93 = load ptr, ptr %15, align 8, !tbaa !5
  %94 = getelementptr inbounds i8, ptr %93, i64 2
  %95 = load i8, ptr %94, align 1, !tbaa !34
  %96 = load ptr, ptr %15, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 3
  %98 = load i8, ptr %97, align 1, !tbaa !34
  %99 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef %86, i8 noundef zeroext %89, i8 noundef zeroext %92, i8 noundef zeroext %95, i8 noundef zeroext %98)
          to label %100 unwind label %119

100:                                              ; preds = %77
  %101 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %102 = load ptr, ptr %15, align 8, !tbaa !5
  %103 = getelementptr inbounds i8, ptr %102, i64 0
  %104 = load i8, ptr %103, align 1, !tbaa !34
  %105 = load ptr, ptr %15, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i64 1
  %107 = load i8, ptr %106, align 1, !tbaa !34
  %108 = load ptr, ptr %15, align 8, !tbaa !5
  %109 = getelementptr inbounds i8, ptr %108, i64 2
  %110 = load i8, ptr %109, align 1, !tbaa !34
  %111 = load ptr, ptr %15, align 8, !tbaa !5
  %112 = getelementptr inbounds i8, ptr %111, i64 3
  %113 = load i8, ptr %112, align 1, !tbaa !34
  %114 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef %101, i8 noundef zeroext %104, i8 noundef zeroext %107, i8 noundef zeroext %110, i8 noundef zeroext %113)
          to label %115 unwind label %119

115:                                              ; preds = %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %5, align 4, !tbaa !32
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %5, align 4, !tbaa !32
  br label %70, !llvm.loop !35

119:                                              ; preds = %100, %77
  %120 = landingpad { ptr, i32 }
          cleanup
  %121 = extractvalue { ptr, i32 } %120, 0
  store ptr %121, ptr %7, align 8
  %122 = extractvalue { ptr, i32 } %120, 1
  store i32 %122, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %286

123:                                              ; preds = %70
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = getelementptr inbounds %"struct.rw::Image", ptr %124, i32 0, i32 1
  %126 = load i32, ptr %125, align 4, !tbaa !37
  %127 = sdiv i32 %126, 2
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %"struct.rw::Image", ptr %128, i32 0, i32 2
  %130 = load i32, ptr %129, align 8, !tbaa !38
  %131 = mul nsw i32 %127, %130
  %132 = sext i32 %131 to i64
  %133 = mul i64 %132, 1
  %134 = invoke noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %133, i32 noundef 65560, ptr noundef @.str.5)
          to label %135 unwind label %53

135:                                              ; preds = %123
  store ptr %134, ptr %13, align 8, !tbaa !5
  %136 = load ptr, ptr %13, align 8, !tbaa !5
  %137 = load ptr, ptr %3, align 8, !tbaa !5
  %138 = getelementptr inbounds %"struct.rw::Image", ptr %137, i32 0, i32 1
  %139 = load i32, ptr %138, align 4, !tbaa !37
  %140 = sdiv i32 %139, 2
  %141 = load ptr, ptr %3, align 8, !tbaa !5
  %142 = getelementptr inbounds %"struct.rw::Image", ptr %141, i32 0, i32 6
  %143 = load ptr, ptr %142, align 8, !tbaa !13
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  %145 = getelementptr inbounds %"struct.rw::Image", ptr %144, i32 0, i32 1
  %146 = load i32, ptr %145, align 4, !tbaa !37
  %147 = load ptr, ptr %3, align 8, !tbaa !5
  %148 = getelementptr inbounds %"struct.rw::Image", ptr %147, i32 0, i32 1
  %149 = load i32, ptr %148, align 4, !tbaa !37
  %150 = load ptr, ptr %3, align 8, !tbaa !5
  %151 = getelementptr inbounds %"struct.rw::Image", ptr %150, i32 0, i32 2
  %152 = load i32, ptr %151, align 8, !tbaa !38
  invoke void @_ZN2rw15compressPal4_BEEPhjS0_jii(ptr noundef %136, i32 noundef %140, ptr noundef %143, i32 noundef %146, i32 noundef %149, i32 noundef %152)
          to label %153 unwind label %53

153:                                              ; preds = %135
  br label %227

154:                                              ; preds = %46
  %155 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %156 = getelementptr inbounds %struct.LodePNGColorMode, ptr %155, i32 0, i32 0
  store i32 3, ptr %156, align 8, !tbaa !28
  %157 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %158 = getelementptr inbounds %struct.LodePNGInfo, ptr %157, i32 0, i32 3
  %159 = getelementptr inbounds %struct.LodePNGColorMode, ptr %158, i32 0, i32 0
  store i32 3, ptr %159, align 8, !tbaa !30
  %160 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 1
  %161 = getelementptr inbounds %struct.LodePNGEncoderSettings, ptr %160, i32 0, i32 1
  store i32 0, ptr %161, align 8, !tbaa !31
  store i32 0, ptr %5, align 4, !tbaa !32
  br label %162

162:                                              ; preds = %208, %154
  %163 = load i32, ptr %5, align 4, !tbaa !32
  %164 = load ptr, ptr %3, align 8, !tbaa !5
  %165 = getelementptr inbounds %"struct.rw::Image", ptr %164, i32 0, i32 3
  %166 = load i32, ptr %165, align 4, !tbaa !15
  %167 = shl i32 1, %166
  %168 = icmp slt i32 %163, %167
  br i1 %168, label %169, label %215

169:                                              ; preds = %162
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %170 = load ptr, ptr %3, align 8, !tbaa !5
  %171 = getelementptr inbounds %"struct.rw::Image", ptr %170, i32 0, i32 7
  %172 = load ptr, ptr %171, align 8, !tbaa !33
  %173 = load i32, ptr %5, align 4, !tbaa !32
  %174 = mul nsw i32 %173, 4
  %175 = sext i32 %174 to i64
  %176 = getelementptr inbounds i8, ptr %172, i64 %175
  store ptr %176, ptr %16, align 8, !tbaa !5
  %177 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %178 = getelementptr inbounds %struct.LodePNGInfo, ptr %177, i32 0, i32 3
  %179 = load ptr, ptr %16, align 8, !tbaa !5
  %180 = getelementptr inbounds i8, ptr %179, i64 0
  %181 = load i8, ptr %180, align 1, !tbaa !34
  %182 = load ptr, ptr %16, align 8, !tbaa !5
  %183 = getelementptr inbounds i8, ptr %182, i64 1
  %184 = load i8, ptr %183, align 1, !tbaa !34
  %185 = load ptr, ptr %16, align 8, !tbaa !5
  %186 = getelementptr inbounds i8, ptr %185, i64 2
  %187 = load i8, ptr %186, align 1, !tbaa !34
  %188 = load ptr, ptr %16, align 8, !tbaa !5
  %189 = getelementptr inbounds i8, ptr %188, i64 3
  %190 = load i8, ptr %189, align 1, !tbaa !34
  %191 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef %178, i8 noundef zeroext %181, i8 noundef zeroext %184, i8 noundef zeroext %187, i8 noundef zeroext %190)
          to label %192 unwind label %211

192:                                              ; preds = %169
  %193 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %194 = load ptr, ptr %16, align 8, !tbaa !5
  %195 = getelementptr inbounds i8, ptr %194, i64 0
  %196 = load i8, ptr %195, align 1, !tbaa !34
  %197 = load ptr, ptr %16, align 8, !tbaa !5
  %198 = getelementptr inbounds i8, ptr %197, i64 1
  %199 = load i8, ptr %198, align 1, !tbaa !34
  %200 = load ptr, ptr %16, align 8, !tbaa !5
  %201 = getelementptr inbounds i8, ptr %200, i64 2
  %202 = load i8, ptr %201, align 1, !tbaa !34
  %203 = load ptr, ptr %16, align 8, !tbaa !5
  %204 = getelementptr inbounds i8, ptr %203, i64 3
  %205 = load i8, ptr %204, align 1, !tbaa !34
  %206 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef %193, i8 noundef zeroext %196, i8 noundef zeroext %199, i8 noundef zeroext %202, i8 noundef zeroext %205)
          to label %207 unwind label %211

207:                                              ; preds = %192
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %208

208:                                              ; preds = %207
  %209 = load i32, ptr %5, align 4, !tbaa !32
  %210 = add nsw i32 %209, 1
  store i32 %210, ptr %5, align 4, !tbaa !32
  br label %162, !llvm.loop !39

211:                                              ; preds = %192, %169
  %212 = landingpad { ptr, i32 }
          cleanup
  %213 = extractvalue { ptr, i32 } %212, 0
  store ptr %213, ptr %7, align 8
  %214 = extractvalue { ptr, i32 } %212, 1
  store i32 %214, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %286

215:                                              ; preds = %162
  br label %227

216:                                              ; preds = %46
  %217 = load ptr, ptr %3, align 8, !tbaa !5
  invoke void @_ZN2rw5Image11convertTo32Ev(ptr noundef nonnull align 8 dereferenceable(40) %217)
          to label %218 unwind label %53

218:                                              ; preds = %216
  br label %227

219:                                              ; preds = %46
  %220 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 2
  %221 = getelementptr inbounds %struct.LodePNGColorMode, ptr %220, i32 0, i32 0
  store i32 2, ptr %221, align 8, !tbaa !28
  %222 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 3
  %223 = getelementptr inbounds %struct.LodePNGInfo, ptr %222, i32 0, i32 3
  %224 = getelementptr inbounds %struct.LodePNGColorMode, ptr %223, i32 0, i32 0
  store i32 2, ptr %224, align 8, !tbaa !30
  %225 = getelementptr inbounds %struct.LodePNGState, ptr %14, i32 0, i32 1
  %226 = getelementptr inbounds %struct.LodePNGEncoderSettings, ptr %225, i32 0, i32 1
  store i32 0, ptr %226, align 8, !tbaa !31
  br label %227

227:                                              ; preds = %219, %218, %215, %153, %46, %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %228 = load ptr, ptr %13, align 8, !tbaa !5
  %229 = load ptr, ptr %3, align 8, !tbaa !5
  %230 = getelementptr inbounds %"struct.rw::Image", ptr %229, i32 0, i32 1
  %231 = load i32, ptr %230, align 4, !tbaa !37
  %232 = load ptr, ptr %3, align 8, !tbaa !5
  %233 = getelementptr inbounds %"struct.rw::Image", ptr %232, i32 0, i32 2
  %234 = load i32, ptr %233, align 8, !tbaa !38
  %235 = invoke noundef i32 @_Z14lodepng_encodePPhPmPKhjjP12LodePNGState(ptr noundef %12, ptr noundef %11, ptr noundef %228, i32 noundef %231, i32 noundef %234, ptr noundef %14)
          to label %236 unwind label %255

236:                                              ; preds = %227
  store i32 %235, ptr %17, align 4, !tbaa !32
  %237 = load i32, ptr %17, align 4, !tbaa !32
  %238 = icmp ne i32 %237, 0
  br i1 %238, label %239, label %263

239:                                              ; preds = %236
  br label %240

240:                                              ; preds = %239
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %241 = getelementptr inbounds %"struct.rw::Error", ptr %18, i32 0, i32 0
  store i32 0, ptr %241, align 4, !tbaa !9
  %242 = getelementptr inbounds %"struct.rw::Error", ptr %18, i32 0, i32 1
  store i32 -2147483647, ptr %242, align 4, !tbaa !12
  %243 = load ptr, ptr @stderr, align 8, !tbaa !5
  %244 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %243, ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 141) #6
  %245 = load ptr, ptr @stderr, align 8, !tbaa !5
  %246 = load i32, ptr %17, align 4, !tbaa !32
  %247 = invoke noundef ptr @_Z18lodepng_error_textj(i32 noundef %246)
          to label %248 unwind label %259

248:                                              ; preds = %240
  %249 = invoke noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483647, ptr noundef %247)
          to label %250 unwind label %259

250:                                              ; preds = %248
  %251 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %245, ptr noundef @.str.3, ptr noundef %249) #6
  invoke void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %18)
          to label %252 unwind label %259

252:                                              ; preds = %250
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  br label %253

253:                                              ; preds = %252
  br label %254

254:                                              ; preds = %253
  store i32 1, ptr %10, align 4
  br label %281

255:                                              ; preds = %278, %273, %269, %227
  %256 = landingpad { ptr, i32 }
          cleanup
  %257 = extractvalue { ptr, i32 } %256, 0
  store ptr %257, ptr %7, align 8
  %258 = extractvalue { ptr, i32 } %256, 1
  store i32 %258, ptr %8, align 4
  br label %285

259:                                              ; preds = %250, %248, %240
  %260 = landingpad { ptr, i32 }
          cleanup
  %261 = extractvalue { ptr, i32 } %260, 0
  store ptr %261, ptr %7, align 8
  %262 = extractvalue { ptr, i32 } %260, 1
  store i32 %262, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  br label %285

263:                                              ; preds = %236
  %264 = load ptr, ptr %13, align 8, !tbaa !5
  %265 = load ptr, ptr %3, align 8, !tbaa !5
  %266 = getelementptr inbounds %"struct.rw::Image", ptr %265, i32 0, i32 6
  %267 = load ptr, ptr %266, align 8, !tbaa !13
  %268 = icmp ne ptr %264, %267
  br i1 %268, label %269, label %273

269:                                              ; preds = %263
  %270 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !40
  %271 = load ptr, ptr %13, align 8, !tbaa !5
  invoke void %270(ptr noundef %271)
          to label %272 unwind label %255

272:                                              ; preds = %269
  br label %273

273:                                              ; preds = %272, %263
  %274 = load ptr, ptr %12, align 8, !tbaa !5
  %275 = load i64, ptr %11, align 8, !tbaa !42
  %276 = trunc i64 %275 to i32
  %277 = invoke noundef i32 @_ZN2rw10StreamFile6write8EPKvj(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef %274, i32 noundef %276)
          to label %278 unwind label %255

278:                                              ; preds = %273
  invoke void @_ZN2rw10StreamFile5closeEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
          to label %279 unwind label %255

279:                                              ; preds = %278
  %280 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %280) #6
  store i32 0, ptr %10, align 4
  br label %281

281:                                              ; preds = %279, %254
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 504, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %282

282:                                              ; preds = %281, %36
  call void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %283 = load i32, ptr %10, align 4
  switch i32 %283, label %293 [
    i32 0, label %284
    i32 1, label %284
  ]

284:                                              ; preds = %282, %282
  ret void

285:                                              ; preds = %259, %255
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  br label %286

286:                                              ; preds = %285, %211, %119, %53
  call void @llvm.lifetime.end.p0(i64 504, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %287

287:                                              ; preds = %286, %41, %37
  call void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %288

288:                                              ; preds = %287
  %289 = load ptr, ptr %7, align 8
  %290 = load i32, ptr %8, align 4
  %291 = insertvalue { ptr, i32 } poison, ptr %289, 0
  %292 = insertvalue { ptr, i32 } %291, i32 %290, 1
  resume { ptr, i32 } %292

293:                                              ; preds = %282
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw10StreamFileC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4 align 2

declare noundef ptr @_ZN2rw10StreamFile4openEPKcS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, ptr noundef) #1

declare i32 @__gxx_personality_v0(...)

declare noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #5

declare void @_ZN2rw15compressPal4_BEEPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare void @_ZN2rw5Image11convertTo32Ev(ptr noundef nonnull align 8 dereferenceable(40)) #1

declare noundef i32 @_Z14lodepng_encodePPhPmPKhjjP12LodePNGState(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare noundef i32 @_ZN2rw10StreamFile6write8EPKvj(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #1

declare void @_ZN2rw10StreamFile5closeEv(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN2rw5ErrorE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTSN2rw5ImageE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32}
!15 = !{!14, !11, i64 12}
!16 = !{!17, !11, i64 148}
!17 = !{!"_ZTS12LodePNGState", !18, i64 0, !20, i64 56, !23, i64 144, !26, i64 184, !11, i64 496}
!18 = !{!"_ZTS22LodePNGDecoderSettings", !19, i64 0, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52}
!19 = !{!"_ZTS25LodePNGDecompressSettings", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!"_ZTS22LodePNGEncoderSettings", !21, i64 0, !11, i64 48, !11, i64 52, !22, i64 56, !6, i64 64, !11, i64 72, !11, i64 76, !11, i64 80}
!21 = !{!"_ZTS23LodePNGCompressSettings", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40}
!22 = !{!"_ZTS21LodePNGFilterStrategy", !7, i64 0}
!23 = !{!"_ZTS16LodePNGColorMode", !24, i64 0, !11, i64 4, !6, i64 8, !25, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!24 = !{!"_ZTS16LodePNGColorType", !7, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = !{!"_ZTS11LodePNGInfo", !11, i64 0, !11, i64 4, !11, i64 8, !23, i64 16, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !25, i64 72, !6, i64 80, !6, i64 88, !25, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !11, i64 136, !27, i64 140, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !11, i64 256, !7, i64 264, !7, i64 288}
!27 = !{!"_ZTS11LodePNGTime", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!28 = !{!17, !24, i64 144}
!29 = !{!17, !11, i64 204}
!30 = !{!17, !24, i64 200}
!31 = !{!17, !11, i64 104}
!32 = !{!11, !11, i64 0}
!33 = !{!14, !6, i64 32}
!34 = !{!7, !7, i64 0}
!35 = distinct !{!35, !36}
!36 = !{!"llvm.loop.mustprogress"}
!37 = !{!14, !11, i64 4}
!38 = !{!14, !11, i64 8}
!39 = distinct !{!39, !36}
!40 = !{!41, !6, i64 16}
!41 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!42 = !{!25, !25, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"class.rw::StreamFile" = type { %"class.rw::Stream", ptr }
%"class.rw::Stream" = type { ptr }
%"struct.rw::Error" = type { i32, i32 }
%struct.LodePNGState = type { %struct.LodePNGDecoderSettings, %struct.LodePNGEncoderSettings, %struct.LodePNGColorMode, %struct.LodePNGInfo, i32 }
%struct.LodePNGDecoderSettings = type { %struct.LodePNGDecompressSettings, i32, i32, i32, i32, i32, i32 }
%struct.LodePNGDecompressSettings = type { i32, i32, ptr, ptr, ptr }
%struct.LodePNGEncoderSettings = type { %struct.LodePNGCompressSettings, i32, i32, i32, ptr, i32, i32, i32 }
%struct.LodePNGCompressSettings = type { i32, i32, i32, i32, i32, i32, ptr, ptr, ptr }
%struct.LodePNGColorMode = type { i32, i32, ptr, i64, i32, i32, i32, i32 }
%struct.LodePNGInfo = type { i32, i32, i32, %struct.LodePNGColorMode, i32, i32, i32, i32, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, %struct.LodePNGTime, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, [3 x ptr], [3 x i64] }
%struct.LodePNGTime = type { i32, i32, i32, i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [55 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [71 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_Z18lodepng_state_initP12LodePNGState(ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) local_unnamed_addr #1

declare noundef ptr @_Z18lodepng_error_textj(i32 noundef) local_unnamed_addr #1

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw8writePNGEPNS_5ImageEPKc(ptr noundef %0, ptr noundef %1) local_unnamed_addr #4 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.rw::StreamFile", align 8
  %4 = alloca %"struct.rw::Error", align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.LodePNGState, align 8
  %8 = alloca %"struct.rw::Error", align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #8
  call void @_ZN2rw10StreamFileC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %9 = invoke noundef ptr @_ZN2rw10StreamFile4openEPKcS2_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef %1, ptr noundef nonnull @.str.4)
          to label %10 unwind label %20

10:                                               ; preds = %2
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %11, label %24

11:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  store i32 0, ptr %4, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -2147483645, ptr %12, align 4, !tbaa !10
  %13 = load ptr, ptr @stderr, align 8, !tbaa !11
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 88) #9
  %15 = load ptr, ptr @stderr, align 8, !tbaa !11
  %16 = invoke noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483645, ptr noundef %1)
          to label %17 unwind label %22

17:                                               ; preds = %11
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.3, ptr noundef %16) #9
  invoke void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %4)
          to label %19 unwind label %22

19:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  br label %148

20:                                               ; preds = %2
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %150

22:                                               ; preds = %17, %11
  %23 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  br label %150

24:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #8
  store ptr null, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 504, ptr nonnull %7) #8
  invoke void @_Z18lodepng_state_initP12LodePNGState(ptr noundef nonnull %7)
          to label %25 unwind label %32

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %0, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = add i32 %29, -4
  %31 = call i32 @llvm.fshl.i32(i32 %30, i32 %30, i32 30)
  switch i32 %31, label %.loopexit [
    i32 0, label %34
    i32 1, label %79
    i32 3, label %109
    i32 5, label %110
  ]

32:                                               ; preds = %109, %74, %._crit_edge, %24
  %33 = landingpad { ptr, i32 }
          cleanup
  br label %149

34:                                               ; preds = %25
  %35 = getelementptr inbounds i8, ptr %7, i64 144
  %36 = getelementptr inbounds i8, ptr %7, i64 148
  store i32 4, ptr %36, align 4, !tbaa !16
  store i32 3, ptr %35, align 8, !tbaa !28
  %37 = getelementptr inbounds i8, ptr %7, i64 200
  %38 = getelementptr inbounds i8, ptr %7, i64 204
  store i32 4, ptr %38, align 4, !tbaa !29
  store i32 3, ptr %37, align 8, !tbaa !30
  %39 = getelementptr inbounds i8, ptr %7, i64 104
  store i32 0, ptr %39, align 8, !tbaa !31
  %.not64 = icmp eq i32 %29, 31
  br i1 %.not64, label %._crit_edge, label %.lr.ph62

.lr.ph62:                                         ; preds = %34
  %40 = getelementptr inbounds i8, ptr %0, i64 32
  br label %41

41:                                               ; preds = %.lr.ph62, %59
  %indvars.iv66 = phi i64 [ 0, %.lr.ph62 ], [ %indvars.iv.next67, %59 ]
  %42 = load ptr, ptr %40, align 8, !tbaa !32
  %43 = shl nsw i64 %indvars.iv66, 2
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !33
  %46 = getelementptr inbounds i8, ptr %44, i64 1
  %47 = load i8, ptr %46, align 1, !tbaa !33
  %48 = getelementptr inbounds i8, ptr %44, i64 2
  %49 = load i8, ptr %48, align 1, !tbaa !33
  %50 = getelementptr inbounds i8, ptr %44, i64 3
  %51 = load i8, ptr %50, align 1, !tbaa !33
  %52 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef nonnull %37, i8 noundef zeroext %45, i8 noundef zeroext %47, i8 noundef zeroext %49, i8 noundef zeroext %51)
          to label %53 unwind label %64

53:                                               ; preds = %41
  %54 = load i8, ptr %44, align 1, !tbaa !33
  %55 = load i8, ptr %46, align 1, !tbaa !33
  %56 = load i8, ptr %48, align 1, !tbaa !33
  %57 = load i8, ptr %50, align 1, !tbaa !33
  %58 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef nonnull %35, i8 noundef zeroext %54, i8 noundef zeroext %55, i8 noundef zeroext %56, i8 noundef zeroext %57)
          to label %59 unwind label %64

59:                                               ; preds = %53
  %indvars.iv.next67 = add nuw nsw i64 %indvars.iv66, 1
  %60 = load i32, ptr %28, align 4, !tbaa !15
  %61 = shl nuw i32 1, %60
  %62 = sext i32 %61 to i64
  %63 = icmp slt i64 %indvars.iv.next67, %62
  br i1 %63, label %41, label %._crit_edge, !llvm.loop !34

64:                                               ; preds = %53, %41
  %65 = landingpad { ptr, i32 }
          cleanup
  br label %149

._crit_edge:                                      ; preds = %59, %34
  %66 = getelementptr inbounds i8, ptr %0, i64 4
  %67 = load i32, ptr %66, align 4, !tbaa !36
  %68 = sdiv i32 %67, 2
  %69 = getelementptr inbounds i8, ptr %0, i64 8
  %70 = load i32, ptr %69, align 8, !tbaa !37
  %71 = mul nsw i32 %68, %70
  %72 = sext i32 %71 to i64
  %73 = invoke noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %72, i32 noundef 65560, ptr noundef nonnull @.str.5)
          to label %74 unwind label %32

74:                                               ; preds = %._crit_edge
  %75 = load i32, ptr %66, align 4, !tbaa !36
  %76 = sdiv i32 %75, 2
  %77 = load ptr, ptr %26, align 8, !tbaa !13
  %78 = load i32, ptr %69, align 8, !tbaa !37
  invoke void @_ZN2rw15compressPal4_BEEPhjS0_jii(ptr noundef %73, i32 noundef %76, ptr noundef %77, i32 noundef %75, i32 noundef %75, i32 noundef %78)
          to label %.loopexit unwind label %32

79:                                               ; preds = %25
  %80 = getelementptr inbounds i8, ptr %7, i64 144
  store i32 3, ptr %80, align 8, !tbaa !28
  %81 = getelementptr inbounds i8, ptr %7, i64 200
  store i32 3, ptr %81, align 8, !tbaa !30
  %82 = getelementptr inbounds i8, ptr %7, i64 104
  store i32 0, ptr %82, align 8, !tbaa !31
  %.not63 = icmp eq i32 %29, 31
  br i1 %.not63, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %79
  %83 = getelementptr inbounds i8, ptr %0, i64 32
  br label %84

84:                                               ; preds = %.lr.ph, %102
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %102 ]
  %85 = load ptr, ptr %83, align 8, !tbaa !32
  %86 = shl nsw i64 %indvars.iv, 2
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !33
  %89 = getelementptr inbounds i8, ptr %87, i64 1
  %90 = load i8, ptr %89, align 1, !tbaa !33
  %91 = getelementptr inbounds i8, ptr %87, i64 2
  %92 = load i8, ptr %91, align 1, !tbaa !33
  %93 = getelementptr inbounds i8, ptr %87, i64 3
  %94 = load i8, ptr %93, align 1, !tbaa !33
  %95 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef nonnull %81, i8 noundef zeroext %88, i8 noundef zeroext %90, i8 noundef zeroext %92, i8 noundef zeroext %94)
          to label %96 unwind label %107

96:                                               ; preds = %84
  %97 = load i8, ptr %87, align 1, !tbaa !33
  %98 = load i8, ptr %89, align 1, !tbaa !33
  %99 = load i8, ptr %91, align 1, !tbaa !33
  %100 = load i8, ptr %93, align 1, !tbaa !33
  %101 = invoke noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef nonnull %80, i8 noundef zeroext %97, i8 noundef zeroext %98, i8 noundef zeroext %99, i8 noundef zeroext %100)
          to label %102 unwind label %107

102:                                              ; preds = %96
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %103 = load i32, ptr %28, align 4, !tbaa !15
  %104 = shl nuw i32 1, %103
  %105 = sext i32 %104 to i64
  %106 = icmp slt i64 %indvars.iv.next, %105
  br i1 %106, label %84, label %.loopexit, !llvm.loop !38

107:                                              ; preds = %96, %84
  %108 = landingpad { ptr, i32 }
          cleanup
  br label %149

109:                                              ; preds = %25
  invoke void @_ZN2rw5Image11convertTo32Ev(ptr noundef nonnull align 8 dereferenceable(40) %0)
          to label %.loopexit unwind label %32

110:                                              ; preds = %25
  %111 = getelementptr inbounds i8, ptr %7, i64 144
  store i32 2, ptr %111, align 8, !tbaa !28
  %112 = getelementptr inbounds i8, ptr %7, i64 200
  store i32 2, ptr %112, align 8, !tbaa !30
  %113 = getelementptr inbounds i8, ptr %7, i64 104
  store i32 0, ptr %113, align 8, !tbaa !31
  br label %.loopexit

.loopexit:                                        ; preds = %102, %79, %109, %74, %110, %25
  %.053 = phi ptr [ %27, %25 ], [ %27, %110 ], [ %27, %109 ], [ %73, %74 ], [ %27, %79 ], [ %27, %102 ]
  %114 = getelementptr inbounds i8, ptr %0, i64 4
  %115 = load i32, ptr %114, align 4, !tbaa !36
  %116 = getelementptr inbounds i8, ptr %0, i64 8
  %117 = load i32, ptr %116, align 8, !tbaa !37
  %118 = invoke noundef i32 @_Z14lodepng_encodePPhPmPKhjjP12LodePNGState(ptr noundef nonnull %6, ptr noundef nonnull %5, ptr noundef %.053, i32 noundef %115, i32 noundef %117, ptr noundef nonnull %7)
          to label %119 unwind label %131

119:                                              ; preds = %.loopexit
  %.not55 = icmp eq i32 %118, 0
  br i1 %.not55, label %135, label %120

120:                                              ; preds = %119
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #8
  store i32 0, ptr %8, align 4, !tbaa !5
  %121 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 -2147483647, ptr %121, align 4, !tbaa !10
  %122 = load ptr, ptr @stderr, align 8, !tbaa !11
  %123 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %122, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 141) #9
  %124 = load ptr, ptr @stderr, align 8, !tbaa !11
  %125 = invoke noundef ptr @_Z18lodepng_error_textj(i32 noundef %118)
          to label %126 unwind label %133

126:                                              ; preds = %120
  %127 = invoke noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483647, ptr noundef %125)
          to label %128 unwind label %133

128:                                              ; preds = %126
  %129 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %124, ptr noundef nonnull @.str.3, ptr noundef %127) #9
  invoke void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %8)
          to label %130 unwind label %133

130:                                              ; preds = %128
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #8
  br label %147

131:                                              ; preds = %144, %139, %137, %.loopexit
  %132 = landingpad { ptr, i32 }
          cleanup
  br label %149

133:                                              ; preds = %128, %126, %120
  %134 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #8
  br label %149

135:                                              ; preds = %119
  %136 = load ptr, ptr %26, align 8, !tbaa !13
  %.not56 = icmp eq ptr %.053, %136
  br i1 %.not56, label %139, label %137

137:                                              ; preds = %135
  %138 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !39
  invoke void %138(ptr noundef %.053)
          to label %139 unwind label %131

139:                                              ; preds = %137, %135
  %140 = load ptr, ptr %6, align 8, !tbaa !11
  %141 = load i64, ptr %5, align 8, !tbaa !41
  %142 = trunc i64 %141 to i32
  %143 = invoke noundef i32 @_ZN2rw10StreamFile6write8EPKvj(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef %140, i32 noundef %142)
          to label %144 unwind label %131

144:                                              ; preds = %139
  invoke void @_ZN2rw10StreamFile5closeEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
          to label %145 unwind label %131

145:                                              ; preds = %144
  %146 = load ptr, ptr %6, align 8, !tbaa !11
  call void @free(ptr noundef %146) #8
  br label %147

147:                                              ; preds = %145, %130
  call void @llvm.lifetime.end.p0(i64 504, ptr nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #8
  br label %148

148:                                              ; preds = %147, %19
  call void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #8
  ret void

149:                                              ; preds = %131, %133, %107, %64, %32
  %.pn.pn = phi { ptr, i32 } [ %33, %32 ], [ %108, %107 ], [ %65, %64 ], [ %134, %133 ], [ %132, %131 ]
  call void @llvm.lifetime.end.p0(i64 504, ptr nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #8
  br label %150

150:                                              ; preds = %149, %22, %20
  %.pn.pn.pn = phi { ptr, i32 } [ %.pn.pn, %149 ], [ %23, %22 ], [ %21, %20 ]
  call void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #8
  resume { ptr, i32 } %.pn.pn.pn
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw10StreamFileC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #5 align 2

declare noundef ptr @_ZN2rw10StreamFile4openEPKcS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare noundef i32 @_Z19lodepng_palette_addP16LodePNGColorModehhhh(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

declare void @_ZN2rw15compressPal4_BEEPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @_ZN2rw5Image11convertTo32Ev(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1

declare noundef i32 @_Z14lodepng_encodePPhPmPKhjjP12LodePNGState(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare noundef i32 @_ZN2rw10StreamFile6write8EPKvj(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #1

declare void @_ZN2rw10StreamFile5closeEv(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw6StreamD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #5 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { cold nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"_ZTSN2rw5ImageE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !12, i64 24, !12, i64 32}
!15 = !{!14, !7, i64 12}
!16 = !{!17, !7, i64 148}
!17 = !{!"_ZTS12LodePNGState", !18, i64 0, !20, i64 56, !23, i64 144, !26, i64 184, !7, i64 496}
!18 = !{!"_ZTS22LodePNGDecoderSettings", !19, i64 0, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52}
!19 = !{!"_ZTS25LodePNGDecompressSettings", !7, i64 0, !7, i64 4, !12, i64 8, !12, i64 16, !12, i64 24}
!20 = !{!"_ZTS22LodePNGEncoderSettings", !21, i64 0, !7, i64 48, !7, i64 52, !22, i64 56, !12, i64 64, !7, i64 72, !7, i64 76, !7, i64 80}
!21 = !{!"_ZTS23LodePNGCompressSettings", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !12, i64 24, !12, i64 32, !12, i64 40}
!22 = !{!"_ZTS21LodePNGFilterStrategy", !8, i64 0}
!23 = !{!"_ZTS16LodePNGColorMode", !24, i64 0, !7, i64 4, !12, i64 8, !25, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36}
!24 = !{!"_ZTS16LodePNGColorType", !8, i64 0}
!25 = !{!"long", !8, i64 0}
!26 = !{!"_ZTS11LodePNGInfo", !7, i64 0, !7, i64 4, !7, i64 8, !23, i64 16, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !25, i64 72, !12, i64 80, !12, i64 88, !25, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !7, i64 136, !27, i64 140, !7, i64 164, !7, i64 168, !7, i64 172, !7, i64 176, !7, i64 180, !7, i64 184, !7, i64 188, !7, i64 192, !7, i64 196, !7, i64 200, !7, i64 204, !7, i64 208, !7, i64 212, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !12, i64 240, !12, i64 248, !7, i64 256, !8, i64 264, !8, i64 288}
!27 = !{!"_ZTS11LodePNGTime", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!28 = !{!17, !24, i64 144}
!29 = !{!17, !7, i64 204}
!30 = !{!17, !24, i64 200}
!31 = !{!17, !7, i64 104}
!32 = !{!14, !12, i64 32}
!33 = !{!8, !8, i64 0}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = !{!14, !7, i64 4}
!37 = !{!14, !7, i64 8}
!38 = distinct !{!38, !35}
!39 = !{!40, !12, i64 16}
!40 = !{!"_ZTSN2rw15MemoryFunctionsE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!41 = !{!25, !25, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass