; LLVM IR from Try/Tempest :: Engine/thirdparty/libpng (png)

; 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, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, i32, i32, i32, %struct.z_stream_s, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, ptr, ptr, ptr, ptr, i64, i32, i32, ptr, i16, i32, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i8, i32, %struct.png_color_16_struct, %struct.png_color_16_struct, ptr, i32, i32, i32, i32, 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, i32, i32, i64, i64, i64, i64, i32, i32, ptr, ptr, i32, [29 x i8], i32, ptr, ptr, i32, i32, ptr, i8, i8, i16, i16, i32, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i32, i32, i32, i64, %struct.png_unknown_chunk_t, i64, ptr, i64, i32, i32, ptr, [4 x ptr], %struct.png_colorspace }
%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_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 }
%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 }

@.str.20 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [10 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
define dso_local void @png_colorspace_set_gamma(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 16
  br i1 %10, label %14, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 625000000
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %3
  store ptr @.str.20, ptr %7, align 8, !tbaa !5
  br label %55

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.png_struct_def, ptr %16, i32 0, i32 15
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = and i32 %18, 32768
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.png_colorspace, ptr %22, i32 0, i32 4
  %24 = load i16, ptr %23, align 2, !tbaa !22
  %25 = zext i16 %24 to i32
  %26 = and i32 %25, 8
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  store ptr @.str.21, ptr %7, align 8, !tbaa !5
  br label %54

29:                                               ; preds = %21, %15
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.png_colorspace, ptr %30, i32 0, i32 4
  %32 = load i16, ptr %31, align 2, !tbaa !22
  %33 = zext i16 %32 to i32
  %34 = and i32 %33, 32768
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %29
  store i32 1, ptr %8, align 4
  br label %64

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = call i32 @png_colorspace_check_gamma(ptr noundef %38, ptr noundef %39, i32 noundef %40, i32 noundef 1)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %37
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.png_colorspace, ptr %45, i32 0, i32 0
  store i32 %44, ptr %46, align 4, !tbaa !23
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.png_colorspace, ptr %47, i32 0, i32 4
  %49 = load i16, ptr %48, align 2, !tbaa !22
  %50 = zext i16 %49 to i32
  %51 = or i32 %50, 9
  %52 = trunc i32 %51 to i16
  store i16 %52, ptr %48, align 2, !tbaa !22
  br label %53

53:                                               ; preds = %43, %37
  store i32 1, ptr %8, align 4
  br label %64

54:                                               ; preds = %28
  br label %55

55:                                               ; preds = %54, %14
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.png_colorspace, ptr %56, i32 0, i32 4
  %58 = load i16, ptr %57, align 2, !tbaa !22
  %59 = zext i16 %58 to i32
  %60 = or i32 %59, 32768
  %61 = trunc i32 %60 to i16
  store i16 %61, ptr %57, align 2, !tbaa !22
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @png_chunk_report(ptr noundef %62, ptr noundef %63, i32 noundef 1)
  store i32 0, ptr %8, align 4
  br label %64

64:                                               ; preds = %55, %53, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %65 = load i32, ptr %8, align 4
  switch i32 %65, label %67 [
    i32 0, label %66
    i32 1, label %66
  ]

66:                                               ; preds = %64, %64
  ret void

67:                                               ; preds = %64
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_check_gamma(ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) #1

declare void @png_chunk_report(ptr noundef, ptr noundef, i32 noundef) #2

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 }

!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 300}
!12 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !13, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !7, i64 296, !7, i64 297, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !14, i64 320, !6, i64 432, !10, i64 440, !10, i64 444, !10, i64 448, !10, i64 452, !10, i64 456, !10, i64 460, !10, i64 464, !10, i64 468, !10, i64 472, !10, i64 476, !10, i64 480, !10, i64 484, !10, i64 488, !10, i64 492, !10, i64 496, !10, i64 500, !10, i64 504, !10, i64 508, !10, i64 512, !10, i64 516, !13, i64 520, !10, i64 528, !10, i64 532, !10, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !13, i64 576, !10, i64 584, !10, i64 588, !6, i64 592, !15, i64 600, !10, i64 604, !15, i64 608, !7, i64 610, !7, i64 611, !7, i64 612, !7, i64 613, !7, i64 614, !7, i64 615, !7, i64 616, !7, i64 617, !7, i64 618, !7, i64 619, !7, i64 620, !7, i64 621, !7, i64 622, !7, i64 623, !7, i64 624, !15, i64 626, !7, i64 628, !10, i64 632, !16, i64 636, !16, i64 646, !6, i64 656, !10, i64 664, !10, i64 668, !10, i64 672, !10, i64 676, !6, i64 680, !6, i64 688, !6, i64 696, !6, i64 704, !6, i64 712, !6, i64 720, !17, i64 728, !17, i64 733, !6, i64 744, !16, i64 752, !6, i64 768, !6, i64 776, !6, i64 784, !6, i64 792, !6, i64 800, !6, i64 808, !6, i64 816, !6, i64 824, !6, i64 832, !10, i64 840, !10, i64 844, !13, i64 848, !13, i64 856, !13, i64 864, !13, i64 872, !10, i64 880, !10, i64 884, !6, i64 888, !6, i64 896, !10, i64 904, !7, i64 908, !10, i64 940, !6, i64 944, !6, i64 952, !10, i64 960, !10, i64 964, !6, i64 968, !7, i64 976, !7, i64 977, !15, i64 978, !15, i64 980, !10, i64 984, !7, i64 988, !6, i64 992, !6, i64 1000, !6, i64 1008, !6, i64 1016, !6, i64 1024, !6, i64 1032, !6, i64 1040, !7, i64 1048, !10, i64 1052, !10, i64 1056, !10, i64 1060, !13, i64 1064, !18, i64 1072, !13, i64 1104, !6, i64 1112, !13, i64 1120, !10, i64 1128, !10, i64 1132, !6, i64 1136, !7, i64 1144, !19, i64 1176}
!13 = !{!"long", !7, i64 0}
!14 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !13, i64 96, !13, i64 104}
!15 = !{!"short", !7, i64 0}
!16 = !{!"png_color_16_struct", !7, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !15, 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, !6, i64 8, !13, i64 16, !7, i64 24}
!19 = !{!"png_colorspace", !10, i64 0, !20, i64 4, !21, i64 36, !15, i64 72, !15, i64 74}
!20 = !{!"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}
!21 = !{!"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}
!22 = !{!19, !15, i64 74}
!23 = !{!19, !10, i64 0}


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

; Function Attrs: nounwind uwtable
define dso_local void @png_colorspace_set_gamma(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %2, -625000001
  %or.cond = icmp ult i32 %4, -624999985
  br i1 %or.cond, label %._crit_edge18, label %5

._crit_edge18:                                    ; preds = %3
  %.phi.trans.insert19 = getelementptr inbounds i8, ptr %1, i64 74
  %.pre20 = load i16, ptr %.phi.trans.insert19, align 2, !tbaa !5
  br label %16

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 300
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = and i32 %7, 32768
  %.not = icmp eq i32 %8, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 74
  %.pre = load i16, ptr %.phi.trans.insert, align 2, !tbaa !5
  %9 = and i16 %.pre, 8
  %.not15 = icmp eq i16 %9, 0
  %or.cond21 = select i1 %.not, i1 true, i1 %.not15
  br i1 %or.cond21, label %._crit_edge, label %16

._crit_edge:                                      ; preds = %5
  %10 = getelementptr inbounds i8, ptr %1, i64 74
  %.not16 = icmp sgt i16 %.pre, -1
  br i1 %.not16, label %11, label %20

11:                                               ; preds = %._crit_edge
  %12 = tail call i32 @png_colorspace_check_gamma(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef 1)
  %.not17 = icmp eq i32 %12, 0
  br i1 %.not17, label %20, label %13

13:                                               ; preds = %11
  store i32 %2, ptr %1, align 4, !tbaa !21
  %14 = load i16, ptr %10, align 2, !tbaa !5
  %15 = or i16 %14, 9
  store i16 %15, ptr %10, align 2, !tbaa !5
  br label %20

16:                                               ; preds = %5, %._crit_edge18
  %17 = phi i16 [ %.pre20, %._crit_edge18 ], [ %.pre, %5 ]
  %.0 = phi ptr [ @.str.20, %._crit_edge18 ], [ @.str.21, %5 ]
  %18 = getelementptr inbounds i8, ptr %1, i64 74
  %19 = or i16 %17, -32768
  store i16 %19, ptr %18, align 2, !tbaa !5
  tail call void @png_chunk_report(ptr noundef %0, ptr noundef nonnull %.0, i32 noundef 1) #2
  br label %20

20:                                               ; preds = %11, %13, %._crit_edge, %16
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_check_gamma(ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @png_chunk_report(ptr noundef, ptr noundef, i32 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, !12, i64 74}
!6 = !{!"png_colorspace", !7, i64 0, !10, i64 4, !11, i64 36, !12, i64 72, !12, i64 74}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"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}
!11 = !{!"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}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !7, i64 300}
!14 = !{!"png_struct_def", !8, i64 0, !15, i64 200, !15, i64 208, !16, i64 216, !15, i64 224, !15, i64 232, !15, i64 240, !15, i64 248, !15, i64 256, !15, i64 264, !15, i64 272, !15, i64 280, !15, i64 288, !8, i64 296, !8, i64 297, !7, i64 300, !7, i64 304, !7, i64 308, !7, i64 312, !17, i64 320, !15, i64 432, !7, i64 440, !7, i64 444, !7, i64 448, !7, i64 452, !7, i64 456, !7, i64 460, !7, i64 464, !7, i64 468, !7, i64 472, !7, i64 476, !7, i64 480, !7, i64 484, !7, i64 488, !7, i64 492, !7, i64 496, !7, i64 500, !7, i64 504, !7, i64 508, !7, i64 512, !7, i64 516, !16, i64 520, !7, i64 528, !7, i64 532, !7, i64 536, !15, i64 544, !15, i64 552, !15, i64 560, !15, i64 568, !16, i64 576, !7, i64 584, !7, i64 588, !15, i64 592, !12, i64 600, !7, i64 604, !12, i64 608, !8, i64 610, !8, i64 611, !8, i64 612, !8, i64 613, !8, i64 614, !8, i64 615, !8, i64 616, !8, i64 617, !8, i64 618, !8, i64 619, !8, i64 620, !8, i64 621, !8, i64 622, !8, i64 623, !8, i64 624, !12, i64 626, !8, i64 628, !7, i64 632, !18, i64 636, !18, i64 646, !15, i64 656, !7, i64 664, !7, i64 668, !7, i64 672, !7, i64 676, !15, i64 680, !15, i64 688, !15, i64 696, !15, i64 704, !15, i64 712, !15, i64 720, !19, i64 728, !19, i64 733, !15, i64 744, !18, i64 752, !15, i64 768, !15, i64 776, !15, i64 784, !15, i64 792, !15, i64 800, !15, i64 808, !15, i64 816, !15, i64 824, !15, i64 832, !7, i64 840, !7, i64 844, !16, i64 848, !16, i64 856, !16, i64 864, !16, i64 872, !7, i64 880, !7, i64 884, !15, i64 888, !15, i64 896, !7, i64 904, !8, i64 908, !7, i64 940, !15, i64 944, !15, i64 952, !7, i64 960, !7, i64 964, !15, i64 968, !8, i64 976, !8, i64 977, !12, i64 978, !12, i64 980, !7, i64 984, !8, i64 988, !15, i64 992, !15, i64 1000, !15, i64 1008, !15, i64 1016, !15, i64 1024, !15, i64 1032, !15, i64 1040, !8, i64 1048, !7, i64 1052, !7, i64 1056, !7, i64 1060, !16, i64 1064, !20, i64 1072, !16, i64 1104, !15, i64 1112, !16, i64 1120, !7, i64 1128, !7, i64 1132, !15, i64 1136, !8, i64 1144, !6, i64 1176}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!"z_stream_s", !15, i64 0, !7, i64 8, !16, i64 16, !15, i64 24, !7, i64 32, !16, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !7, i64 88, !16, i64 96, !16, i64 104}
!18 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!19 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!20 = !{!"png_unknown_chunk_t", !8, i64 0, !15, i64 8, !16, i64 16, !8, i64 24}
!21 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass