; 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_info_def = type { i32, i32, i32, i64, ptr, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, [8 x i8], %struct.png_colorspace, ptr, ptr, i32, i32, i32, ptr, %struct.png_time_struct, %struct.png_color_8_struct, ptr, %struct.png_color_16_struct, %struct.png_color_16_struct, i32, i32, i8, i32, i32, i8, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, i8, i8, i32, ptr, i32, ptr, i32, i8, ptr, ptr, ptr }
%struct.png_colorspace = type { i32, %struct.png_xy, %struct.png_XYZ, i16, i16 }
%struct.png_xy = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_XYZ = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_time_struct = type { i16, i8, i8, i8, i8, i8 }
%struct.png_color_8_struct = type { i8, i8, i8, i8, i8 }
%struct.png_color_16_struct = type { i8, i16, i16, i16, i16 }

@.str.13 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_info(ptr noalias noundef, ptr noalias noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_end(ptr noalias noundef, ptr noalias noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_image(ptr noalias noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_png(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %4
  br label %114

15:                                               ; preds = %11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.png_info_def, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = and i32 %18, 32768
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_app_error(ptr noundef %22, ptr noundef @.str.13)
  br label %114

23:                                               ; preds = %15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_info(ptr noundef %24, ptr noundef %25)
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = and i32 %26, 32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %23
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_invert_mono(ptr noundef %30)
  br label %31

31:                                               ; preds = %29, %23
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = and i32 %32, 64
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %46

35:                                               ; preds = %31
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.png_info_def, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = and i32 %38, 2
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %45

41:                                               ; preds = %35
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.png_info_def, ptr %43, i32 0, i32 24
  call void @png_set_shift(ptr noundef %42, ptr noundef %44)
  br label %45

45:                                               ; preds = %41, %35
  br label %46

46:                                               ; preds = %45, %31
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = and i32 %47, 4
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_packing(ptr noundef %51)
  br label %52

52:                                               ; preds = %50, %46
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = and i32 %53, 256
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %52
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_swap_alpha(ptr noundef %57)
  br label %58

58:                                               ; preds = %56, %52
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = and i32 %59, 6144
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %82

62:                                               ; preds = %58
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = and i32 %63, 4096
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %62
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = and i32 %67, 2048
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %66
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_app_error(ptr noundef %71, ptr noundef @.str.14)
  br label %72

72:                                               ; preds = %70, %66
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_filler(ptr noundef %73, i32 noundef 0, i32 noundef 1)
  br label %81

74:                                               ; preds = %62
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = and i32 %75, 2048
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %74
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_filler(ptr noundef %79, i32 noundef 0, i32 noundef 0)
  br label %80

80:                                               ; preds = %78, %74
  br label %81

81:                                               ; preds = %80, %72
  br label %82

82:                                               ; preds = %81, %58
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = and i32 %83, 128
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %88

86:                                               ; preds = %82
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_bgr(ptr noundef %87)
  br label %88

88:                                               ; preds = %86, %82
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = and i32 %89, 512
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %94

92:                                               ; preds = %88
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_swap(ptr noundef %93)
  br label %94

94:                                               ; preds = %92, %88
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = and i32 %95, 8
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %100

98:                                               ; preds = %94
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_packswap(ptr noundef %99)
  br label %100

100:                                              ; preds = %98, %94
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = and i32 %101, 1024
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %106

104:                                              ; preds = %100
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_invert_alpha(ptr noundef %105)
  br label %106

106:                                              ; preds = %104, %100
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.png_info_def, ptr %108, i32 0, i32 53
  %110 = load ptr, ptr %109, align 8, !tbaa !21
  call void @png_write_image(ptr noundef %107, ptr noundef %110)
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_end(ptr noundef %111, ptr noundef %112)
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  br label %114

114:                                              ; preds = %106, %21, %14
  ret void
}

declare void @png_set_invert_mono(ptr noundef) #1

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

declare void @png_set_packing(ptr noundef) #1

declare void @png_set_swap_alpha(ptr noundef) #1

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

declare void @png_set_bgr(ptr noundef) #1

declare void @png_set_swap(ptr noundef) #1

declare void @png_set_packswap(ptr noundef) #1

declare void @png_set_invert_alpha(ptr noundef) #1

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

!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 = !{!"png_info_def", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !6, i64 24, !14, i64 32, !14, i64 34, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !15, i64 52, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148, !10, i64 152, !6, i64 160, !18, i64 168, !19, i64 176, !6, i64 184, !20, i64 192, !20, i64 202, !10, i64 212, !10, i64 216, !7, i64 220, !10, i64 224, !10, i64 228, !7, i64 232, !10, i64 236, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !10, i64 272, !10, i64 276, !6, i64 280, !6, i64 288, !7, i64 296, !7, i64 297, !10, i64 300, !6, i64 304, !10, i64 312, !6, i64 320, !10, i64 328, !7, i64 332, !6, i64 336, !6, i64 344, !6, i64 352}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"png_colorspace", !10, i64 0, !16, i64 4, !17, i64 36, !14, i64 72, !14, i64 74}
!16 = !{!"png_xy", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!17 = !{!"png_XYZ", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!18 = !{!"png_time_struct", !14, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!19 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!20 = !{!"png_color_16_struct", !7, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!21 = !{!12, !6, i64 352}


; 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.13 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_info(ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_end(ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_image(ptr noalias noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_png(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %52, label %7

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

12:                                               ; preds = %7
  tail call void @png_app_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.13) #2
  br label %52

13:                                               ; preds = %7
  tail call void @png_write_info(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %14 = and i32 %2, 32
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %16, label %15

15:                                               ; preds = %13
  tail call void @png_set_invert_mono(ptr noundef nonnull %0) #2
  br label %16

16:                                               ; preds = %15, %13
  %17 = and i32 %2, 64
  %.not37 = icmp eq i32 %17, 0
  br i1 %.not37, label %23, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr %8, align 8, !tbaa !5
  %20 = and i32 %19, 2
  %.not38 = icmp eq i32 %20, 0
  br i1 %.not38, label %23, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %1, i64 176
  tail call void @png_set_shift(ptr noundef nonnull %0, ptr noundef nonnull %22) #2
  br label %23

23:                                               ; preds = %18, %21, %16
  %24 = and i32 %2, 4
  %.not39 = icmp eq i32 %24, 0
  br i1 %.not39, label %26, label %25

25:                                               ; preds = %23
  tail call void @png_set_packing(ptr noundef nonnull %0) #2
  br label %26

26:                                               ; preds = %25, %23
  %27 = and i32 %2, 256
  %.not40 = icmp eq i32 %27, 0
  br i1 %.not40, label %29, label %28

28:                                               ; preds = %26
  tail call void @png_set_swap_alpha(ptr noundef nonnull %0) #2
  br label %29

29:                                               ; preds = %28, %26
  %30 = and i32 %2, 6144
  %.not41 = icmp eq i32 %30, 0
  br i1 %.not41, label %37, label %31

31:                                               ; preds = %29
  %32 = and i32 %2, 4096
  %.not42 = icmp eq i32 %32, 0
  %33 = and i32 %2, 2048
  %.not43 = icmp eq i32 %33, 0
  br i1 %.not42, label %36, label %34

34:                                               ; preds = %31
  br i1 %.not43, label %.sink.split, label %35

35:                                               ; preds = %34
  tail call void @png_app_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.14) #2
  br label %.sink.split

36:                                               ; preds = %31
  br i1 %.not43, label %37, label %.sink.split

.sink.split:                                      ; preds = %36, %34, %35
  %.sink = phi i32 [ 1, %35 ], [ 1, %34 ], [ 0, %36 ]
  tail call void @png_set_filler(ptr noundef nonnull %0, i32 noundef 0, i32 noundef %.sink) #2
  br label %37

37:                                               ; preds = %.sink.split, %36, %29
  %38 = and i32 %2, 128
  %.not45 = icmp eq i32 %38, 0
  br i1 %.not45, label %40, label %39

39:                                               ; preds = %37
  tail call void @png_set_bgr(ptr noundef nonnull %0) #2
  br label %40

40:                                               ; preds = %39, %37
  %41 = and i32 %2, 512
  %.not46 = icmp eq i32 %41, 0
  br i1 %.not46, label %43, label %42

42:                                               ; preds = %40
  tail call void @png_set_swap(ptr noundef nonnull %0) #2
  br label %43

43:                                               ; preds = %42, %40
  %44 = and i32 %2, 8
  %.not47 = icmp eq i32 %44, 0
  br i1 %.not47, label %46, label %45

45:                                               ; preds = %43
  tail call void @png_set_packswap(ptr noundef nonnull %0) #2
  br label %46

46:                                               ; preds = %45, %43
  %47 = and i32 %2, 1024
  %.not48 = icmp eq i32 %47, 0
  br i1 %.not48, label %49, label %48

48:                                               ; preds = %46
  tail call void @png_set_invert_alpha(ptr noundef nonnull %0) #2
  br label %49

49:                                               ; preds = %48, %46
  %50 = getelementptr inbounds i8, ptr %1, i64 352
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  tail call void @png_write_image(ptr noundef nonnull %0, ptr noundef %51)
  tail call void @png_write_end(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %52

52:                                               ; preds = %4, %49, %12
  ret void
}

declare void @png_set_invert_mono(ptr noundef) local_unnamed_addr #1

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

declare void @png_set_packing(ptr noundef) local_unnamed_addr #1

declare void @png_set_swap_alpha(ptr noundef) local_unnamed_addr #1

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

declare void @png_set_bgr(ptr noundef) local_unnamed_addr #1

declare void @png_set_swap(ptr noundef) local_unnamed_addr #1

declare void @png_set_packswap(ptr noundef) local_unnamed_addr #1

declare void @png_set_invert_alpha(ptr noundef) local_unnamed_addr #1

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 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 8}
!6 = !{!"png_info_def", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !12, i64 34, !8, i64 36, !8, i64 37, !8, i64 38, !8, i64 39, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 43, !8, i64 44, !13, i64 52, !11, i64 128, !11, i64 136, !7, i64 144, !7, i64 148, !7, i64 152, !11, i64 160, !16, i64 168, !17, i64 176, !11, i64 184, !18, i64 192, !18, i64 202, !7, i64 212, !7, i64 216, !8, i64 220, !7, i64 224, !7, i64 228, !8, i64 232, !7, i64 236, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !7, i64 272, !7, i64 276, !11, i64 280, !11, i64 288, !8, i64 296, !8, i64 297, !7, i64 300, !11, i64 304, !7, i64 312, !11, i64 320, !7, i64 328, !8, i64 332, !11, i64 336, !11, i64 344, !11, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"png_colorspace", !7, i64 0, !14, i64 4, !15, i64 36, !12, i64 72, !12, i64 74}
!14 = !{!"png_xy", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!15 = !{!"png_XYZ", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!16 = !{!"png_time_struct", !12, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6}
!17 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!18 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!19 = !{!6, !11, i64 352}


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