; LLVM IR from rdguez-mariano/fast_imas_IPOL :: io_png/libs/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 { i64, i64, i64, 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, i64, i64, i8, i64, i64, i8, ptr, float, float, float, float, float, float, float, float, ptr, i64, i64, ptr, ptr, i8, i8, i64, ptr, i64, ptr, ptr, i64, i8, ptr, i64, i8, double, double, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%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 %102

15:                                               ; preds = %11
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = and i32 %16, 1024
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_invert_alpha(ptr noundef %20)
  br label %21

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

27:                                               ; preds = %21
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_invert_mono(ptr noundef %28)
  br label %29

29:                                               ; preds = %27, %21
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = and i32 %30, 64
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %43

33:                                               ; preds = %29
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.png_info_struct, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = and i64 %36, 2
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %33
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.png_info_struct, ptr %41, i32 0, i32 22
  call void @png_set_shift(ptr noundef %40, ptr noundef %42)
  br label %43

43:                                               ; preds = %39, %33, %29
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = and i32 %44, 4
  %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_packing(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %43
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = and i32 %50, 256
  %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_swap_alpha(ptr noundef %54)
  br label %55

55:                                               ; preds = %53, %49
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = and i32 %56, 4096
  %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, i64 noundef 0, i32 noundef 1)
  br label %68

61:                                               ; preds = %55
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = and i32 %62, 2048
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %61
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_set_filler(ptr noundef %66, i64 noundef 0, i32 noundef 0)
  br label %67

67:                                               ; preds = %65, %61
  br label %68

68:                                               ; preds = %67, %59
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = and i32 %69, 128
  %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_bgr(ptr noundef %73)
  br label %74

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

80:                                               ; preds = %78, %74
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = and i32 %81, 8
  %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_packswap(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 i64, ptr %88, align 8, !tbaa !11
  %90 = and i64 %89, 32768
  %91 = icmp ne i64 %90, 0
  br i1 %91, label %92, label %97

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

97:                                               ; preds = %92, %86
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_end(ptr noundef %98, ptr noundef %99)
  %100 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %100, ptr %7, align 4, !tbaa !9
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %101, ptr %8, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %97, %14
  ret void
}

declare void @png_set_invert_alpha(ptr noundef) #1

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, i64 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

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, !13, i64 16}
!12 = !{!"png_info_struct", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !14, i64 40, !14, i64 42, !7, i64 44, !7, i64 45, !7, i64 46, !7, i64 47, !7, i64 48, !7, i64 49, !7, i64 50, !7, i64 51, !7, i64 52, !15, i64 60, !7, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !16, i64 88, !17, i64 96, !6, i64 104, !18, i64 112, !18, i64 122, !13, i64 136, !13, i64 144, !7, i64 152, !13, i64 160, !13, i64 168, !7, i64 176, !6, i64 184, !15, i64 192, !15, i64 196, !15, i64 200, !15, i64 204, !15, i64 208, !15, i64 212, !15, i64 216, !15, i64 220, !6, i64 224, !13, i64 232, !13, i64 240, !6, i64 248, !6, i64 256, !7, i64 264, !7, i64 265, !13, i64 272, !6, i64 280, !13, i64 288, !6, i64 296, !6, i64 304, !13, i64 312, !7, i64 320, !6, i64 328, !13, i64 336, !7, i64 344, !19, i64 352, !19, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !13, i64 392, !13, i64 400, !13, i64 408, !13, i64 416, !13, i64 424, !13, i64 432, !13, i64 440, !13, i64 448, !13, i64 456}
!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 384}


; 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
  %8 = and i32 %2, 1024
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

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

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

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

13:                                               ; preds = %12, %10
  %14 = and i32 %2, 64
  %.not35 = icmp eq i32 %14, 0
  br i1 %.not35, label %21, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = and i64 %17, 2
  %.not36 = icmp eq i64 %18, 0
  br i1 %.not36, label %21, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %1, i64 96
  tail call void @png_set_shift(ptr noundef nonnull %0, ptr noundef nonnull %20) #2
  br label %21

21:                                               ; preds = %19, %15, %13
  %22 = and i32 %2, 4
  %.not37 = icmp eq i32 %22, 0
  br i1 %.not37, label %24, label %23

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

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

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

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

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

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

31:                                               ; preds = %.sink.split, %29
  %32 = and i32 %2, 128
  %.not41 = icmp eq i32 %32, 0
  br i1 %.not41, label %34, label %33

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

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

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

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

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

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

44:                                               ; preds = %40
  %45 = getelementptr inbounds i8, ptr %1, i64 384
  %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_alpha(ptr noundef) local_unnamed_addr #1

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, i64 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

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 16}
!6 = !{!"png_info_struct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !11, i64 42, !8, i64 44, !8, i64 45, !8, i64 46, !8, i64 47, !8, i64 48, !8, i64 49, !8, i64 50, !8, i64 51, !8, i64 52, !12, i64 60, !8, i64 64, !13, i64 68, !13, i64 72, !10, i64 80, !14, i64 88, !15, i64 96, !10, i64 104, !16, i64 112, !16, i64 122, !7, i64 136, !7, i64 144, !8, i64 152, !7, i64 160, !7, i64 168, !8, i64 176, !10, i64 184, !12, i64 192, !12, i64 196, !12, i64 200, !12, i64 204, !12, i64 208, !12, i64 212, !12, i64 216, !12, i64 220, !10, i64 224, !7, i64 232, !7, i64 240, !10, i64 248, !10, i64 256, !8, i64 264, !8, i64 265, !7, i64 272, !10, i64 280, !7, i64 288, !10, i64 296, !10, i64 304, !7, i64 312, !8, i64 320, !10, i64 328, !7, i64 336, !8, i64 344, !17, i64 352, !17, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !7, i64 392, !7, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !7, i64 432, !7, i64 440, !7, i64 448, !7, i64 456}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"png_time_struct", !11, 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, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8}
!17 = !{!"double", !8, i64 0}
!18 = !{!6, !10, i64 384}


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