; LLVM IR from niessner/Matterport :: code/gaps/pkgs/png (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_struct = type { i32, i32, i32, i64, ptr, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, [8 x i8], float, i8, 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, ptr, float, float, float, float, float, float, float, float, ptr, i32, i32, ptr, ptr, i8, i8, i32, ptr, i64, ptr, ptr, i32, i8, ptr, i32, i8, double, double, ptr, ptr, ptr, 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 }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_png(ptr noundef %0, ptr 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 %105

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_info(ptr noundef %16, ptr noundef %17)
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = and i32 %18, 32
  %20 = icmp ne 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_set_invert_mono(ptr noundef %22)
  br label %23

23:                                               ; preds = %21, %15
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = and i32 %24, 64
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.png_info_struct, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = and i32 %30, 2
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.png_info_struct, ptr %35, i32 0, i32 22
  call void @png_set_shift(ptr noundef %34, ptr noundef %36)
  br label %37

37:                                               ; preds = %33, %27, %23
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = and i32 %38, 4
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_packing(ptr noundef %42)
  br label %43

43:                                               ; preds = %41, %37
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = and i32 %44, 256
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_swap_alpha(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %43
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = and i32 %50, 4096
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_filler(ptr noundef %54, i32 noundef 0, i32 noundef 1)
  br label %62

55:                                               ; preds = %49
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = and i32 %56, 2048
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_filler(ptr noundef %60, i32 noundef 0, i32 noundef 0)
  br label %61

61:                                               ; preds = %59, %55
  br label %62

62:                                               ; preds = %61, %53
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = and i32 %63, 128
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %68

66:                                               ; preds = %62
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_bgr(ptr noundef %67)
  br label %68

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

72:                                               ; preds = %68
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_swap(ptr noundef %73)
  br label %74

74:                                               ; preds = %72, %68
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = and i32 %75, 8
  %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_packswap(ptr noundef %79)
  br label %80

80:                                               ; preds = %78, %74
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = and i32 %81, 1024
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %80
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_invert_alpha(ptr noundef %85)
  br label %86

86:                                               ; preds = %84, %80
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.png_info_struct, ptr %87, i32 0, i32 2
  %89 = load i32, ptr %88, align 8, !tbaa !11
  %90 = zext i32 %89 to i64
  %91 = and i64 %90, 32768
  %92 = icmp ne i64 %91, 0
  br i1 %92, label %93, label %98

93:                                               ; preds = %86
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.png_info_struct, ptr %95, i32 0, i32 62
  %97 = load ptr, ptr %96, align 8, !tbaa !20
  call void @png_write_image(ptr noundef %94, ptr noundef %97)
  br label %98

98:                                               ; preds = %93, %86
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_end(ptr noundef %99, ptr noundef %100)
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = add nsw i32 %101, 0
  store i32 %102, ptr %7, align 4, !tbaa !9
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 0
  store ptr %104, ptr %8, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %98, %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_struct", !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, !7, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !16, i64 80, !17, i64 88, !6, i64 96, !18, i64 104, !18, i64 114, !10, i64 124, !10, i64 128, !7, i64 132, !10, i64 136, !10, i64 140, !7, i64 144, !6, i64 152, !15, i64 160, !15, i64 164, !15, i64 168, !15, i64 172, !15, i64 176, !15, i64 180, !15, i64 184, !15, i64 188, !6, i64 192, !10, i64 200, !10, i64 204, !6, i64 208, !6, i64 216, !7, i64 224, !7, i64 225, !10, i64 228, !6, i64 232, !13, i64 240, !6, i64 248, !6, i64 256, !10, i64 264, !7, i64 268, !6, i64 272, !10, i64 280, !7, i64 284, !19, i64 288, !19, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !10, i64 328, !10, i64 332, !10, i64 336, !10, i64 340, !10, i64 344, !10, i64 348, !10, i64 352, !10, i64 356, !10, i64 360}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"png_time_struct", !14, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!17 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!18 = !{!"png_color_16_struct", !7, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!19 = !{!"double", !7, i64 0}
!20 = !{!12, !6, i64 320}


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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_png(ptr noundef %0, ptr 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 %48, label %7

7:                                                ; preds = %4
  tail call void @png_write_info(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %8 = and i32 %2, 32
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %7
  tail call void @png_set_invert_mono(ptr noundef nonnull %0) #2
  br label %10

10:                                               ; preds = %9, %7
  %11 = and i32 %2, 64
  %.not34 = icmp eq i32 %11, 0
  br i1 %.not34, label %18, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = and i32 %14, 2
  %.not35 = icmp eq i32 %15, 0
  br i1 %.not35, label %18, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %1, i64 88
  tail call void @png_set_shift(ptr noundef nonnull %0, ptr noundef nonnull %17) #2
  br label %18

18:                                               ; preds = %16, %12, %10
  %19 = and i32 %2, 4
  %.not36 = icmp eq i32 %19, 0
  br i1 %.not36, label %21, label %20

20:                                               ; preds = %18
  tail call void @png_set_packing(ptr noundef nonnull %0) #2
  br label %21

21:                                               ; preds = %20, %18
  %22 = and i32 %2, 256
  %.not37 = icmp eq i32 %22, 0
  br i1 %.not37, label %24, label %23

23:                                               ; preds = %21
  tail call void @png_set_swap_alpha(ptr noundef nonnull %0) #2
  br label %24

24:                                               ; preds = %23, %21
  %25 = and i32 %2, 4096
  %.not38 = icmp eq i32 %25, 0
  br i1 %.not38, label %26, label %.sink.split

26:                                               ; preds = %24
  %27 = and i32 %2, 2048
  %.not39 = icmp eq i32 %27, 0
  br i1 %.not39, label %28, label %.sink.split

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

28:                                               ; preds = %.sink.split, %26
  %29 = and i32 %2, 128
  %.not40 = icmp eq i32 %29, 0
  br i1 %.not40, label %31, label %30

30:                                               ; preds = %28
  tail call void @png_set_bgr(ptr noundef nonnull %0) #2
  br label %31

31:                                               ; preds = %30, %28
  %32 = and i32 %2, 512
  %.not41 = icmp eq i32 %32, 0
  br i1 %.not41, label %34, label %33

33:                                               ; preds = %31
  tail call void @png_set_swap(ptr noundef nonnull %0) #2
  br label %34

34:                                               ; preds = %33, %31
  %35 = and i32 %2, 8
  %.not42 = icmp eq i32 %35, 0
  br i1 %.not42, label %37, label %36

36:                                               ; preds = %34
  tail call void @png_set_packswap(ptr noundef nonnull %0) #2
  br label %37

37:                                               ; preds = %36, %34
  %38 = and i32 %2, 1024
  %.not43 = icmp eq i32 %38, 0
  br i1 %.not43, label %40, label %39

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

40:                                               ; preds = %39, %37
  %41 = getelementptr inbounds i8, ptr %1, i64 8
  %42 = load i32, ptr %41, align 8, !tbaa !5
  %43 = and i32 %42, 32768
  %.not44 = icmp eq i32 %43, 0
  br i1 %.not44, label %47, label %44

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %1, i64 320
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  tail call void @png_write_image(ptr noundef nonnull %0, ptr noundef %46)
  br label %47

47:                                               ; preds = %44, %40
  tail call void @png_write_end(ptr noundef nonnull %0, ptr noundef nonnull %1)
  br label %48

48:                                               ; preds = %4, %47
  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_struct", !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, !8, i64 56, !7, i64 60, !7, i64 64, !11, i64 72, !14, i64 80, !15, i64 88, !11, i64 96, !16, i64 104, !16, i64 114, !7, i64 124, !7, i64 128, !8, i64 132, !7, i64 136, !7, i64 140, !8, i64 144, !11, i64 152, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !13, i64 184, !13, i64 188, !11, i64 192, !7, i64 200, !7, i64 204, !11, i64 208, !11, i64 216, !8, i64 224, !8, i64 225, !7, i64 228, !11, i64 232, !10, i64 240, !11, i64 248, !11, i64 256, !7, i64 264, !8, i64 268, !11, i64 272, !7, i64 280, !8, i64 284, !17, i64 288, !17, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !7, i64 328, !7, i64 332, !7, i64 336, !7, i64 340, !7, i64 344, !7, i64 348, !7, i64 352, !7, i64 356, !7, i64 360}
!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 = !{!"float", !8, i64 0}
!14 = !{!"png_time_struct", !12, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6}
!15 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!16 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!17 = !{!"double", !8, i64 0}
!18 = !{!6, !11, i64 320}


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