; LLVM IR from aagdev/mlimgsynth :: src/ccommon (image_io_png)

; 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.png_text_struct = type { i32, ptr, ptr, i64, i64, ptr, ptr }
%struct.ImageIO = type { ptr, ptr, ptr, ptr, i32, i32 }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }
%struct.Image = type { ptr, i32, i32, i32, i32, i32, i32 }
%struct.CodecPng = type { ptr, i32 }
%struct.CodecPngText = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@g_allocator = external global ptr, align 8

; 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

declare noalias ptr @png_create_info_struct(ptr noundef) #1

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) #2

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

; Function Attrs: noreturn nounwind
declare void @longjmp(ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @dynbuf_count(ptr noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @imgio_png_save_op(ptr noundef %0, ptr noundef %1, ptr noundef %2) #6 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %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 i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %struct.png_text_struct, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  store ptr null, ptr %11, align 8, !tbaa !5
  %19 = call noalias ptr @png_create_write_struct(ptr noundef @.str.1, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %19, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %26, label %22

22:                                               ; preds = %3
  br label %23

23:                                               ; preds = %22
  store i32 -771, ptr %7, align 4, !tbaa !9
  br label %187

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25, %3
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = call noalias ptr @png_create_info_struct(ptr noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %35, label %31

31:                                               ; preds = %26
  br label %32

32:                                               ; preds = %31
  store i32 -771, ptr %7, align 4, !tbaa !9
  br label %187

33:                                               ; No predecessors!
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34, %26
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ImageIO, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  call void @png_set_write_fn(ptr noundef %36, ptr noundef %39, ptr noundef @png_write_data, ptr noundef @png_flush_data)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call ptr @png_set_longjmp_fn(ptr noundef %40, ptr noundef @longjmp, i64 noundef 200)
  %42 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %41, i64 0, i64 0
  %43 = call i32 @_setjmp(ptr noundef %42) #9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %35
  br label %46

46:                                               ; preds = %45
  store i32 -780, ptr %7, align 4, !tbaa !9
  br label %187

47:                                               ; No predecessors!
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48, %35
  store i32 8, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !9
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Image, ptr %50, i32 0, i32 5
  %52 = load i32, ptr %51, align 8, !tbaa !13
  switch i32 %52, label %56 [
    i32 1, label %53
    i32 258, label %54
    i32 771, label %55
  ]

53:                                               ; preds = %49
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %60

54:                                               ; preds = %49
  store i32 2, ptr %13, align 4, !tbaa !9
  br label %60

55:                                               ; preds = %49
  store i32 6, ptr %13, align 4, !tbaa !9
  br label %60

56:                                               ; preds = %49
  br label %57

57:                                               ; preds = %56
  store i32 -776, ptr %7, align 4, !tbaa !9
  br label %187

58:                                               ; No predecessors!
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59, %55, %54, %53
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Image, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !15
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Image, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 4, !tbaa !16
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !9
  call void @png_set_IHDR(ptr noundef %61, ptr noundef %62, i32 noundef %65, i32 noundef %68, i32 noundef %69, i32 noundef %70, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.CodecPng, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 8, !tbaa !17
  %74 = icmp sgt i32 %73, 0
  br i1 %74, label %75, label %80

75:                                               ; preds = %60
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.CodecPng, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !17
  call void @png_set_compression_level(ptr noundef %76, i32 noundef %79)
  br label %80

80:                                               ; preds = %75, %60
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.CodecPng, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !19
  %84 = call i32 @dynbuf_count(ptr noundef %83)
  store i32 %84, ptr %14, align 4, !tbaa !9
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %148

87:                                               ; preds = %80
  %88 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %89 = load i32, ptr %14, align 4, !tbaa !9
  %90 = zext i32 %89 to i64
  %91 = mul i64 56, %90
  %92 = call noalias ptr @alloc_alloc(ptr noundef %88, i64 noundef %91) #10
  store ptr %92, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #8
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.CodecPng, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !19
  %96 = call i32 @dynbuf_count(ptr noundef %95)
  store i32 %96, ptr %16, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %140, %87
  %98 = load i32, ptr %15, align 4, !tbaa !9
  %99 = load i32, ptr %16, align 4, !tbaa !9
  %100 = icmp ult i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #8
  br label %143

102:                                              ; preds = %97
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = load i32, ptr %15, align 4, !tbaa !9
  %105 = zext i32 %104 to i64
  %106 = getelementptr inbounds %struct.png_text_struct, ptr %103, i64 %105
  %107 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 0
  store i32 -1, ptr %107, align 8, !tbaa !20
  %108 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 1
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.CodecPng, ptr %109, i32 0, i32 0
  %111 = load ptr, ptr %110, align 8, !tbaa !19
  %112 = load i32, ptr %15, align 4, !tbaa !9
  %113 = zext i32 %112 to i64
  %114 = getelementptr inbounds %struct.CodecPngText, ptr %111, i64 %113
  %115 = getelementptr inbounds %struct.CodecPngText, ptr %114, i32 0, i32 0
  %116 = load ptr, ptr %115, align 8, !tbaa !23
  store ptr %116, ptr %108, align 8, !tbaa !25
  %117 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 2
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.CodecPng, ptr %118, i32 0, i32 0
  %120 = load ptr, ptr %119, align 8, !tbaa !19
  %121 = load i32, ptr %15, align 4, !tbaa !9
  %122 = zext i32 %121 to i64
  %123 = getelementptr inbounds %struct.CodecPngText, ptr %120, i64 %122
  %124 = getelementptr inbounds %struct.CodecPngText, ptr %123, i32 0, i32 1
  %125 = load ptr, ptr %124, align 8, !tbaa !26
  store ptr %125, ptr %117, align 8, !tbaa !27
  %126 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 3
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.CodecPng, ptr %127, i32 0, i32 0
  %129 = load ptr, ptr %128, align 8, !tbaa !19
  %130 = load i32, ptr %15, align 4, !tbaa !9
  %131 = zext i32 %130 to i64
  %132 = getelementptr inbounds %struct.CodecPngText, ptr %129, i64 %131
  %133 = getelementptr inbounds %struct.CodecPngText, ptr %132, i32 0, i32 1
  %134 = load ptr, ptr %133, align 8, !tbaa !26
  %135 = call i32 @dynbuf_count(ptr noundef %134)
  %136 = zext i32 %135 to i64
  store i64 %136, ptr %126, align 8, !tbaa !28
  %137 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 4
  store i64 0, ptr %137, align 8, !tbaa !29
  %138 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 5
  store ptr null, ptr %138, align 8, !tbaa !30
  %139 = getelementptr inbounds %struct.png_text_struct, ptr %17, i32 0, i32 6
  store ptr null, ptr %139, align 8, !tbaa !31
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %106, ptr align 8 %17, i64 56, i1 false), !tbaa.struct !32
  br label %140

140:                                              ; preds = %102
  %141 = load i32, ptr %15, align 4, !tbaa !9
  %142 = add i32 %141, 1
  store i32 %142, ptr %15, align 4, !tbaa !9
  br label %97, !llvm.loop !34

143:                                              ; preds = %101
  %144 = load ptr, ptr %8, align 8, !tbaa !5
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  %146 = load ptr, ptr %10, align 8, !tbaa !5
  %147 = load i32, ptr %14, align 4, !tbaa !9
  call void @png_set_text(ptr noundef %144, ptr noundef %145, ptr noundef %146, i32 noundef %147)
  br label %148

148:                                              ; preds = %143, %80
  %149 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %150 = load ptr, ptr %6, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct.Image, ptr %150, i32 0, i32 2
  %152 = load i32, ptr %151, align 4, !tbaa !16
  %153 = zext i32 %152 to i64
  %154 = mul i64 8, %153
  %155 = call noalias ptr @alloc_alloc(ptr noundef %149, i64 noundef %154) #10
  store ptr %155, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #8
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %156

156:                                              ; preds = %178, %148
  %157 = load i32, ptr %18, align 4, !tbaa !9
  %158 = load ptr, ptr %6, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.Image, ptr %158, i32 0, i32 2
  %160 = load i32, ptr %159, align 4, !tbaa !16
  %161 = icmp ult i32 %157, %160
  br i1 %161, label %163, label %162

162:                                              ; preds = %156
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  br label %181

163:                                              ; preds = %156
  %164 = load ptr, ptr %6, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.Image, ptr %164, i32 0, i32 0
  %166 = load ptr, ptr %165, align 8, !tbaa !36
  %167 = load ptr, ptr %6, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.Image, ptr %167, i32 0, i32 3
  %169 = load i32, ptr %168, align 8, !tbaa !37
  %170 = load i32, ptr %18, align 4, !tbaa !9
  %171 = mul i32 %169, %170
  %172 = zext i32 %171 to i64
  %173 = getelementptr inbounds i8, ptr %166, i64 %172
  %174 = load ptr, ptr %11, align 8, !tbaa !5
  %175 = load i32, ptr %18, align 4, !tbaa !9
  %176 = zext i32 %175 to i64
  %177 = getelementptr inbounds ptr, ptr %174, i64 %176
  store ptr %173, ptr %177, align 8, !tbaa !5
  br label %178

178:                                              ; preds = %163
  %179 = load i32, ptr %18, align 4, !tbaa !9
  %180 = add i32 %179, 1
  store i32 %180, ptr %18, align 4, !tbaa !9
  br label %156, !llvm.loop !38

181:                                              ; preds = %162
  %182 = load ptr, ptr %8, align 8, !tbaa !5
  %183 = load ptr, ptr %9, align 8, !tbaa !5
  %184 = load ptr, ptr %11, align 8, !tbaa !5
  call void @png_set_rows(ptr noundef %182, ptr noundef %183, ptr noundef %184)
  %185 = load ptr, ptr %8, align 8, !tbaa !5
  %186 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_write_png(ptr noundef %185, ptr noundef %186, i32 noundef 0, ptr noundef null)
  br label %187

187:                                              ; preds = %181, %57, %46, %32, %23
  %188 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %189 = load ptr, ptr %11, align 8, !tbaa !5
  call void @alloc_free(ptr noundef %188, ptr noundef %189)
  %190 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %191 = load ptr, ptr %10, align 8, !tbaa !5
  call void @alloc_free(ptr noundef %190, ptr noundef %191)
  %192 = load ptr, ptr %8, align 8, !tbaa !5
  %193 = icmp ne ptr %192, null
  br i1 %193, label %194, label %201

194:                                              ; preds = %187
  %195 = load ptr, ptr %9, align 8, !tbaa !5
  %196 = icmp ne ptr %195, null
  br i1 %196, label %197, label %198

197:                                              ; preds = %194
  br label %199

198:                                              ; preds = %194
  br label %199

199:                                              ; preds = %198, %197
  %200 = phi ptr [ %9, %197 ], [ null, %198 ]
  call void @png_destroy_write_struct(ptr noundef %8, ptr noundef %200)
  br label %201

201:                                              ; preds = %199, %187
  %202 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  ret i32 %202
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @png_flush_data(ptr noundef) #6

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

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

; Function Attrs: inlinehint nounwind allocsize(1) uwtable
declare hidden noalias ptr @alloc_alloc(ptr noundef, i64 noundef) #7

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @alloc_free(ptr noundef, ptr noundef) #5

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

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 returns_twice "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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { inlinehint 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 = { 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 #7 = { inlinehint nounwind allocsize(1) 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 #8 = { nounwind }
attributes #9 = { nounwind returns_twice }
attributes #10 = { allocsize(1) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"ImageIO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!14, !10, i64 24}
!14 = !{!"Image", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !10, i64 12}
!17 = !{!18, !10, i64 8}
!18 = !{!"CodecPng", !6, i64 0, !10, i64 8}
!19 = !{!18, !6, i64 0}
!20 = !{!21, !10, i64 0}
!21 = !{!"png_text_struct", !10, i64 0, !6, i64 8, !6, i64 16, !22, i64 24, !22, i64 32, !6, i64 40, !6, i64 48}
!22 = !{!"long", !7, i64 0}
!23 = !{!24, !6, i64 0}
!24 = !{!"CodecPngText", !6, i64 0, !6, i64 8}
!25 = !{!21, !6, i64 8}
!26 = !{!24, !6, i64 8}
!27 = !{!21, !6, i64 16}
!28 = !{!21, !22, i64 24}
!29 = !{!21, !22, i64 32}
!30 = !{!21, !6, i64 40}
!31 = !{!21, !6, i64 48}
!32 = !{i64 0, i64 4, !9, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !33, i64 32, i64 8, !33, i64 40, i64 8, !5, i64 48, i64 8, !5}
!33 = !{!22, !22, i64 0}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = !{!14, !6, i64 0}
!37 = !{!14, !10, i64 16}
!38 = distinct !{!38, !35}


; 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.png_text_struct = type { i32, ptr, ptr, i64, i64, ptr, ptr }
%struct.CodecPngText = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@g_allocator = external local_unnamed_addr global ptr, align 8

; 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

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

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #2

declare ptr @png_set_longjmp_fn(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @longjmp(ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @dynbuf_count(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -780, 1) i32 @imgio_png_save_op(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #5 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #8
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = call noalias ptr @png_create_write_struct(ptr noundef nonnull @.str.1, ptr noundef null, ptr noundef null, ptr noundef null) #8
  store ptr %6, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %83, label %7

7:                                                ; preds = %3
  %8 = call noalias ptr @png_create_info_struct(ptr noundef nonnull %6) #8
  store ptr %8, ptr %5, align 8, !tbaa !5
  %.not46 = icmp eq ptr %8, null
  br i1 %.not46, label %83, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  call void @png_set_write_fn(ptr noundef nonnull %6, ptr noundef %11, ptr noundef nonnull @png_write_data, ptr noundef nonnull @png_flush_data) #8
  %12 = call ptr @png_set_longjmp_fn(ptr noundef nonnull %6, ptr noundef nonnull @longjmp, i64 noundef 200) #8
  %13 = call i32 @_setjmp(ptr noundef %12) #9
  %.not47 = icmp eq i32 %13, 0
  br i1 %.not47, label %14, label %83

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !12
  switch i32 %16, label %83 [
    i32 1, label %19
    i32 258, label %17
    i32 771, label %18
  ]

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %14, %18, %17
  %.041 = phi i32 [ 6, %18 ], [ 2, %17 ], [ 0, %14 ]
  %20 = getelementptr inbounds i8, ptr %2, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %2, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !15
  call void @png_set_IHDR(ptr noundef nonnull %6, ptr noundef nonnull %8, i32 noundef %21, i32 noundef %23, i32 noundef 8, i32 noundef %.041, i32 noundef 0, i32 noundef 0, i32 noundef 0) #8
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !16
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  call void @png_set_compression_level(ptr noundef nonnull %6, i32 noundef %25) #8
  br label %28

28:                                               ; preds = %27, %19
  %29 = load ptr, ptr %0, align 8, !tbaa !18
  %30 = call i32 @dynbuf_count(ptr noundef %29)
  %.not48 = icmp eq i32 %30, 0
  br i1 %.not48, label %46, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %33 = zext i32 %30 to i64
  %34 = mul nuw nsw i64 %33, 56
  %35 = call noalias ptr @alloc_alloc(ptr noundef %32, i64 noundef %34) #10
  %36 = load ptr, ptr %0, align 8, !tbaa !18
  %37 = call i32 @dynbuf_count(ptr noundef %36)
  %.not56 = icmp eq i32 %37, 0
  br i1 %.not56, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %31
  %wide.trip.count = zext i32 %37 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %31
  call void @png_set_text(ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef %35, i32 noundef %30) #8
  br label %46

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %38 = getelementptr inbounds %struct.png_text_struct, ptr %35, i64 %indvars.iv
  %39 = load ptr, ptr %0, align 8, !tbaa !18
  %40 = getelementptr inbounds %struct.CodecPngText, ptr %39, i64 %indvars.iv
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = getelementptr inbounds i8, ptr %40, i64 8
  %43 = load ptr, ptr %42, align 8, !tbaa !21
  %44 = call i32 @dynbuf_count(ptr noundef %43)
  %45 = zext i32 %44 to i64
  store i32 -1, ptr %38, align 8, !tbaa !22
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %38, i64 8
  store ptr %41, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !5
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %38, i64 16
  store ptr %43, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %38, i64 24
  store i64 %45, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !23
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %38, i64 32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %.sroa.5.0..sroa_idx, i8 0, i64 24, i1 false)
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !25

46:                                               ; preds = %._crit_edge, %28
  %.039 = phi ptr [ %35, %._crit_edge ], [ null, %28 ]
  %47 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  %48 = load i32, ptr %22, align 4, !tbaa !15
  %49 = zext i32 %48 to i64
  %50 = shl nuw nsw i64 %49, 3
  %51 = call noalias ptr @alloc_alloc(ptr noundef %47, i64 noundef %50) #10
  %52 = load i32, ptr %22, align 4, !tbaa !15
  %.not57 = icmp eq i32 %52, 0
  br i1 %.not57, label %._crit_edge55, label %.lr.ph54

.lr.ph54:                                         ; preds = %46
  %53 = load ptr, ptr %2, align 8, !tbaa !27
  %54 = getelementptr inbounds i8, ptr %2, i64 16
  %55 = load i32, ptr %54, align 8, !tbaa !28
  %wide.trip.count62 = zext i32 %52 to i64
  %xtraiter = and i64 %wide.trip.count62, 3
  %56 = icmp ult i32 %52, 4
  br i1 %56, label %._crit_edge55.loopexit.unr-lcssa, label %.lr.ph54.new

.lr.ph54.new:                                     ; preds = %.lr.ph54
  %unroll_iter = and i64 %wide.trip.count62, 4294967292
  br label %62

._crit_edge55.loopexit.unr-lcssa:                 ; preds = %62, %.lr.ph54
  %indvars.iv59.unr = phi i64 [ 0, %.lr.ph54 ], [ %indvars.iv.next60.3, %62 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge55, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge55.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv59.epil = phi i64 [ %indvars.iv.next60.epil, %.epil.preheader ], [ %indvars.iv59.unr, %._crit_edge55.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge55.loopexit.unr-lcssa ]
  %57 = trunc nuw i64 %indvars.iv59.epil to i32
  %58 = mul i32 %55, %57
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %53, i64 %59
  %61 = getelementptr inbounds ptr, ptr %51, i64 %indvars.iv59.epil
  store ptr %60, ptr %61, align 8, !tbaa !5
  %indvars.iv.next60.epil = add nuw nsw i64 %indvars.iv59.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge55, label %.epil.preheader, !llvm.loop !29

._crit_edge55:                                    ; preds = %._crit_edge55.loopexit.unr-lcssa, %.epil.preheader, %46
  call void @png_set_rows(ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef %51) #8
  call void @png_write_png(ptr noundef nonnull %6, ptr noundef nonnull %8, i32 noundef 0, ptr noundef null) #8
  br label %83

62:                                               ; preds = %62, %.lr.ph54.new
  %indvars.iv59 = phi i64 [ 0, %.lr.ph54.new ], [ %indvars.iv.next60.3, %62 ]
  %niter = phi i64 [ 0, %.lr.ph54.new ], [ %niter.next.3, %62 ]
  %63 = trunc nuw i64 %indvars.iv59 to i32
  %64 = mul i32 %55, %63
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %53, i64 %65
  %67 = getelementptr inbounds ptr, ptr %51, i64 %indvars.iv59
  store ptr %66, ptr %67, align 8, !tbaa !5
  %indvars.iv.next60 = or disjoint i64 %indvars.iv59, 1
  %68 = trunc nuw i64 %indvars.iv.next60 to i32
  %69 = mul i32 %55, %68
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %53, i64 %70
  %72 = getelementptr inbounds ptr, ptr %51, i64 %indvars.iv.next60
  store ptr %71, ptr %72, align 8, !tbaa !5
  %indvars.iv.next60.1 = or disjoint i64 %indvars.iv59, 2
  %73 = trunc nuw i64 %indvars.iv.next60.1 to i32
  %74 = mul i32 %55, %73
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %53, i64 %75
  %77 = getelementptr inbounds ptr, ptr %51, i64 %indvars.iv.next60.1
  store ptr %76, ptr %77, align 8, !tbaa !5
  %indvars.iv.next60.2 = or disjoint i64 %indvars.iv59, 3
  %78 = trunc nuw i64 %indvars.iv.next60.2 to i32
  %79 = mul i32 %55, %78
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %53, i64 %80
  %82 = getelementptr inbounds ptr, ptr %51, i64 %indvars.iv.next60.2
  store ptr %81, ptr %82, align 8, !tbaa !5
  %indvars.iv.next60.3 = add nuw nsw i64 %indvars.iv59, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge55.loopexit.unr-lcssa, label %62, !llvm.loop !31

83:                                               ; preds = %14, %9, %7, %3, %._crit_edge55
  %.040 = phi ptr [ %51, %._crit_edge55 ], [ null, %3 ], [ null, %7 ], [ null, %9 ], [ null, %14 ]
  %.1 = phi ptr [ %.039, %._crit_edge55 ], [ null, %3 ], [ null, %7 ], [ null, %9 ], [ null, %14 ]
  %.038 = phi i32 [ 0, %._crit_edge55 ], [ -771, %3 ], [ -771, %7 ], [ -780, %9 ], [ -776, %14 ]
  %84 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  call void @alloc_free(ptr noundef %84, ptr noundef %.040)
  %85 = load ptr, ptr @g_allocator, align 8, !tbaa !5
  call void @alloc_free(ptr noundef %85, ptr noundef %.1)
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %.not49 = icmp eq ptr %86, null
  br i1 %.not49, label %89, label %87

87:                                               ; preds = %83
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %.not50 = icmp eq ptr %88, null
  %. = select i1 %.not50, ptr null, ptr %5
  call void @png_destroy_write_struct(ptr noundef nonnull %4, ptr noundef %.) #8
  br label %89

89:                                               ; preds = %87, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  ret i32 %.038
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @png_flush_data(ptr noundef) #5

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

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

; Function Attrs: inlinehint nounwind allocsize(1) uwtable
declare hidden noalias ptr @alloc_alloc(ptr noundef, i64 noundef) local_unnamed_addr #6

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

declare void @png_set_rows(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @alloc_free(ptr noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nounwind returns_twice "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 = { 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 #4 = { inlinehint 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 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 nounwind allocsize(1) 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 nounwind willreturn memory(argmem: write) }
attributes #8 = { nounwind }
attributes #9 = { nounwind returns_twice }
attributes #10 = { allocsize(1) }

!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/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"ImageIO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 24}
!13 = !{!"Image", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !11, i64 12}
!16 = !{!17, !11, i64 8}
!17 = !{!"CodecPng", !6, i64 0, !11, i64 8}
!18 = !{!17, !6, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"CodecPngText", !6, i64 0, !6, i64 8}
!21 = !{!20, !6, i64 8}
!22 = !{!11, !11, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"long", !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!13, !6, i64 0}
!28 = !{!13, !11, i64 16}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.unroll.disable"}
!31 = distinct !{!31, !26}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass