; LLVM IR from fhanau/Efficient-Compression-Tool :: src/lodepng/lodepng.ll (ZN7lodepng6decodeEPPhRmRjS3_PKhm16LodePNGColorTypej)

; 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"

%"class.lodepng::State" = type { %struct.LodePNGState }
%struct.LodePNGState = type { %struct.LodePNGDecoderSettings, %struct.LodePNGEncoderSettings, %struct.LodePNGColorMode, %struct.LodePNGInfo, %struct.LodePNGColorMode, i32, i32, i32 }
%struct.LodePNGDecoderSettings = type { i32, i32, i32 }
%struct.LodePNGEncoderSettings = type { %struct.LodePNGCompressSettings, i32, i32, i32, ptr, i32, i32, i16, i32 }
%struct.LodePNGCompressSettings = type { ptr, ptr }
%struct.LodePNGInfo = type { i32, i32, i32, %struct.LodePNGColorMode, i32, i32, i32, i32, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, [3 x ptr], [3 x i64] }
%struct.LodePNGColorMode = type { i32, i32, ptr, i64, i32, i32, i32, i32 }

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

; 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) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z20lodepng_get_raw_sizejjPK16LodePNGColorMode(i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z21lodepng_decode_memoryPPhPjS1_PKhm16LodePNGColorTypej(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7lodepng6decodeEPPhRmRjS3_PKhm16LodePNGColorTypej(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, i32 noundef %7) #2 personality ptr @__gxx_personality_v0 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %"class.lodepng::State", align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i64 %5, ptr %14, align 8, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !11
  store i32 %7, ptr %16, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = load i64, ptr %14, align 8, !tbaa !9
  %26 = load i32, ptr %15, align 4, !tbaa !11
  %27 = load i32, ptr %16, align 4, !tbaa !13
  %28 = call noundef i32 @_Z21lodepng_decode_memoryPPhPjS1_PKhm16LodePNGColorTypej(ptr noundef %21, ptr noundef %22, ptr noundef %23, ptr noundef %24, i64 noundef %25, i32 noundef %26, i32 noundef %27)
  store i32 %28, ptr %17, align 4, !tbaa !13
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %54

32:                                               ; preds = %8
  %33 = load i32, ptr %17, align 4, !tbaa !13
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %54, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 352, ptr %18) #3
  call void @_ZN7lodepng5StateC1Ev(ptr noundef nonnull align 8 dereferenceable(352) %18)
  %36 = load i32, ptr %15, align 4, !tbaa !11
  %37 = getelementptr inbounds %struct.LodePNGState, ptr %18, i32 0, i32 2
  %38 = getelementptr inbounds %struct.LodePNGColorMode, ptr %37, i32 0, i32 0
  store i32 %36, ptr %38, align 8, !tbaa !15
  %39 = load i32, ptr %16, align 4, !tbaa !13
  %40 = getelementptr inbounds %struct.LodePNGState, ptr %18, i32 0, i32 2
  %41 = getelementptr inbounds %struct.LodePNGColorMode, ptr %40, i32 0, i32 1
  store i32 %39, ptr %41, align 4, !tbaa !24
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = getelementptr inbounds %struct.LodePNGState, ptr %18, i32 0, i32 2
  %47 = invoke noundef i64 @_Z20lodepng_get_raw_sizejjPK16LodePNGColorMode(i32 noundef %43, i32 noundef %45, ptr noundef %46)
          to label %48 unwind label %50

48:                                               ; preds = %35
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %47, ptr %49, align 8, !tbaa !9
  call void @_ZN7lodepng5StateD1Ev(ptr noundef nonnull align 8 dereferenceable(352) %18) #3
  call void @llvm.lifetime.end.p0(i64 352, ptr %18) #3
  br label %62

50:                                               ; preds = %35
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %19, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %20, align 4
  call void @_ZN7lodepng5StateD1Ev(ptr noundef nonnull align 8 dereferenceable(352) %18) #3
  call void @llvm.lifetime.end.p0(i64 352, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %64

54:                                               ; preds = %32, %8
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %61

58:                                               ; preds = %54
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  call void @free(ptr noundef %60) #3
  br label %61

61:                                               ; preds = %58, %54
  br label %62

62:                                               ; preds = %61, %48
  %63 = load i32, ptr %17, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  ret i32 %63

64:                                               ; preds = %50
  %65 = load ptr, ptr %19, align 8
  %66 = load i32, ptr %20, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

declare void @_ZN7lodepng5StateC1Ev(ptr)

declare void @_ZN7lodepng5StateD1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS16LodePNGColorType", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !12, i64 72}
!16 = !{!"_ZTS12LodePNGState", !17, i64 0, !18, i64 16, !22, i64 72, !23, i64 112, !22, i64 296, !14, i64 336, !14, i64 340, !14, i64 344}
!17 = !{!"_ZTS22LodePNGDecoderSettings", !14, i64 0, !14, i64 4, !14, i64 8}
!18 = !{!"_ZTS22LodePNGEncoderSettings", !19, i64 0, !14, i64 16, !14, i64 20, !20, i64 24, !6, i64 32, !14, i64 40, !14, i64 44, !21, i64 48, !14, i64 52}
!19 = !{!"_ZTS23LodePNGCompressSettings", !6, i64 0, !6, i64 8}
!20 = !{!"_ZTS21LodePNGFilterStrategy", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!"_ZTS16LodePNGColorMode", !12, i64 0, !14, i64 4, !6, i64 8, !10, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36}
!23 = !{!"_ZTS11LodePNGInfo", !14, i64 0, !14, i64 4, !14, i64 8, !22, i64 16, !14, i64 56, !14, i64 60, !14, i64 64, !14, i64 68, !10, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !7, i64 136, !7, i64 160}
!24 = !{!16, !14, i64 76}


; 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"

%"class.lodepng::State" = type { %struct.LodePNGState }
%struct.LodePNGState = type { %struct.LodePNGDecoderSettings, %struct.LodePNGEncoderSettings, %struct.LodePNGColorMode, %struct.LodePNGInfo, %struct.LodePNGColorMode, i32, i32, i32 }
%struct.LodePNGDecoderSettings = type { i32, i32, i32 }
%struct.LodePNGEncoderSettings = type { %struct.LodePNGCompressSettings, i32, i32, i32, ptr, i32, i32, i16, i32 }
%struct.LodePNGCompressSettings = type { ptr, ptr }
%struct.LodePNGInfo = type { i32, i32, i32, %struct.LodePNGColorMode, i32, i32, i32, i32, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, [3 x ptr], [3 x i64] }
%struct.LodePNGColorMode = type { i32, i32, ptr, i64, i32, i32, i32, i32 }

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

; 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 #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z20lodepng_get_raw_sizejjPK16LodePNGColorMode(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z21lodepng_decode_memoryPPhPjS1_PKhm16LodePNGColorTypej(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7lodepng6decodeEPPhRmRjS3_PKhm16LodePNGColorTypej(ptr noundef %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %9 = alloca %"class.lodepng::State", align 8
  %10 = tail call noundef i32 @_Z21lodepng_decode_memoryPPhPjS1_PKhm16LodePNGColorTypej(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, i32 noundef %7)
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  %13 = icmp ne i32 %10, 0
  %or.cond = or i1 %13, %12
  br i1 %or.cond, label %23, label %14

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 352, ptr nonnull %9) #3
  call void @_ZN7lodepng5StateC1Ev(ptr noundef nonnull align 8 dereferenceable(352) %9)
  %15 = getelementptr inbounds i8, ptr %9, i64 72
  store i32 %6, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %9, i64 76
  store i32 %7, ptr %16, align 4, !tbaa !21
  %17 = load i32, ptr %2, align 4, !tbaa !22
  %18 = load i32, ptr %3, align 4, !tbaa !22
  %19 = invoke noundef i64 @_Z20lodepng_get_raw_sizejjPK16LodePNGColorMode(i32 noundef %17, i32 noundef %18, ptr noundef nonnull %15)
          to label %20 unwind label %21

20:                                               ; preds = %14
  store i64 %19, ptr %1, align 8, !tbaa !23
  call void @_ZN7lodepng5StateD1Ev(ptr noundef nonnull align 8 dereferenceable(352) %9) #3
  call void @llvm.lifetime.end.p0(i64 352, ptr nonnull %9) #3
  br label %25

21:                                               ; preds = %14
  %22 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN7lodepng5StateD1Ev(ptr noundef nonnull align 8 dereferenceable(352) %9) #3
  call void @llvm.lifetime.end.p0(i64 352, ptr nonnull %9) #3
  resume { ptr, i32 } %22

23:                                               ; preds = %8
  br i1 %12, label %25, label %24

24:                                               ; preds = %23
  tail call void @free(ptr noundef nonnull %11) #3
  br label %25

25:                                               ; preds = %23, %24, %20
  ret i32 %10
}

