; LLVM IR from fhanau/Efficient-Compression-Tool :: src/optipng (codec)

; 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.opng_codec_context = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32, i32, i8 }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@_ZTIPKc = external constant ptr
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL13opng_sig_IEND = external hidden constant [4 x i8], align 1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #0

declare void @opng_error(ptr noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef) #4

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #5

declare ptr @__cxa_begin_catch(ptr)

declare void @__cxa_end_catch()

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

declare noalias ptr @png_create_write_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16opng_write_errorP14png_struct_defPKc(ptr noundef, ptr noundef) #6

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL18opng_write_warningP14png_struct_defPKc(ptr noundef, ptr noundef) #6

declare void @png_destroy_write_struct(ptr noundef, ptr noundef) #1

declare void @png_set_write_fn(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15opng_write_dataP14png_struct_defPhm(ptr noundef, ptr noundef, i64 noundef) #6

; Function Attrs: mustprogress uwtable
define dso_local i32 @opng_copy_png(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #6 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [8 x i8], align 1
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 4096, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store volatile i32 0, ptr %15, align 4, !tbaa !9
  %21 = call noalias ptr @png_create_write_struct(ptr noundef @.str, ptr noundef null, ptr noundef @_ZL16opng_write_errorP14png_struct_defPKc, ptr noundef @_ZL18opng_write_warningP14png_struct_defPKc)
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.opng_codec_context, ptr %22, i32 0, i32 4
  store ptr %21, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.opng_codec_context, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %5
  call void @opng_error(ptr noundef null, ptr noundef @.str.1)
  call void @exit(i32 noundef 1) #8
  unreachable

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.opng_codec_context, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  store ptr %32, ptr %16, align 8, !tbaa !5
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  call void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef %33)
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.opng_codec_context, ptr %35, i32 0, i32 2
  store ptr %34, ptr %36, align 8, !tbaa !16
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.opng_codec_context, ptr %38, i32 0, i32 3
  store ptr %37, ptr %39, align 8, !tbaa !17
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.opng_codec_context, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_set_write_fn(ptr noundef %42, ptr noundef %43, ptr noundef @_ZL15opng_write_dataP14png_struct_defPhm, ptr noundef null)
  store volatile ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  store i32 0, ptr %17, align 4, !tbaa !9
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.opng_codec_context, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  invoke void @png_write_sig(ptr noundef %46)
          to label %47 unwind label %57

47:                                               ; preds = %29
  br label %48

48:                                               ; preds = %163, %47
  %49 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = invoke i64 @fread(ptr noundef %49, i64 noundef 8, i64 noundef 1, ptr noundef %50)
          to label %52 unwind label %57

52:                                               ; preds = %48
  %53 = icmp ne i64 %51, 1
  br i1 %53, label %54, label %79

54:                                               ; preds = %52
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  invoke void @opng_error(ptr noundef %55, ptr noundef @.str.2)
          to label %56 unwind label %57

56:                                               ; preds = %54
  store volatile i32 -1, ptr %15, align 4, !tbaa !9
  br label %168

57:                                               ; preds = %153, %150, %141, %124, %119, %111, %54, %48, %29
  %58 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPKc
  %59 = extractvalue { ptr, i32 } %58, 0
  store ptr %59, ptr %18, align 8
  %60 = extractvalue { ptr, i32 } %58, 1
  store i32 %60, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  br label %61

61:                                               ; preds = %57
  %62 = load i32, ptr %19, align 4
  %63 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTIPKc) #7
  %64 = icmp eq i32 %62, %63
  br i1 %64, label %65, label %173

65:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #7
  %66 = load ptr, ptr %18, align 8
  %67 = call ptr @__cxa_begin_catch(ptr %66) #7
  store ptr %67, ptr %20, align 8
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %20, align 8, !tbaa !5
  invoke void @opng_error(ptr noundef %68, ptr noundef %69)
          to label %70 unwind label %169

70:                                               ; preds = %65
  store volatile i32 -1, ptr %15, align 4, !tbaa !9
  call void @__cxa_end_catch() #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #7
  br label %71

71:                                               ; preds = %168, %70
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.opng_codec_context, ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = load volatile ptr, ptr %11, align 8, !tbaa !5
  call void @png_free(ptr noundef %74, ptr noundef %75)
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.opng_codec_context, ptr %76, i32 0, i32 4
  call void @png_destroy_write_struct(ptr noundef %77, ptr noundef null)
  %78 = load volatile i32, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  ret i32 %78

79:                                               ; preds = %52
  %80 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %81 = load i8, ptr %80, align 1, !tbaa !18
  %82 = zext i8 %81 to i32
  %83 = shl i32 %82, 24
  %84 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %85 = getelementptr inbounds i8, ptr %84, i64 1
  %86 = load i8, ptr %85, align 1, !tbaa !18
  %87 = zext i8 %86 to i32
  %88 = shl i32 %87, 16
  %89 = add i32 %83, %88
  %90 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %91 = getelementptr inbounds i8, ptr %90, i64 2
  %92 = load i8, ptr %91, align 1, !tbaa !18
  %93 = zext i8 %92 to i32
  %94 = shl i32 %93, 8
  %95 = add i32 %89, %94
  %96 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %97 = getelementptr inbounds i8, ptr %96, i64 3
  %98 = load i8, ptr %97, align 1, !tbaa !18
  %99 = zext i8 %98 to i32
  %100 = add i32 %95, %99
  store i32 %100, ptr %13, align 4, !tbaa !9
  %101 = load i32, ptr %13, align 4, !tbaa !9
  %102 = icmp ugt i32 %101, 2147483647
  br i1 %102, label %103, label %114

103:                                              ; preds = %79
  %104 = load volatile ptr, ptr %11, align 8, !tbaa !5
  %105 = icmp ne ptr %104, null
  br i1 %105, label %111, label %106

106:                                              ; preds = %103
  %107 = load i32, ptr %13, align 4, !tbaa !9
  %108 = zext i32 %107 to i64
  %109 = icmp eq i64 %108, 2303741511
  br i1 %109, label %110, label %111

110:                                              ; preds = %106
  br label %163

111:                                              ; preds = %106, %103
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  invoke void @opng_error(ptr noundef %112, ptr noundef @.str.3)
          to label %113 unwind label %57

113:                                              ; preds = %111
  store volatile i32 -1, ptr %15, align 4, !tbaa !9
  br label %168

114:                                              ; preds = %79
  %115 = load i32, ptr %13, align 4, !tbaa !9
  %116 = add i32 %115, 4
  %117 = load i32, ptr %17, align 4, !tbaa !9
  %118 = icmp ugt i32 %116, %117
  br i1 %118, label %119, label %141

119:                                              ; preds = %114
  %120 = load ptr, ptr %6, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.opng_codec_context, ptr %120, i32 0, i32 4
  %122 = load ptr, ptr %121, align 8, !tbaa !11
  %123 = load volatile ptr, ptr %11, align 8, !tbaa !5
  invoke void @png_free(ptr noundef %122, ptr noundef %123)
          to label %124 unwind label %57

124:                                              ; preds = %119
  %125 = load i32, ptr %13, align 4, !tbaa !9
  %126 = add i32 %125, 4
  %127 = add i32 %126, 4095
  %128 = udiv i32 %127, 4096
  %129 = mul i32 %128, 4096
  store i32 %129, ptr %17, align 4, !tbaa !9
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.opng_codec_context, ptr %130, i32 0, i32 4
  %132 = load ptr, ptr %131, align 8, !tbaa !11
  %133 = load i32, ptr %17, align 4, !tbaa !9
  %134 = zext i32 %133 to i64
  %135 = invoke noalias ptr @png_malloc(ptr noundef %132, i64 noundef %134)
          to label %136 unwind label %57

136:                                              ; preds = %124
  store volatile ptr %135, ptr %11, align 8, !tbaa !5
  %137 = load volatile ptr, ptr %11, align 8, !tbaa !5
  %138 = icmp ne ptr %137, null
  br i1 %138, label %140, label %139

139:                                              ; preds = %136
  call void @exit(i32 noundef 1) #8
  unreachable

140:                                              ; preds = %136
  br label %141

141:                                              ; preds = %140, %114
  %142 = load volatile ptr, ptr %11, align 8, !tbaa !5
  %143 = load i32, ptr %13, align 4, !tbaa !9
  %144 = add i32 %143, 4
  %145 = zext i32 %144 to i64
  %146 = load ptr, ptr %7, align 8, !tbaa !5
  %147 = invoke i64 @fread(ptr noundef %142, i64 noundef %145, i64 noundef 1, ptr noundef %146)
          to label %148 unwind label %57

148:                                              ; preds = %141
  %149 = icmp ne i64 %147, 1
  br i1 %149, label %150, label %153

150:                                              ; preds = %148
  %151 = load ptr, ptr %8, align 8, !tbaa !5
  invoke void @opng_error(ptr noundef %151, ptr noundef @.str.2)
          to label %152 unwind label %57

152:                                              ; preds = %150
  store volatile i32 -1, ptr %15, align 4, !tbaa !9
  br label %168

153:                                              ; preds = %148
  %154 = load ptr, ptr %6, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.opng_codec_context, ptr %154, i32 0, i32 4
  %156 = load ptr, ptr %155, align 8, !tbaa !11
  %157 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %158 = getelementptr inbounds i8, ptr %157, i64 4
  %159 = load volatile ptr, ptr %11, align 8, !tbaa !5
  %160 = load i32, ptr %13, align 4, !tbaa !9
  %161 = zext i32 %160 to i64
  invoke void @png_write_chunk(ptr noundef %156, ptr noundef %158, ptr noundef %159, i64 noundef %161)
          to label %162 unwind label %57

162:                                              ; preds = %153
  br label %163

163:                                              ; preds = %162, %110
  %164 = getelementptr inbounds [8 x i8], ptr %14, i64 0, i64 0
  %165 = getelementptr inbounds i8, ptr %164, i64 4
  %166 = call i32 @memcmp(ptr noundef %165, ptr noundef @_ZL13opng_sig_IEND, i64 noundef 4) #9
  %167 = icmp ne i32 %166, 0
  br i1 %167, label %48, label %168, !llvm.loop !19

168:                                              ; preds = %163, %152, %113, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  br label %71

169:                                              ; preds = %65
  %170 = landingpad { ptr, i32 }
          cleanup
  %171 = extractvalue { ptr, i32 } %170, 0
  store ptr %171, ptr %18, align 8
  %172 = extractvalue { ptr, i32 } %170, 1
  store i32 %172, ptr %19, align 4
  call void @__cxa_end_catch() #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #7
  br label %173

173:                                              ; preds = %169, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %174

174:                                              ; preds = %173
  %175 = load ptr, ptr %18, align 8
  %176 = load i32, ptr %19, align 4
  %177 = insertvalue { ptr, i32 } poison, ptr %175, 0
  %178 = insertvalue { ptr, i32 } %177, i32 %176, 1
  resume { ptr, i32 } %178
}

declare void @png_write_sig(ptr noundef) #1

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

declare void @png_free(ptr noundef, ptr noundef) #1

declare noalias ptr @png_malloc(ptr noundef, i64 noundef) #1

declare void @png_write_chunk(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nounwind willreturn memory(read) "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 #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 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind memory(none) }
attributes #6 = { 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 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"_ZTS18opng_codec_context", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !14, i64 84}
!13 = !{!"long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !6, i64 24}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@_ZTIPKc = external constant ptr
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@_ZL13opng_sig_IEND = external hidden constant [4 x i8], align 1

declare void @opng_error(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef) local_unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #4

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

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

declare noalias ptr @png_create_write_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL16opng_write_errorP14png_struct_defPKc(ptr noundef, ptr noundef) #5

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL18opng_write_warningP14png_struct_defPKc(ptr noundef, ptr noundef) #5

declare void @png_destroy_write_struct(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @png_set_write_fn(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL15opng_write_dataP14png_struct_defPhm(ptr noundef, ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
define dso_local i32 @opng_copy_png(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca [8 x i8], align 1
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8)
  store volatile i32 0, ptr %8, align 4, !tbaa !5
  %9 = tail call noalias ptr @png_create_write_struct(ptr noundef nonnull @.str, ptr noundef null, ptr noundef nonnull @_ZL16opng_write_errorP14png_struct_defPKc, ptr noundef nonnull @_ZL18opng_write_warningP14png_struct_defPKc)
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %9, ptr %10, align 8, !tbaa !9
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %11, label %12

11:                                               ; preds = %5
  tail call void @opng_error(ptr noundef null, ptr noundef nonnull @.str.1)
  tail call void @exit(i32 noundef 1) #9
  unreachable

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  tail call void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef %14)
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %3, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %4, ptr %16, align 8, !tbaa !16
  %17 = load ptr, ptr %10, align 8, !tbaa !9
  tail call void @png_set_write_fn(ptr noundef %17, ptr noundef nonnull %0, ptr noundef nonnull @_ZL15opng_write_dataP14png_struct_defPhm, ptr noundef null)
  store volatile ptr null, ptr %6, align 8, !tbaa !17
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  invoke void @png_write_sig(ptr noundef %18)
          to label %.preheader unwind label %.loopexit.split-lp

.preheader:                                       ; preds = %12
  %19 = getelementptr inbounds i8, ptr %7, i64 1
  %20 = getelementptr inbounds i8, ptr %7, i64 2
  %21 = getelementptr inbounds i8, ptr %7, i64 3
  %22 = getelementptr inbounds i8, ptr %7, i64 4
  br label %23

23:                                               ; preds = %.preheader, %78
  %.0 = phi i32 [ %.2, %78 ], [ 0, %.preheader ]
  %24 = call i64 @fread(ptr noundef nonnull %7, i64 noundef 8, i64 noundef 1, ptr noundef %1)
  %.not49 = icmp eq i64 %24, 1
  br i1 %.not49, label %36, label %25

25:                                               ; preds = %23
  invoke void @opng_error(ptr noundef %2, ptr noundef nonnull @.str.2)
          to label %26 unwind label %.loopexit.split-lp

26:                                               ; preds = %25
  store volatile i32 -1, ptr %8, align 4, !tbaa !5
  br label %.loopexit53

.loopexit:                                        ; preds = %60, %62, %75
  %lpad.loopexit = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPKc
  br label %27

.loopexit.split-lp:                               ; preds = %12, %25, %55, %73
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPKc
  br label %27

27:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %28 = extractvalue { ptr, i32 } %lpad.phi, 1
  %29 = call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIPKc) #8
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %81

31:                                               ; preds = %27
  %32 = extractvalue { ptr, i32 } %lpad.phi, 0
  %33 = call ptr @__cxa_begin_catch(ptr %32) #8
  invoke void @opng_error(ptr noundef %4, ptr noundef %33)
          to label %34 unwind label %79

34:                                               ; preds = %31
  store volatile i32 -1, ptr %8, align 4, !tbaa !5
  call void @__cxa_end_catch() #8
  br label %.loopexit53

.loopexit53:                                      ; preds = %78, %26, %56, %74, %34
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %.0..0..0..0.16 = load volatile ptr, ptr %6, align 8, !tbaa !17
  call void @png_free(ptr noundef %35, ptr noundef %.0..0..0..0.16)
  call void @png_destroy_write_struct(ptr noundef nonnull %10, ptr noundef null)
  %.0..0..0..0.9 = load volatile i32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6)
  ret i32 %.0..0..0..0.9

36:                                               ; preds = %23
  %37 = load i8, ptr %7, align 1, !tbaa !18
  %38 = zext i8 %37 to i32
  %39 = shl nuw i32 %38, 24
  %40 = load i8, ptr %19, align 1, !tbaa !18
  %41 = zext i8 %40 to i32
  %42 = shl nuw nsw i32 %41, 16
  %43 = load i8, ptr %20, align 1, !tbaa !18
  %44 = zext i8 %43 to i32
  %45 = shl nuw nsw i32 %44, 8
  %46 = load i8, ptr %21, align 1, !tbaa !18
  %47 = zext i8 %46 to i32
  %48 = or disjoint i32 %42, %47
  %49 = or disjoint i32 %48, %45
  %50 = or disjoint i32 %49, %39
  %51 = icmp slt i32 %39, 0
  br i1 %51, label %52, label %57

52:                                               ; preds = %36
  %.0..0..0..0.17 = load volatile ptr, ptr %6, align 8, !tbaa !17
  %53 = icmp eq ptr %.0..0..0..0.17, null
  %54 = icmp eq i32 %50, -1991225785
  %or.cond = select i1 %53, i1 %54, i1 false
  br i1 %or.cond, label %78, label %55

55:                                               ; preds = %52
  invoke void @opng_error(ptr noundef %2, ptr noundef nonnull @.str.3)
          to label %56 unwind label %.loopexit.split-lp

56:                                               ; preds = %55
  store volatile i32 -1, ptr %8, align 4, !tbaa !5
  br label %.loopexit53

57:                                               ; preds = %36
  %58 = add nuw i32 %50, 4
  %59 = icmp ugt i32 %58, %.0
  br i1 %59, label %60, label %70

60:                                               ; preds = %57
  %61 = load ptr, ptr %10, align 8, !tbaa !9
  %.0..0..0..0.18 = load volatile ptr, ptr %6, align 8, !tbaa !17
  invoke void @png_free(ptr noundef %61, ptr noundef %.0..0..0..0.18)
          to label %62 unwind label %.loopexit

62:                                               ; preds = %60
  %63 = add nuw i32 %50, 4099
  %64 = and i32 %63, -4096
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = zext i32 %64 to i64
  %67 = invoke noalias ptr @png_malloc(ptr noundef %65, i64 noundef %66)
          to label %68 unwind label %.loopexit

68:                                               ; preds = %62
  store volatile ptr %67, ptr %6, align 8, !tbaa !17
  %.0..0..0..0.19 = load volatile ptr, ptr %6, align 8, !tbaa !17
  %.not50 = icmp eq ptr %.0..0..0..0.19, null
  br i1 %.not50, label %69, label %70

69:                                               ; preds = %68
  call void @exit(i32 noundef 1) #9
  unreachable

70:                                               ; preds = %68, %57
  %.1 = phi i32 [ %64, %68 ], [ %.0, %57 ]
  %.0..0..0..0.20 = load volatile ptr, ptr %6, align 8, !tbaa !17
  %71 = zext i32 %58 to i64
  %72 = call i64 @fread(ptr noundef %.0..0..0..0.20, i64 noundef %71, i64 noundef 1, ptr noundef %1)
  %.not51 = icmp eq i64 %72, 1
  br i1 %.not51, label %75, label %73

73:                                               ; preds = %70
  invoke void @opng_error(ptr noundef %2, ptr noundef nonnull @.str.2)
          to label %74 unwind label %.loopexit.split-lp

74:                                               ; preds = %73
  store volatile i32 -1, ptr %8, align 4, !tbaa !5
  br label %.loopexit53

75:                                               ; preds = %70
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  %.0..0..0..0.21 = load volatile ptr, ptr %6, align 8, !tbaa !17
  %77 = zext nneg i32 %50 to i64
  invoke void @png_write_chunk(ptr noundef %76, ptr noundef nonnull %22, ptr noundef %.0..0..0..0.21, i64 noundef %77)
          to label %78 unwind label %.loopexit

78:                                               ; preds = %75, %52
  %.2 = phi i32 [ %.0, %52 ], [ %.1, %75 ]
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(4) %22, ptr noundef nonnull dereferenceable(4) @_ZL13opng_sig_IEND, i64 4)
  %.not52 = icmp eq i32 %bcmp, 0
  br i1 %.not52, label %.loopexit53, label %23, !llvm.loop !19

79:                                               ; preds = %31
  %80 = landingpad { ptr, i32 }
          cleanup
  call void @__cxa_end_catch() #8
  br label %81

81:                                               ; preds = %79, %27
  %.merged = phi { ptr, i32 } [ %80, %79 ], [ %lpad.phi, %27 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6)
  resume { ptr, i32 } %.merged
}

declare void @png_write_sig(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

declare void @png_free(ptr noundef, ptr noundef) local_unnamed_addr #0

declare noalias ptr @png_malloc(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @png_write_chunk(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #7

attributes #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 #1 = { noreturn 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nofree nosync nounwind memory(none) }
attributes #5 = { 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 = { 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 #7 = { nofree nounwind willreturn memory(argmem: read) }
attributes #8 = { nounwind }
attributes #9 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 32}
!10 = !{!"_ZTS18opng_codec_context", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !12, i64 64, !6, i64 72, !6, i64 76, !6, i64 80, !13, i64 84}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !11, i64 24}
!17 = !{!11, !11, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass