; 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 }
%struct.opng_encoding_stats = type { i64, i64, 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

declare noalias ptr @png_create_info_struct(ptr noundef) #0

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

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

; Function Attrs: 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) #3

declare void @png_set_keep_unknown_chunks(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #0

declare i32 @__gxx_personality_v0(...)

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

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) #2

declare void @png_data_freer(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @opng_encode_image(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #5 personality ptr @__gxx_personality_v0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %17 = 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)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.opng_codec_context, ptr %18, i32 0, i32 4
  store ptr %17, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.opng_codec_context, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = call noalias ptr @png_create_info_struct(ptr noundef %22)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.opng_codec_context, ptr %24, i32 0, i32 5
  store ptr %23, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.opng_codec_context, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %35

30:                                               ; preds = %5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.opng_codec_context, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = icmp ne ptr %33, null
  br i1 %34, label %40, label %35

35:                                               ; preds = %30, %5
  call void @opng_error(ptr noundef null, ptr noundef @.str.1)
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.opng_codec_context, ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.opng_codec_context, ptr %38, i32 0, i32 5
  call void @png_destroy_write_struct(ptr noundef %37, ptr noundef %39)
  call void @exit(i32 noundef 1) #6
  unreachable

40:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.opng_codec_context, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  store ptr %43, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef %44)
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.opng_codec_context, ptr %46, i32 0, i32 2
  store ptr %45, ptr %47, align 8, !tbaa !17
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.opng_codec_context, ptr %49, i32 0, i32 3
  store ptr %48, ptr %50, align 8, !tbaa !18
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.opng_codec_context, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = icmp ne i32 %54, 0
  %56 = zext i1 %55 to i64
  %57 = select i1 %55, i32 248, i32 8
  invoke void @png_set_filter(ptr noundef %53, i32 noundef 0, i32 noundef %57)
          to label %58 unwind label %73

58:                                               ; preds = %40
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = icmp ne i32 %59, 6
  br i1 %60, label %61, label %89

61:                                               ; preds = %58
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.opng_codec_context, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 51
  br i1 %66, label %67, label %68

67:                                               ; preds = %61
  br label %70

68:                                               ; preds = %61
  %69 = load i32, ptr %11, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %68, %67
  %71 = phi i32 [ 5, %67 ], [ %69, %68 ]
  invoke void @png_set_compression_level(ptr noundef %64, i32 noundef %71)
          to label %72 unwind label %73

72:                                               ; preds = %70
  br label %89

73:                                               ; preds = %138, %133, %123, %119, %113, %93, %89, %70, %40
  %74 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPKc
  %75 = extractvalue { ptr, i32 } %74, 0
  store ptr %75, ptr %13, align 8
  %76 = extractvalue { ptr, i32 } %74, 1
  store i32 %76, ptr %14, align 4
  br label %77

77:                                               ; preds = %73
  %78 = load i32, ptr %14, align 4
  %79 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTIPKc) #7
  %80 = icmp eq i32 %78, %79
  br i1 %80, label %81, label %169

81:                                               ; preds = %77
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %82 = load ptr, ptr %13, align 8
  %83 = call ptr @__cxa_begin_catch(ptr %82) #7
  store ptr %83, ptr %15, align 8
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.opng_encoding_stats, ptr %84, i32 0, i32 0
  store i64 9223372036854775807, ptr %85, align 8, !tbaa !19
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %15, align 8, !tbaa !5
  invoke void @opng_error(ptr noundef %86, ptr noundef %87)
          to label %88 unwind label %146

88:                                               ; preds = %81
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  call void @__cxa_end_catch() #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  br label %167

89:                                               ; preds = %72, %58
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.opng_codec_context, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !11
  invoke void @png_set_compression_mem_level(ptr noundef %92, i32 noundef 8)
          to label %93 unwind label %73

93:                                               ; preds = %89
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.opng_codec_context, ptr %94, i32 0, i32 4
  %96 = load ptr, ptr %95, align 8, !tbaa !11
  invoke void @png_set_compression_window_bits(ptr noundef %96, i32 noundef 15)
          to label %97 unwind label %73

97:                                               ; preds = %93
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.opng_codec_context, ptr %98, i32 0, i32 4
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  %101 = load i32, ptr %11, align 4, !tbaa !9
  %102 = icmp eq i32 %101, 1
  br i1 %102, label %106, label %103

103:                                              ; preds = %97
  %104 = load i32, ptr %11, align 4, !tbaa !9
  %105 = icmp eq i32 %104, 51
  br i1 %105, label %106, label %112

106:                                              ; preds = %103, %97
  %107 = load i32, ptr %8, align 4, !tbaa !9
  %108 = icmp ne i32 %107, 0
  %109 = xor i1 %108, true
  %110 = xor i1 %109, true
  %111 = zext i1 %110 to i32
  br label %113

112:                                              ; preds = %103
  br label %113

113:                                              ; preds = %112, %106
  %114 = phi i32 [ %111, %106 ], [ 0, %112 ]
  invoke void @png_set_compression_strategy(ptr noundef %100, i32 noundef %114)
          to label %115 unwind label %73

115:                                              ; preds = %113
  %116 = load i32, ptr %11, align 4, !tbaa !9
  %117 = icmp eq i32 %116, 51
  br i1 %117, label %118, label %119

118:                                              ; preds = %115
  store i32 5, ptr %11, align 4, !tbaa !9
  br label %119

119:                                              ; preds = %118, %115
  %120 = load ptr, ptr %7, 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
  invoke void @png_set_keep_unknown_chunks(ptr noundef %122, i32 noundef 3, ptr noundef null, i32 noundef 0)
          to label %123 unwind label %73

123:                                              ; preds = %119
  %124 = load ptr, ptr %7, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.opng_codec_context, ptr %124, i32 0, i32 0
  %126 = load ptr, ptr %125, align 8, !tbaa !21
  %127 = load ptr, ptr %7, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.opng_codec_context, ptr %127, i32 0, i32 4
  %129 = load ptr, ptr %128, align 8, !tbaa !11
  %130 = load ptr, ptr %7, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.opng_codec_context, ptr %130, i32 0, i32 5
  %132 = load ptr, ptr %131, align 8, !tbaa !15
  invoke void @opng_store_image(ptr noundef %126, ptr noundef %129, ptr noundef %132)
          to label %133 unwind label %73

133:                                              ; preds = %123
  %134 = load ptr, ptr %7, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.opng_codec_context, ptr %134, i32 0, i32 4
  %136 = load ptr, ptr %135, align 8, !tbaa !11
  %137 = load ptr, ptr %7, align 8, !tbaa !5
  invoke void @png_set_write_fn(ptr noundef %136, ptr noundef %137, ptr noundef @_ZL15opng_write_dataP14png_struct_defPhm, ptr noundef null)
          to label %138 unwind label %73

138:                                              ; preds = %133
  %139 = load ptr, ptr %7, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.opng_codec_context, ptr %139, i32 0, i32 4
  %141 = load ptr, ptr %140, align 8, !tbaa !11
  %142 = load ptr, ptr %7, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.opng_codec_context, ptr %142, i32 0, i32 5
  %144 = load ptr, ptr %143, align 8, !tbaa !15
  invoke void @png_write_png(ptr noundef %141, ptr noundef %144, i32 noundef 0, ptr noundef null)
          to label %145 unwind label %73

145:                                              ; preds = %138
  br label %150

146:                                              ; preds = %81
  %147 = landingpad { ptr, i32 }
          cleanup
  %148 = extractvalue { ptr, i32 } %147, 0
  store ptr %148, ptr %13, align 8
  %149 = extractvalue { ptr, i32 } %147, 1
  store i32 %149, ptr %14, align 4
  call void @__cxa_end_catch() #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  br label %169

150:                                              ; preds = %145
  %151 = load ptr, ptr %7, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.opng_codec_context, ptr %151, i32 0, i32 4
  %153 = load ptr, ptr %152, align 8, !tbaa !11
  %154 = load ptr, ptr %7, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.opng_codec_context, ptr %154, i32 0, i32 5
  %156 = load ptr, ptr %155, align 8, !tbaa !15
  call void @png_data_freer(ptr noundef %153, ptr noundef %156, i32 noundef 2, i32 noundef 65535)
  %157 = load ptr, ptr %7, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.opng_codec_context, ptr %157, i32 0, i32 4
  %159 = load ptr, ptr %158, align 8, !tbaa !11
  %160 = load ptr, ptr %7, align 8, !tbaa !5
  %161 = getelementptr inbounds %struct.opng_codec_context, ptr %160, i32 0, i32 5
  %162 = load ptr, ptr %161, align 8, !tbaa !15
  call void @png_data_freer(ptr noundef %159, ptr noundef %162, i32 noundef 1, i32 noundef 12800)
  %163 = load ptr, ptr %7, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.opng_codec_context, ptr %163, i32 0, i32 4
  %165 = load ptr, ptr %7, align 8, !tbaa !5
  %166 = getelementptr inbounds %struct.opng_codec_context, ptr %165, i32 0, i32 5
  call void @png_destroy_write_struct(ptr noundef %164, ptr noundef %166)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %167

167:                                              ; preds = %150, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  %168 = load i32, ptr %6, align 4
  ret i32 %168

169:                                              ; preds = %146, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %170

170:                                              ; preds = %169
  %171 = load ptr, ptr %13, align 8
  %172 = load i32, ptr %14, align 4
  %173 = insertvalue { ptr, i32 } poison, ptr %171, 0
  %174 = insertvalue { ptr, i32 } %173, i32 %172, 1
  resume { ptr, i32 } %174
}

declare noalias ptr @png_create_write_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #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) #0

declare void @png_set_filter(ptr noundef, i32 noundef, i32 noundef) #0

declare void @png_set_compression_level(ptr noundef, i32 noundef) #0

declare void @png_set_compression_mem_level(ptr noundef, i32 noundef) #0

declare void @png_set_compression_window_bits(ptr noundef, i32 noundef) #0

declare void @png_set_compression_strategy(ptr noundef, i32 noundef) #0

declare void @opng_store_image(ptr noundef, ptr noundef, ptr noundef) #0

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

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

declare void @png_write_png(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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 = { 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 = { 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 = { noreturn nounwind }
attributes #7 = { 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 = !{!"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 40}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 24}
!19 = !{!20, !13, i64 0}
!20 = !{!"_ZTS19opng_encoding_stats", !13, i64 0, !13, i64 8, !10, i64 16, !14, i64 20}
!21 = !{!12, !6, 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"

@.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

declare noalias ptr @png_create_info_struct(ptr noundef) local_unnamed_addr #0

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 nounwind uwtable
declare hidden void @_ZL15opng_init_statsP19opng_encoding_stats(ptr noundef) local_unnamed_addr #2

declare void @png_set_keep_unknown_chunks(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

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

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

declare void @png_data_freer(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -1, 1) i32 @opng_encode_image(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #4 personality ptr @__gxx_personality_v0 {
  %6 = 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)
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = tail call noalias ptr @png_create_info_struct(ptr noundef %6)
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %8, ptr %9, align 8, !tbaa !13
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %10, null
  %.not52 = icmp eq ptr %8, null
  %or.cond54 = select i1 %.not, i1 true, i1 %.not52
  br i1 %or.cond54, label %11, label %12

11:                                               ; preds = %5
  tail call void @opng_error(ptr noundef null, ptr noundef nonnull @.str.1)
  tail call void @png_destroy_write_struct(ptr noundef nonnull %7, ptr noundef nonnull %9)
  tail call void @exit(i32 noundef 1) #5
  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 %2, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %3, ptr %16, align 8, !tbaa !16
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne i32 %1, 0
  %19 = select i1 %18, i32 248, i32 8
  invoke void @png_set_filter(ptr noundef %17, i32 noundef 0, i32 noundef %19)
          to label %20 unwind label %25

20:                                               ; preds = %12
  %.not53 = icmp eq i32 %4, 6
  br i1 %.not53, label %34, label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp eq i32 %4, 51
  %24 = select i1 %23, i32 5, i32 %4
  invoke void @png_set_compression_level(ptr noundef %22, i32 noundef %24)
          to label %34 unwind label %25

25:                                               ; preds = %52, %50, %46, %44, %42, %36, %34, %21, %12
  %26 = landingpad { ptr, i32 }
          cleanup
          catch ptr @_ZTIPKc
  %27 = extractvalue { ptr, i32 } %26, 1
  %28 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIPKc) #6
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %63

30:                                               ; preds = %25
  %31 = extractvalue { ptr, i32 } %26, 0
  %32 = tail call ptr @__cxa_begin_catch(ptr %31) #6
  store i64 9223372036854775807, ptr %14, align 8, !tbaa !17
  invoke void @opng_error(ptr noundef %3, ptr noundef %32)
          to label %33 unwind label %55

33:                                               ; preds = %30
  tail call void @__cxa_end_catch() #6
  br label %62

34:                                               ; preds = %21, %20
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  invoke void @png_set_compression_mem_level(ptr noundef %35, i32 noundef 8)
          to label %36 unwind label %25

36:                                               ; preds = %34
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  invoke void @png_set_compression_window_bits(ptr noundef %37, i32 noundef 15)
          to label %38 unwind label %25

38:                                               ; preds = %36
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  switch i32 %4, label %42 [
    i32 51, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  %41 = zext i1 %18 to i32
  br label %42

42:                                               ; preds = %38, %40
  %43 = phi i32 [ %41, %40 ], [ 0, %38 ]
  invoke void @png_set_compression_strategy(ptr noundef %39, i32 noundef %43)
          to label %44 unwind label %25

44:                                               ; preds = %42
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  invoke void @png_set_keep_unknown_chunks(ptr noundef %45, i32 noundef 3, ptr noundef null, i32 noundef 0)
          to label %46 unwind label %25

46:                                               ; preds = %44
  %47 = load ptr, ptr %0, align 8, !tbaa !19
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %9, align 8, !tbaa !13
  invoke void @opng_store_image(ptr noundef %47, ptr noundef %48, ptr noundef %49)
          to label %50 unwind label %25

50:                                               ; preds = %46
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  invoke void @png_set_write_fn(ptr noundef %51, ptr noundef nonnull %0, ptr noundef nonnull @_ZL15opng_write_dataP14png_struct_defPhm, ptr noundef null)
          to label %52 unwind label %25

52:                                               ; preds = %50
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !13
  invoke void @png_write_png(ptr noundef %53, ptr noundef %54, i32 noundef 0, ptr noundef null)
          to label %57 unwind label %25

55:                                               ; preds = %30
  %56 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_end_catch() #6
  br label %63

57:                                               ; preds = %52
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !13
  tail call void @png_data_freer(ptr noundef %58, ptr noundef %59, i32 noundef 2, i32 noundef 65535)
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !13
  tail call void @png_data_freer(ptr noundef %60, ptr noundef %61, i32 noundef 1, i32 noundef 12800)
  tail call void @png_destroy_write_struct(ptr noundef nonnull %7, ptr noundef nonnull %9)
  br label %62

62:                                               ; preds = %57, %33
  %.0 = phi i32 [ 0, %57 ], [ -1, %33 ]
  ret i32 %.0

63:                                               ; preds = %55, %25
  %.merged = phi { ptr, i32 } [ %56, %55 ], [ %26, %25 ]
  resume { ptr, i32 } %.merged
}

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) #4

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

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

declare void @png_set_filter(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @png_set_compression_level(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @png_set_compression_mem_level(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @png_set_compression_window_bits(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @png_set_compression_strategy(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @opng_store_image(ptr noundef, 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) #4

declare void @png_write_png(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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 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 #3 = { nofree nosync nounwind memory(none) }
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 = { noreturn nounwind }
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, !7, i64 32}
!6 = !{!"_ZTS18opng_codec_context", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !12, i64 84}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !7, i64 40}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !7, i64 24}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTS19opng_encoding_stats", !10, i64 0, !10, i64 8, !11, i64 16, !12, i64 20}
!19 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass