; LLVM IR from Try/Tempest :: Engine/thirdparty/libpng (pngwrite)

; 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_image_write_control = type { ptr, ptr, i32, ptr, i32, ptr, i64, ptr, ptr, i64, i64 }
%struct.png_image = type { ptr, i32, i32, i32, i32, i32, i32, i32, [64 x i8] }

@.str.15 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [55 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @png_image_write_to_memory(ptr noundef %0, ptr noundef %1, ptr noalias noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca %struct.png_image_write_control, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %82

20:                                               ; preds = %7
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.png_image, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %82

25:                                               ; preds = %20
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %79

28:                                               ; preds = %25
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %79

31:                                               ; preds = %28
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %35, align 8, !tbaa !13
  br label %36

36:                                               ; preds = %34, %31
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = call i32 @png_image_write_init(ptr noundef %37)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %78

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 88, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 88, i1 false)
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 0
  store ptr %41, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 1
  store ptr %43, ptr %44, align 8, !tbaa !17
  %45 = load i32, ptr %14, align 4, !tbaa !9
  %46 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 2
  store i32 %45, ptr %46, align 8, !tbaa !18
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 3
  store ptr %47, ptr %48, align 8, !tbaa !19
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 4
  store i32 %49, ptr %50, align 8, !tbaa !20
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 8
  store ptr %51, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !13
  %55 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 9
  store i64 %54, ptr %55, align 8, !tbaa !22
  %56 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 10
  store i64 0, ptr %56, align 8, !tbaa !23
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = call i32 @png_safe_execute(ptr noundef %57, ptr noundef @png_image_write_memory, ptr noundef %16)
  store i32 %58, ptr %17, align 4, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_image_free(ptr noundef %59)
  %60 = load i32, ptr %17, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %76

62:                                               ; preds = %40
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %72

65:                                               ; preds = %62
  %66 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 10
  %67 = load i64, ptr %66, align 8, !tbaa !23
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8, !tbaa !13
  %70 = icmp ugt i64 %67, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %65
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %71, %65, %62
  %73 = getelementptr inbounds %struct.png_image_write_control, ptr %16, i32 0, i32 10
  %74 = load i64, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %74, ptr %75, align 8, !tbaa !13
  br label %76

76:                                               ; preds = %72, %40
  %77 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %77, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 88, ptr %16) #4
  br label %89

78:                                               ; preds = %36
  store i32 0, ptr %8, align 4
  br label %89

79:                                               ; preds = %28, %25
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = call i32 @png_image_error(ptr noundef %80, ptr noundef @.str.15)
  store i32 %81, ptr %8, align 4
  br label %89

82:                                               ; preds = %20, %7
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %88

85:                                               ; preds = %82
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = call i32 @png_image_error(ptr noundef %86, ptr noundef @.str.16)
  store i32 %87, ptr %8, align 4
  br label %89

88:                                               ; preds = %82
  store i32 0, ptr %8, align 4
  br label %89

89:                                               ; preds = %88, %85, %79, %78, %76
  %90 = load i32, ptr %8, align 4
  ret i32 %90
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_write_init(ptr noundef) #1

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

declare i32 @png_safe_execute(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_write_memory(ptr noundef) #1

declare void @png_image_free(ptr noundef) #3

declare i32 @png_image_error(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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, !10, i64 8}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 36}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !14, i64 48, !6, i64 56, !6, i64 64, !14, i64 72, !14, i64 80}
!17 = !{!16, !6, i64 8}
!18 = !{!16, !10, i64 16}
!19 = !{!16, !6, i64 24}
!20 = !{!16, !10, i64 32}
!21 = !{!16, !6, i64 64}
!22 = !{!16, !14, i64 72}
!23 = !{!16, !14, i64 80}


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

@.str.15 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [55 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @png_image_write_to_memory(ptr noundef %0, ptr noundef %1, ptr noalias noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = alloca %struct.png_image_write_control, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %40

13:                                               ; preds = %9
  %14 = icmp ne ptr %2, null
  %15 = icmp ne ptr %4, null
  %or.cond = and i1 %14, %15
  br i1 %or.cond, label %16, label %38

16:                                               ; preds = %13
  %17 = icmp eq ptr %1, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  store i64 0, ptr %2, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %18, %16
  %20 = tail call i32 @png_image_write_init(ptr noundef nonnull %0)
  %.not32 = icmp eq i32 %20, 0
  br i1 %.not32, label %.critedge, label %21

21:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %8) #4
  %22 = getelementptr inbounds i8, ptr %8, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %22, i8 0, i64 48, i1 false)
  store ptr %0, ptr %8, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %4, ptr %23, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %8, i64 16
  store i32 %5, ptr %24, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %6, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %8, i64 32
  store i32 %3, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %8, i64 64
  store ptr %1, ptr %27, align 8, !tbaa !19
  %28 = load i64, ptr %2, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %8, i64 72
  store i64 %28, ptr %29, align 8, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %8, i64 80
  store i64 0, ptr %30, align 8, !tbaa !21
  %31 = call i32 @png_safe_execute(ptr noundef nonnull %0, ptr noundef nonnull @png_image_write_memory, ptr noundef nonnull %8) #4
  call void @png_image_free(ptr noundef nonnull %0) #4
  %.not33 = icmp eq i32 %31, 0
  br i1 %.not33, label %37, label %32

32:                                               ; preds = %21
  %.pre = load i64, ptr %30, align 8, !tbaa !21
  br i1 %17, label %36, label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %2, align 8, !tbaa !11
  %35 = icmp ugt i64 %.pre, %34
  %spec.select = select i1 %35, i32 0, i32 %31
  br label %36

36:                                               ; preds = %33, %32
  %.0 = phi i32 [ %31, %32 ], [ %spec.select, %33 ]
  store i64 %.pre, ptr %2, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %36, %21
  %.1 = phi i32 [ %.0, %36 ], [ 0, %21 ]
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %8) #4
  br label %.critedge

38:                                               ; preds = %13
  %39 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.15) #4
  br label %.critedge

40:                                               ; preds = %9
  %41 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.16) #4
  br label %.critedge

.critedge:                                        ; preds = %7, %19, %40, %38, %37
  %.025 = phi i32 [ %.1, %37 ], [ %39, %38 ], [ %41, %40 ], [ 0, %19 ], [ 0, %7 ]
  ret i32 %.025
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_write_init(ptr noundef) local_unnamed_addr #1

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

declare i32 @png_safe_execute(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_write_memory(ptr noundef) #1

declare void @png_image_free(ptr noundef) local_unnamed_addr #3

declare i32 @png_image_error(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !8, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !12, i64 48, !7, i64 56, !7, i64 64, !12, i64 72, !12, i64 80}
!15 = !{!14, !7, i64 8}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !7, i64 24}
!18 = !{!14, !10, i64 32}
!19 = !{!14, !7, i64 64}
!20 = !{!14, !12, i64 72}
!21 = !{!14, !12, i64 80}


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