; LLVM IR from rdguez-mariano/fast_imas_IPOL :: io_png/libs/png (pngrtran)

; 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_struct_def = type { [1 x %struct.__jmp_buf_tag], ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i64, i64, i64, %struct.z_stream_s, ptr, i64, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, %struct.png_row_info_struct, i64, i64, ptr, i16, i16, [5 x i8], i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i8, float, %struct.png_color_16_struct, %struct.png_color_16_struct, ptr, i64, i64, i32, float, float, ptr, ptr, ptr, ptr, ptr, ptr, %struct.png_color_8_struct, %struct.png_color_8_struct, ptr, %struct.png_color_16_struct, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i32, i32, i64, i64, ptr, ptr, ptr, ptr, ptr, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, ptr, i32, ptr, i8, i16, i16, i16, i64, i64, i8, i8, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i64, i64, %struct.png_unknown_chunk_t, i64, i64, ptr }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }
%struct.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }
%struct.png_row_info_struct = type { i64, i64, 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 }
%struct.png_unknown_chunk_t = type { [5 x i8], ptr, i64, i8 }

@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1

declare void @png_warning(ptr noundef, ptr noundef) #0

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

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

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

13:                                               ; preds = %4
  br label %82

14:                                               ; preds = %4
  %15 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %15, label %31 [
    i32 1, label %16
    i32 2, label %21
    i32 3, label %26
  ]

16:                                               ; preds = %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.png_struct_def, ptr %17, i32 0, i32 14
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = or i64 %19, 6291456
  store i64 %20, ptr %18, align 8, !tbaa !13
  br label %31

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.png_struct_def, ptr %22, i32 0, i32 14
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = or i64 %24, 4194304
  store i64 %25, ptr %23, align 8, !tbaa !13
  br label %31

26:                                               ; preds = %14
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.png_struct_def, ptr %27, i32 0, i32 14
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = or i64 %29, 2097152
  store i64 %30, ptr %28, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %26, %21, %16, %14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.png_struct_def, ptr %32, i32 0, i32 49
  %34 = load i8, ptr %33, align 2, !tbaa !22
  %35 = zext i8 %34 to i32
  %36 = icmp eq i32 %35, 3
  br i1 %36, label %37, label %42

37:                                               ; preds = %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.png_struct_def, ptr %38, i32 0, i32 14
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = or i64 %40, 4096
  store i64 %41, ptr %39, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %37, %31
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %43 = load i64, ptr %7, align 8, !tbaa !11
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %48, label %45

45:                                               ; preds = %42
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45, %42
  store i16 6968, ptr %9, align 2, !tbaa !23
  store i16 23434, ptr %10, align 2, !tbaa !23
  br label %66

49:                                               ; preds = %45
  %50 = load i64, ptr %7, align 8, !tbaa !11
  %51 = load i64, ptr %8, align 8, !tbaa !11
  %52 = add nsw i64 %50, %51
  %53 = icmp slt i64 %52, 100000
  br i1 %53, label %54, label %63

54:                                               ; preds = %49
  %55 = load i64, ptr %7, align 8, !tbaa !11
  %56 = mul i64 %55, 32768
  %57 = udiv i64 %56, 100000
  %58 = trunc i64 %57 to i16
  store i16 %58, ptr %9, align 2, !tbaa !23
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = mul i64 %59, 32768
  %61 = udiv i64 %60, 100000
  %62 = trunc i64 %61 to i16
  store i16 %62, ptr %10, align 2, !tbaa !23
  br label %65

63:                                               ; preds = %49
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_warning(ptr noundef %64, ptr noundef @.str.2)
  store i16 6968, ptr %9, align 2, !tbaa !23
  store i16 23434, ptr %10, align 2, !tbaa !23
  br label %65

65:                                               ; preds = %63, %54
  br label %66

66:                                               ; preds = %65, %48
  %67 = load i16, ptr %9, align 2, !tbaa !23
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.png_struct_def, ptr %68, i32 0, i32 115
  store i16 %67, ptr %69, align 2, !tbaa !24
  %70 = load i16, ptr %10, align 2, !tbaa !23
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.png_struct_def, ptr %71, i32 0, i32 116
  store i16 %70, ptr %72, align 4, !tbaa !25
  %73 = load i16, ptr %9, align 2, !tbaa !23
  %74 = zext i16 %73 to i32
  %75 = sub nsw i32 32768, %74
  %76 = load i16, ptr %10, align 2, !tbaa !23
  %77 = zext i16 %76 to i32
  %78 = sub nsw i32 %75, %77
  %79 = trunc i32 %78 to i16
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.png_struct_def, ptr %80, i32 0, i32 117
  store i16 %79, ptr %81, align 2, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  br label %82

82:                                               ; preds = %66, %13
  ret void
}

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 296}
!14 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !7, i64 272, !7, i64 273, !12, i64 280, !12, i64 288, !12, i64 296, !15, i64 304, !6, i64 416, !12, i64 424, !10, i64 432, !10, i64 436, !10, i64 440, !10, i64 444, !10, i64 448, !12, i64 456, !12, i64 464, !12, i64 472, !12, i64 480, !12, i64 488, !12, i64 496, !12, i64 504, !12, i64 512, !6, i64 520, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !16, i64 568, !12, i64 592, !12, i64 600, !6, i64 608, !17, i64 616, !17, i64 618, !7, i64 620, !7, i64 625, !7, i64 626, !7, i64 627, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !7, i64 633, !7, i64 634, !7, i64 635, !7, i64 636, !17, i64 638, !7, i64 640, !18, i64 644, !19, i64 648, !19, i64 658, !6, i64 672, !12, i64 680, !12, i64 688, !10, i64 696, !18, i64 700, !18, i64 704, !6, i64 712, !6, i64 720, !6, i64 728, !6, i64 736, !6, i64 744, !6, i64 752, !20, i64 760, !20, i64 765, !6, i64 776, !19, i64 784, !6, i64 800, !6, i64 808, !6, i64 816, !6, i64 824, !6, i64 832, !6, i64 840, !6, i64 848, !6, i64 856, !6, i64 864, !12, i64 872, !12, i64 880, !12, i64 888, !12, i64 896, !12, i64 904, !12, i64 912, !10, i64 920, !10, i64 924, !12, i64 928, !12, i64 936, !6, i64 944, !6, i64 952, !6, i64 960, !6, i64 968, !6, i64 976, !7, i64 984, !7, i64 985, !6, i64 992, !6, i64 1000, !6, i64 1008, !6, i64 1016, !6, i64 1024, !6, i64 1032, !12, i64 1040, !6, i64 1048, !6, i64 1056, !10, i64 1064, !6, i64 1072, !7, i64 1080, !17, i64 1082, !17, i64 1084, !17, i64 1086, !12, i64 1088, !12, i64 1096, !7, i64 1104, !7, i64 1105, !12, i64 1112, !12, i64 1120, !6, i64 1128, !6, i64 1136, !6, i64 1144, !6, i64 1152, !6, i64 1160, !6, i64 1168, !6, i64 1176, !7, i64 1184, !12, i64 1192, !12, i64 1200, !21, i64 1208, !12, i64 1240, !12, i64 1248, !6, i64 1256}
!15 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !12, i64 16, !6, i64 24, !10, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !12, i64 96, !12, i64 104}
!16 = !{!"png_row_info_struct", !12, i64 0, !12, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19}
!17 = !{!"short", !7, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = !{!"png_color_16_struct", !7, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !17, i64 8}
!20 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!21 = !{!"png_unknown_chunk_t", !7, i64 0, !6, i64 8, !12, i64 16, !7, i64 24}
!22 = !{!14, !7, i64 630}
!23 = !{!17, !17, i64 0}
!24 = !{!14, !17, i64 1082}
!25 = !{!14, !17, i64 1084}
!26 = !{!14, !17, i64 1086}


; 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.2 = external hidden unnamed_addr constant [47 x i8], align 1

declare void @png_warning(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @png_set_rgb_to_gray_fixed(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %39, label %6

6:                                                ; preds = %4
  %switch.tableidx = add i32 %1, -1
  %7 = icmp ult i32 %switch.tableidx, 3
  br i1 %7, label %switch.lookup, label %12

switch.lookup:                                    ; preds = %6
  %8 = shl nuw nsw i32 %switch.tableidx, 21
  %narrow = sub nuw nsw i32 6291456, %8
  %switch.offset = zext nneg i32 %narrow to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 296
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = or i64 %10, %switch.offset
  store i64 %11, ptr %9, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %6, %switch.lookup
  %13 = getelementptr inbounds i8, ptr %0, i64 630
  %14 = load i8, ptr %13, align 2, !tbaa !19
  %15 = icmp eq i8 %14, 3
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 296
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = or i64 %18, 4096
  store i64 %19, ptr %17, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %16, %12
  %21 = or i64 %3, %2
  %or.cond.not = icmp sgt i64 %21, -1
  br i1 %or.cond.not, label %22, label %33

22:                                               ; preds = %20
  %23 = add nuw nsw i64 %3, %2
  %24 = icmp slt i64 %23, 100000
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = shl i64 %2, 15
  %27 = udiv i64 %26, 100000
  %28 = trunc i64 %27 to i16
  %29 = shl i64 %3, 15
  %30 = udiv i64 %29, 100000
  %31 = trunc i64 %30 to i16
  br label %33

32:                                               ; preds = %22
  tail call void @png_warning(ptr noundef nonnull %0, ptr noundef nonnull @.str.2) #2
  br label %33

33:                                               ; preds = %20, %25, %32
  %.021 = phi i16 [ %28, %25 ], [ 6968, %32 ], [ 6968, %20 ]
  %.0 = phi i16 [ %31, %25 ], [ 23434, %32 ], [ 23434, %20 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 1082
  store i16 %.021, ptr %34, align 2, !tbaa !20
  %35 = getelementptr inbounds i8, ptr %0, i64 1084
  store i16 %.0, ptr %35, align 4, !tbaa !21
  %36 = add i16 %.021, %.0
  %37 = sub i16 -32768, %36
  %38 = getelementptr inbounds i8, ptr %0, i64 1086
  store i16 %37, ptr %38, align 2, !tbaa !22
  br label %39

39:                                               ; preds = %4, %33
  ret void
}

attributes #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 = { 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 = { 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 296}
!6 = !{!"png_struct_def", !7, i64 0, !9, i64 200, !9, i64 208, !9, i64 216, !9, i64 224, !9, i64 232, !9, i64 240, !9, i64 248, !9, i64 256, !9, i64 264, !7, i64 272, !7, i64 273, !10, i64 280, !10, i64 288, !10, i64 296, !11, i64 304, !9, i64 416, !10, i64 424, !12, i64 432, !12, i64 436, !12, i64 440, !12, i64 444, !12, i64 448, !10, i64 456, !10, i64 464, !10, i64 472, !10, i64 480, !10, i64 488, !10, i64 496, !10, i64 504, !10, i64 512, !9, i64 520, !9, i64 528, !9, i64 536, !9, i64 544, !9, i64 552, !9, i64 560, !13, i64 568, !10, i64 592, !10, i64 600, !9, i64 608, !14, i64 616, !14, i64 618, !7, i64 620, !7, i64 625, !7, i64 626, !7, i64 627, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !7, i64 633, !7, i64 634, !7, i64 635, !7, i64 636, !14, i64 638, !7, i64 640, !15, i64 644, !16, i64 648, !16, i64 658, !9, i64 672, !10, i64 680, !10, i64 688, !12, i64 696, !15, i64 700, !15, i64 704, !9, i64 712, !9, i64 720, !9, i64 728, !9, i64 736, !9, i64 744, !9, i64 752, !17, i64 760, !17, i64 765, !9, i64 776, !16, i64 784, !9, i64 800, !9, i64 808, !9, i64 816, !9, i64 824, !9, i64 832, !9, i64 840, !9, i64 848, !9, i64 856, !9, i64 864, !10, i64 872, !10, i64 880, !10, i64 888, !10, i64 896, !10, i64 904, !10, i64 912, !12, i64 920, !12, i64 924, !10, i64 928, !10, i64 936, !9, i64 944, !9, i64 952, !9, i64 960, !9, i64 968, !9, i64 976, !7, i64 984, !7, i64 985, !9, i64 992, !9, i64 1000, !9, i64 1008, !9, i64 1016, !9, i64 1024, !9, i64 1032, !10, i64 1040, !9, i64 1048, !9, i64 1056, !12, i64 1064, !9, i64 1072, !7, i64 1080, !14, i64 1082, !14, i64 1084, !14, i64 1086, !10, i64 1088, !10, i64 1096, !7, i64 1104, !7, i64 1105, !10, i64 1112, !10, i64 1120, !9, i64 1128, !9, i64 1136, !9, i64 1144, !9, i64 1152, !9, i64 1160, !9, i64 1168, !9, i64 1176, !7, i64 1184, !10, i64 1192, !10, i64 1200, !18, i64 1208, !10, i64 1240, !10, i64 1248, !9, i64 1256}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"z_stream_s", !9, i64 0, !12, i64 8, !10, i64 16, !9, i64 24, !12, i64 32, !10, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !12, i64 88, !10, i64 96, !10, i64 104}
!12 = !{!"int", !7, i64 0}
!13 = !{!"png_row_info_struct", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19}
!14 = !{!"short", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"png_color_16_struct", !7, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!17 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!18 = !{!"png_unknown_chunk_t", !7, i64 0, !9, i64 8, !10, i64 16, !7, i64 24}
!19 = !{!6, !7, i64 630}
!20 = !{!6, !14, i64 1082}
!21 = !{!6, !14, i64 1084}
!22 = !{!6, !14, i64 1086}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass