; LLVM IR from ewconnell/Netlib :: Sources/ImageCodecs (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.CByteArray = type { ptr, i64 }
%struct.BufferItem = type { ptr, i64, i64, ptr, ptr, ptr }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.pngEncode = external hidden unnamed_addr constant [93 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @accumulateAndFree(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @writeFn(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @pngEncode(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, i64 noundef %5) #2 {
  %7 = alloca %struct.CByteArray, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca %struct.BufferItem, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  %21 = alloca double, align 8
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i64, align 8
  %25 = alloca ptr, align 8
  %26 = alloca ptr, align 8
  %27 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !11
  store i64 %5, ptr %13, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.CByteArray, ptr %7, i32 0, i32 1
  store i64 0, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.CByteArray, ptr %7, i32 0, i32 0
  store ptr null, ptr %29, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 48, ptr %14) #8
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 48, i1 false)
  %30 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 4
  store ptr %14, ptr %30, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #8
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds i64, ptr %31, i64 0
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %35, i64 1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %39, i64 2
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #8
  %43 = call noalias ptr @png_create_write_struct(ptr noundef @.str.2, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %43, ptr %18, align 8, !tbaa !5
  %44 = load ptr, ptr %18, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %6
  store i32 1, ptr %19, align 4
  br label %153

47:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #8
  %48 = load ptr, ptr %18, align 8, !tbaa !5
  %49 = call noalias ptr @png_create_info_struct(ptr noundef %48)
  store ptr %49, ptr %20, align 8, !tbaa !5
  %50 = load ptr, ptr %20, align 8, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  call void @png_destroy_write_struct(ptr noundef %18, ptr noundef null)
  store i32 1, ptr %19, align 4
  br label %152

53:                                               ; preds = %47
  %54 = load ptr, ptr %18, align 8, !tbaa !5
  %55 = call ptr @png_set_longjmp_fn(ptr noundef %54, ptr noundef @longjmp, i64 noundef 200)
  %56 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %55, i64 0, i64 0
  %57 = call i32 @_setjmp(ptr noundef %56) #9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  call void @png_destroy_write_struct(ptr noundef %18, ptr noundef %20)
  store i32 1, ptr %19, align 4
  br label %152

60:                                               ; preds = %53
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  call void @png_set_write_fn(ptr noundef %61, ptr noundef %14, ptr noundef @writeFn, ptr noundef null)
  %62 = load i64, ptr %13, align 8, !tbaa !9
  %63 = icmp eq i64 %62, -1
  br i1 %63, label %64, label %65

64:                                               ; preds = %60
  store i64 -1, ptr %13, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %64, %60
  %66 = load ptr, ptr %18, align 8, !tbaa !5
  %67 = load i64, ptr %13, align 8, !tbaa !9
  %68 = trunc i64 %67 to i32
  call void @png_set_compression_level(ptr noundef %66, i32 noundef %68)
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #8
  store double 5.000000e-01, ptr %21, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #8
  store i32 0, ptr %22, align 4, !tbaa !11
  %69 = load i32, ptr %17, align 4, !tbaa !11
  switch i32 %69, label %75 [
    i32 1, label %70
    i32 2, label %71
    i32 3, label %72
    i32 4, label %73
    i32 0, label %74
  ]

70:                                               ; preds = %65
  store i32 0, ptr %22, align 4, !tbaa !11
  br label %76

71:                                               ; preds = %65
  store i32 4, ptr %22, align 4, !tbaa !11
  br label %76

72:                                               ; preds = %65
  store i32 2, ptr %22, align 4, !tbaa !11
  br label %76

73:                                               ; preds = %65
  store i32 6, ptr %22, align 4, !tbaa !11
  br label %76

74:                                               ; preds = %65
  br label %75

75:                                               ; preds = %74, %65
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 190, ptr noundef @__PRETTY_FUNCTION__.pngEncode) #10
  unreachable

76:                                               ; preds = %73, %72, %71, %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #8
  %77 = load i32, ptr %12, align 4, !tbaa !11
  %78 = icmp eq i32 %77, 0
  %79 = zext i1 %78 to i64
  %80 = select i1 %78, i32 8, i32 16
  store i32 %80, ptr %23, align 4, !tbaa !11
  %81 = load ptr, ptr %18, align 8, !tbaa !5
  %82 = load ptr, ptr %20, align 8, !tbaa !5
  %83 = load i32, ptr %16, align 4, !tbaa !11
  %84 = load i32, ptr %15, align 4, !tbaa !11
  %85 = load i32, ptr %23, align 4, !tbaa !11
  %86 = load i32, ptr %22, align 4, !tbaa !11
  call void @png_set_IHDR(ptr noundef %81, ptr noundef %82, i32 noundef %83, i32 noundef %84, i32 noundef %85, i32 noundef %86, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #8
  %87 = load ptr, ptr %18, align 8, !tbaa !5
  %88 = load ptr, ptr %20, align 8, !tbaa !5
  %89 = call i64 @png_get_rowbytes(ptr noundef %87, ptr noundef %88)
  store i64 %89, ptr %24, align 8, !tbaa !9
  %90 = load i64, ptr %24, align 8, !tbaa !9
  %91 = load i32, ptr %15, align 4, !tbaa !11
  %92 = zext i32 %91 to i64
  %93 = mul i64 %90, %92
  %94 = uitofp i64 %93 to double
  %95 = load double, ptr %21, align 8, !tbaa !18
  %96 = fmul double %94, %95
  %97 = fptoui double %96 to i64
  %98 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 1
  store i64 %97, ptr %98, align 8, !tbaa !20
  %99 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 1
  %100 = load i64, ptr %99, align 8, !tbaa !20
  %101 = icmp ult i64 %100, 1024
  br i1 %101, label %102, label %104

102:                                              ; preds = %76
  %103 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 1
  store i64 1024, ptr %103, align 8, !tbaa !20
  br label %104

104:                                              ; preds = %102, %76
  %105 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 1
  %106 = load i64, ptr %105, align 8, !tbaa !20
  %107 = call noalias ptr @malloc(i64 noundef %106) #11
  %108 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 0
  store ptr %107, ptr %108, align 8, !tbaa !21
  %109 = load ptr, ptr %18, align 8, !tbaa !5
  %110 = load ptr, ptr %20, align 8, !tbaa !5
  call void @png_write_info(ptr noundef %109, ptr noundef %110)
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #8
  %111 = load i32, ptr %15, align 4, !tbaa !11
  %112 = zext i32 %111 to i64
  %113 = mul i64 8, %112
  %114 = call noalias ptr @malloc(i64 noundef %113) #11
  store ptr %114, ptr %25, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #8
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %115, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #8
  store i32 0, ptr %27, align 4, !tbaa !11
  br label %116

116:                                              ; preds = %127, %104
  %117 = load i32, ptr %27, align 4, !tbaa !11
  %118 = load i32, ptr %15, align 4, !tbaa !11
  %119 = icmp ult i32 %117, %118
  br i1 %119, label %121, label %120

120:                                              ; preds = %116
  store i32 3, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #8
  br label %133

121:                                              ; preds = %116
  %122 = load ptr, ptr %26, align 8, !tbaa !5
  %123 = load ptr, ptr %25, align 8, !tbaa !5
  %124 = load i32, ptr %27, align 4, !tbaa !11
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds ptr, ptr %123, i64 %125
  store ptr %122, ptr %126, align 8, !tbaa !5
  br label %127

127:                                              ; preds = %121
  %128 = load i32, ptr %27, align 4, !tbaa !11
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %27, align 4, !tbaa !11
  %130 = load i64, ptr %24, align 8, !tbaa !9
  %131 = load ptr, ptr %26, align 8, !tbaa !5
  %132 = getelementptr inbounds i8, ptr %131, i64 %130
  store ptr %132, ptr %26, align 8, !tbaa !5
  br label %116, !llvm.loop !22

133:                                              ; preds = %120
  %134 = load ptr, ptr %18, align 8, !tbaa !5
  %135 = load ptr, ptr %25, align 8, !tbaa !5
  call void @png_write_image(ptr noundef %134, ptr noundef %135)
  %136 = load ptr, ptr %18, align 8, !tbaa !5
  %137 = load ptr, ptr %20, align 8, !tbaa !5
  call void @png_write_end(ptr noundef %136, ptr noundef %137)
  %138 = load ptr, ptr %25, align 8, !tbaa !5
  call void @free(ptr noundef %138) #8
  call void @png_destroy_write_struct(ptr noundef %18, ptr noundef %20)
  %139 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 3
  %140 = load ptr, ptr %139, align 8, !tbaa !24
  %141 = icmp eq ptr %140, null
  br i1 %141, label %142, label %149

142:                                              ; preds = %133
  %143 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 0
  %144 = load ptr, ptr %143, align 8, !tbaa !21
  %145 = getelementptr inbounds %struct.CByteArray, ptr %7, i32 0, i32 0
  store ptr %144, ptr %145, align 8, !tbaa !15
  %146 = getelementptr inbounds %struct.BufferItem, ptr %14, i32 0, i32 2
  %147 = load i64, ptr %146, align 8, !tbaa !25
  %148 = getelementptr inbounds %struct.CByteArray, ptr %7, i32 0, i32 1
  store i64 %147, ptr %148, align 8, !tbaa !13
  br label %151

149:                                              ; preds = %133
  %150 = call ptr @accumulateAndFree(ptr noundef %14, ptr noundef %7)
  br label %151

151:                                              ; preds = %149, %142
  store i32 1, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #8
  br label %152

152:                                              ; preds = %151, %59, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #8
  br label %153

153:                                              ; preds = %152, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr %14) #8
  %154 = load { ptr, i64 }, ptr %7, align 8
  ret { ptr, i64 } %154
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

declare noalias ptr @png_create_info_struct(ptr noundef) #6

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

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

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

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

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

declare void @png_set_compression_level(ptr noundef, i32 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) #6

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) #6

declare void @png_write_info(ptr noundef, ptr noundef) #6

declare void @png_write_image(ptr noundef, ptr noundef) #6

declare void @png_write_end(ptr noundef, ptr noundef) #6

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { "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 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 #8 = { nounwind }
attributes #9 = { nounwind returns_twice }
attributes #10 = { noreturn nounwind }
attributes #11 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"", !6, i64 0, !10, i64 8}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !6, i64 32}
!17 = !{!"BufferItem", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = !{!17, !10, i64 8}
!21 = !{!17, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!17, !6, i64 24}
!25 = !{!17, !10, i64 16}


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

@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.pngEncode = external hidden unnamed_addr constant [93 x i8], align 1
@switch.table.pngEncode = private unnamed_addr constant [4 x i32] [i32 0, i32 4, i32 2, i32 6], align 4

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @accumulateAndFree(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local void @writeFn(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local { ptr, i64 } @pngEncode(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, i32 noundef %4, i64 noundef %5) local_unnamed_addr #2 {
  %7 = alloca %struct.CByteArray, align 8
  %8 = alloca %struct.BufferItem, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = getelementptr inbounds i8, ptr %7, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %8) #9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %8, i8 0, i64 48, i1 false)
  %12 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %8, ptr %12, align 8, !tbaa !5
  %13 = load i64, ptr %2, align 8, !tbaa !11
  %14 = trunc i64 %13 to i32
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = trunc i64 %16 to i32
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = trunc i64 %19 to i32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #9
  %21 = call noalias ptr @png_create_write_struct(ptr noundef nonnull @.str.2, ptr noundef null, ptr noundef null, ptr noundef null) #9
  store ptr %21, ptr %9, align 8, !tbaa !12
  %22 = icmp eq ptr %21, null
  br i1 %22, label %89, label %23

23:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #9
  %24 = call noalias ptr @png_create_info_struct(ptr noundef nonnull %21) #9
  store ptr %24, ptr %10, align 8, !tbaa !12
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  call void @png_destroy_write_struct(ptr noundef nonnull %9, ptr noundef null) #9
  br label %88

27:                                               ; preds = %23
  %28 = call ptr @png_set_longjmp_fn(ptr noundef nonnull %21, ptr noundef nonnull @longjmp, i64 noundef 200) #9
  %29 = call i32 @_setjmp(ptr noundef %28) #10
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %31, label %30

30:                                               ; preds = %27
  call void @png_destroy_write_struct(ptr noundef nonnull %9, ptr noundef nonnull %10) #9
  br label %88

31:                                               ; preds = %27
  %32 = load ptr, ptr %9, align 8, !tbaa !12
  call void @png_set_write_fn(ptr noundef %32, ptr noundef nonnull %8, ptr noundef nonnull @writeFn, ptr noundef null) #9
  %33 = load ptr, ptr %9, align 8, !tbaa !12
  %34 = trunc i64 %5 to i32
  call void @png_set_compression_level(ptr noundef %33, i32 noundef %34) #9
  %switch.tableidx = add i32 %20, -1
  %35 = icmp ult i32 %switch.tableidx, 4
  br i1 %35, label %switch.lookup, label %36

36:                                               ; preds = %31
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 190, ptr noundef nonnull @__PRETTY_FUNCTION__.pngEncode) #11
  unreachable

switch.lookup:                                    ; preds = %31
  %37 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [4 x i32], ptr @switch.table.pngEncode, i64 0, i64 %37
  %switch.load = load i32, ptr %switch.gep, align 4
  %38 = icmp eq i32 %4, 0
  %39 = select i1 %38, i32 8, i32 16
  %40 = load ptr, ptr %9, align 8, !tbaa !12
  %41 = load ptr, ptr %10, align 8, !tbaa !12
  call void @png_set_IHDR(ptr noundef %40, ptr noundef %41, i32 noundef %17, i32 noundef %14, i32 noundef %39, i32 noundef %switch.load, i32 noundef 0, i32 noundef 0, i32 noundef 0) #9
  %42 = load ptr, ptr %9, align 8, !tbaa !12
  %43 = load ptr, ptr %10, align 8, !tbaa !12
  %44 = call i64 @png_get_rowbytes(ptr noundef %42, ptr noundef %43) #9
  %45 = and i64 %13, 4294967295
  %46 = mul i64 %44, %45
  %47 = uitofp i64 %46 to double
  %48 = fmul double %47, 5.000000e-01
  %49 = fptoui double %48 to i64
  %50 = getelementptr inbounds i8, ptr %8, i64 8
  %spec.select = call i64 @llvm.umax.i64(i64 %49, i64 1024)
  store i64 %spec.select, ptr %50, align 8, !tbaa !13
  %51 = call noalias ptr @malloc(i64 noundef %spec.select) #12
  store ptr %51, ptr %8, align 8, !tbaa !14
  %52 = load ptr, ptr %9, align 8, !tbaa !12
  %53 = load ptr, ptr %10, align 8, !tbaa !12
  call void @png_write_info(ptr noundef %52, ptr noundef %53) #9
  %54 = shl nuw nsw i64 %45, 3
  %55 = call noalias ptr @malloc(i64 noundef %54) #12
  %.not29 = icmp eq i32 %14, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %switch.lookup
  %wide.trip.count = and i64 %13, 4294967295
  %56 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %13, 7
  %57 = icmp ult i64 %56, 7
  br i1 %57, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = sub nsw i64 %wide.trip.count, %xtraiter
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.7, %.lr.ph ]
  %.02527.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %81, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02527.epil = phi ptr [ %59, %.lr.ph.epil ], [ %.02527.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %58 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.epil
  store ptr %.02527.epil, ptr %58, align 8, !tbaa !12
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %59 = getelementptr inbounds i8, ptr %.02527.epil, i64 %44
  %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_edge, label %.lr.ph.epil, !llvm.loop !15

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %switch.lookup
  %60 = load ptr, ptr %9, align 8, !tbaa !12
  call void @png_write_image(ptr noundef %60, ptr noundef %55) #9
  %61 = load ptr, ptr %9, align 8, !tbaa !12
  %62 = load ptr, ptr %10, align 8, !tbaa !12
  call void @png_write_end(ptr noundef %61, ptr noundef %62) #9
  call void @free(ptr noundef %55) #9
  call void @png_destroy_write_struct(ptr noundef nonnull %9, ptr noundef nonnull %10) #9
  %63 = getelementptr inbounds i8, ptr %8, i64 24
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = icmp eq ptr %64, null
  br i1 %65, label %82, label %86

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.7, %.lr.ph ]
  %.02527 = phi ptr [ %0, %.lr.ph.preheader.new ], [ %81, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %66 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv
  store ptr %.02527, ptr %66, align 8, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %67 = getelementptr inbounds i8, ptr %.02527, i64 %44
  %68 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next
  store ptr %67, ptr %68, align 8, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %69 = getelementptr inbounds i8, ptr %67, i64 %44
  %70 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.1
  store ptr %69, ptr %70, align 8, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %71 = getelementptr inbounds i8, ptr %69, i64 %44
  %72 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.2
  store ptr %71, ptr %72, align 8, !tbaa !12
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %73 = getelementptr inbounds i8, ptr %71, i64 %44
  %74 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.3
  store ptr %73, ptr %74, align 8, !tbaa !12
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %75 = getelementptr inbounds i8, ptr %73, i64 %44
  %76 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.4
  store ptr %75, ptr %76, align 8, !tbaa !12
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %77 = getelementptr inbounds i8, ptr %75, i64 %44
  %78 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.5
  store ptr %77, ptr %78, align 8, !tbaa !12
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %79 = getelementptr inbounds i8, ptr %77, i64 %44
  %80 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv.next.6
  store ptr %79, ptr %80, align 8, !tbaa !12
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %81 = getelementptr inbounds i8, ptr %79, i64 %44
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !18

82:                                               ; preds = %._crit_edge
  %83 = load ptr, ptr %8, align 8, !tbaa !14
  %84 = getelementptr inbounds i8, ptr %8, i64 16
  %85 = load i64, ptr %84, align 8, !tbaa !20
  br label %88

86:                                               ; preds = %._crit_edge
  %87 = call ptr @accumulateAndFree(ptr noundef nonnull %8, ptr noundef nonnull %7)
  %.fca.0.load.pre.pre = load ptr, ptr %7, align 8
  %.fca.1.load.pre.pre = load i64, ptr %11, align 8
  br label %88

88:                                               ; preds = %82, %86, %30, %26
  %.fca.1.load.pre = phi i64 [ %85, %82 ], [ %.fca.1.load.pre.pre, %86 ], [ 0, %30 ], [ 0, %26 ]
  %.fca.0.load.pre = phi ptr [ %83, %82 ], [ %.fca.0.load.pre.pre, %86 ], [ null, %30 ], [ null, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #9
  br label %89

89:                                               ; preds = %6, %88
  %.fca.1.load = phi i64 [ 0, %6 ], [ %.fca.1.load.pre, %88 ]
  %.fca.0.load = phi ptr [ null, %6 ], [ %.fca.0.load.pre, %88 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #9
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %8) #9
  %.fca.0.insert = insertvalue { ptr, i64 } poison, ptr %.fca.0.load, 0
  %.fca.1.insert = insertvalue { ptr, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { ptr, i64 } %.fca.1.insert
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

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

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

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

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

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

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

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

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 #6

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) local_unnamed_addr #6

declare void @png_write_info(ptr noundef, ptr noundef) local_unnamed_addr #6

declare void @png_write_image(ptr noundef, ptr noundef) local_unnamed_addr #6

declare void @png_write_end(ptr noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #8

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { "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 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 #8 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #9 = { nounwind }
attributes #10 = { nounwind returns_twice }
attributes #11 = { noreturn nounwind }
attributes #12 = { nounwind allocsize(0) }

!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 = !{!"BufferItem", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = !{!6, !7, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !10, i64 16}


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