; LLVM IR from corentinartaud/graphics :: ThirdParty/FreeImage-3170/Source/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 = type { ptr, i32, i32, i32, i32, i32, i32, i32, [64 x i8] }

@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [53 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
declare dso_local i32 @png_image_write_to_stdio(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

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

24:                                               ; preds = %19
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %82

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = call noalias ptr @fopen(ptr noundef %28, ptr noundef @.str.19)
  store ptr %29, ptr %14, align 8, !tbaa !5
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %75

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = call i32 @png_image_write_to_stdio(ptr noundef %33, ptr noundef %34, i32 noundef %35, ptr noundef %36, i32 noundef %37, ptr noundef %38)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %70

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = call i32 @fflush(ptr noundef %42)
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %57

45:                                               ; preds = %41
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = call i32 @ferror(ptr noundef %46) #5
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %57

49:                                               ; preds = %45
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = call i32 @fclose(ptr noundef %50)
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  store i32 1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %69

54:                                               ; preds = %49
  %55 = call ptr @__errno_location() #6
  %56 = load i32, ptr %55, align 4, !tbaa !9
  store i32 %56, ptr %15, align 4, !tbaa !9
  br label %62

57:                                               ; preds = %45, %41
  %58 = call ptr @__errno_location() #6
  %59 = load i32, ptr %58, align 4, !tbaa !9
  store i32 %59, ptr %15, align 4, !tbaa !9
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = call i32 @fclose(ptr noundef %60)
  br label %62

62:                                               ; preds = %57, %54
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call i32 @remove(ptr noundef %63) #5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = call ptr @strerror(i32 noundef %66) #5
  %68 = call i32 @png_image_error(ptr noundef %65, ptr noundef %67)
  store i32 %68, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %69

69:                                               ; preds = %62, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %81

70:                                               ; preds = %32
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = call i32 @fclose(ptr noundef %71)
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call i32 @remove(ptr noundef %73) #5
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %81

75:                                               ; preds = %27
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = call ptr @__errno_location() #6
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = call ptr @strerror(i32 noundef %78) #5
  %80 = call i32 @png_image_error(ptr noundef %76, ptr noundef %79)
  store i32 %80, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %81

81:                                               ; preds = %75, %70, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %92

82:                                               ; preds = %24
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = call i32 @png_image_error(ptr noundef %83, ptr noundef @.str.20)
  store i32 %84, ptr %7, align 4
  br label %92

85:                                               ; preds = %19, %6
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %91

88:                                               ; preds = %85
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = call i32 @png_image_error(ptr noundef %89, ptr noundef @.str.21)
  store i32 %90, ptr %7, align 4
  br label %92

91:                                               ; preds = %85
  store i32 0, ptr %7, align 4
  br label %92

92:                                               ; preds = %91, %88, %82, %81
  %93 = load i32, ptr %7, align 4
  ret i32 %93
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i32 @fflush(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #3

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nounwind
declare i32 @remove(ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strerror(i32 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 = { "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 = { 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 willreturn memory(none) "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 }
attributes #6 = { nounwind willreturn memory(none) }

!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}


; 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.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @png_image_write_to_stdio(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @png_image_write_to_file(ptr noundef %0, ptr noundef readonly %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %7

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

11:                                               ; preds = %7
  %.not29 = icmp eq ptr %1, null
  br i1 %.not29, label %44, label %12

12:                                               ; preds = %11
  %13 = tail call noalias ptr @fopen(ptr noundef nonnull %1, ptr noundef nonnull @.str.19)
  %.not30 = icmp eq ptr %13, null
  br i1 %.not30, label %39, label %14

14:                                               ; preds = %12
  %15 = tail call i32 @png_image_write_to_stdio(ptr noundef nonnull %0, ptr noundef nonnull %13, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5)
  %.not31 = icmp eq i32 %15, 0
  br i1 %.not31, label %36, label %16

16:                                               ; preds = %14
  %17 = tail call i32 @fflush(ptr noundef nonnull %13)
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = tail call i32 @ferror(ptr noundef nonnull %13) #6
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = tail call i32 @fclose(ptr noundef nonnull %13)
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %.critedge, label %25

25:                                               ; preds = %22
  %26 = tail call ptr @__errno_location() #7
  %27 = load i32, ptr %26, align 4, !tbaa !11
  br label %32

28:                                               ; preds = %19, %16
  %29 = tail call ptr @__errno_location() #7
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = tail call i32 @fclose(ptr noundef nonnull %13)
  br label %32

32:                                               ; preds = %28, %25
  %.0 = phi i32 [ %27, %25 ], [ %30, %28 ]
  %33 = tail call i32 @remove(ptr noundef nonnull %1) #6
  %34 = tail call ptr @strerror(i32 noundef %.0) #6
  %35 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef %34) #6
  br label %.critedge

36:                                               ; preds = %14
  %37 = tail call i32 @fclose(ptr noundef nonnull %13)
  %38 = tail call i32 @remove(ptr noundef nonnull %1) #6
  br label %.critedge

39:                                               ; preds = %12
  %40 = tail call ptr @__errno_location() #7
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = tail call ptr @strerror(i32 noundef %41) #6
  %43 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef %42) #6
  br label %.critedge

44:                                               ; preds = %11
  %45 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.20) #6
  br label %.critedge

46:                                               ; preds = %7
  %47 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.21) #6
  br label %.critedge

.critedge:                                        ; preds = %6, %36, %39, %22, %32, %46, %44
  %.2 = phi i32 [ %45, %44 ], [ %47, %46 ], [ 0, %36 ], [ %43, %39 ], [ %35, %32 ], [ 1, %22 ], [ 0, %6 ]
  ret i32 %.2
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #5

attributes #0 = { 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 #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 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nofree nounwind memory(read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 "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 }
attributes #7 = { nounwind willreturn memory(none) }

!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 = !{!10, !10, i64 0}


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