declare void @_ZN7lodepng5StateC1Ev(ptr) local_unnamed_addr

declare void @_ZN7lodepng5StateD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !18, i64 72}
!10 = !{!"_ZTS12LodePNGState", !11, i64 0, !13, i64 16, !17, i64 72, !20, i64 112, !17, i64 296, !12, i64 336, !12, i64 340, !12, i64 344}
!11 = !{!"_ZTS22LodePNGDecoderSettings", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS22LodePNGEncoderSettings", !14, i64 0, !12, i64 16, !12, i64 20, !15, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !16, i64 48, !12, i64 52}
!14 = !{!"_ZTS23LodePNGCompressSettings", !6, i64 0, !6, i64 8}
!15 = !{!"_ZTS21LodePNGFilterStrategy", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS16LodePNGColorMode", !18, i64 0, !12, i64 4, !6, i64 8, !19, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!18 = !{!"_ZTS16LodePNGColorType", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTS11LodePNGInfo", !12, i64 0, !12, i64 4, !12, i64 8, !17, i64 16, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !19, i64 72, !6, i64 80, !6, i64 88, !19, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !7, i64 136, !7, i64 160}
!21 = !{!10, !12, i64 76}
!22 = !{!12, !12, i64 0}
!23 = !{!19, !19, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass