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

; 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.3 = 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
declare dso_local void @png_crc_read(ptr noalias noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_crc_finish(ptr noalias noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [1024 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %17, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp ugt i32 %9, 0
  br i1 %10, label %11, label %24

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %7) #4
  store i32 1024, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ugt i32 %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %16, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %15, %11
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub i32 %19, %18
  store i32 %20, ptr %5, align 4, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %23 = load i32, ptr %6, align 4, !tbaa !9
  call void @png_crc_read(ptr noundef %21, ptr noundef %22, i32 noundef %23)
  call void @llvm.lifetime.end.p0(i64 1024, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %8, !llvm.loop !11

24:                                               ; preds = %8
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 @png_crc_error(ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %52

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.png_struct_def, ptr %29, i32 0, i32 44
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = lshr i32 %31, 29
  %33 = and i32 1, %32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %28
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.png_struct_def, ptr %36, i32 0, i32 16
  %38 = load i32, ptr %37, align 8, !tbaa !24
  %39 = and i32 %38, 512
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %47, label %49

41:                                               ; preds = %28
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.png_struct_def, ptr %42, i32 0, i32 16
  %44 = load i32, ptr %43, align 8, !tbaa !24
  %45 = and i32 %44, 1024
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %41, %35
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @png_chunk_warning(ptr noundef %48, ptr noundef @.str.3)
  br label %51

49:                                               ; preds = %41, %35
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @png_chunk_error(ptr noundef %50, ptr noundef @.str.3) #5
  unreachable

51:                                               ; preds = %47
  store i32 1, ptr %3, align 4
  br label %53

52:                                               ; preds = %24
  store i32 0, ptr %3, align 4
  br label %53

53:                                               ; preds = %52, %51
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @png_crc_error(ptr noalias noundef) #1

declare void @png_chunk_warning(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn
declare void @png_chunk_error(ptr noundef, ptr noundef) #3

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 = { noreturn "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 #4 = { nounwind }
attributes #5 = { noreturn }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 536}
!14 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !15, 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, !16, 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, !15, i64 520, !10, i64 528, !10, i64 532, !10, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !15, i64 576, !10, i64 584, !10, i64 588, !6, i64 592, !17, i64 600, !10, i64 604, !17, 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, !17, i64 626, !7, i64 628, !10, i64 632, !18, i64 636, !18, 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, !19, i64 728, !19, i64 733, !6, i64 744, !18, 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, !15, i64 848, !15, i64 856, !15, i64 864, !15, 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, !17, i64 978, !17, 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, !15, i64 1064, !20, i64 1072, !15, i64 1104, !6, i64 1112, !15, i64 1120, !10, i64 1128, !10, i64 1132, !6, i64 1136, !7, i64 1144, !21, i64 1176}
!15 = !{!"long", !7, i64 0}
!16 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !15, i64 16, !6, i64 24, !10, i64 32, !15, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !15, i64 96, !15, i64 104}
!17 = !{!"short", !7, i64 0}
!18 = !{!"png_color_16_struct", !7, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !17, i64 8}
!19 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!20 = !{!"png_unknown_chunk_t", !7, i64 0, !6, i64 8, !15, i64 16, !7, i64 24}
!21 = !{!"png_colorspace", !10, i64 0, !22, i64 4, !23, i64 36, !17, i64 72, !17, i64 74}
!22 = !{!"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}
!23 = !{!"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}
!24 = !{!14, !10, i64 304}


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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @png_crc_read(ptr noalias noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @png_crc_finish(ptr noalias noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [1024 x i8], align 16
  %.not19 = icmp eq i32 %1, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01420 = phi i32 [ %4, %.lr.ph ], [ %1, %2 ]
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #5
  %spec.select = call i32 @llvm.umin.i32(i32 %.01420, i32 1024)
  %4 = sub i32 %.01420, %spec.select
  call void @png_crc_read(ptr noundef %0, ptr noundef nonnull %3, i32 noundef %spec.select)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %5 = call i32 @png_crc_error(ptr noundef %0)
  %.not16 = icmp eq i32 %5, 0
  br i1 %.not16, label %19, label %6

6:                                                ; preds = %._crit_edge
  %7 = getelementptr inbounds i8, ptr %0, i64 536
  %8 = load i32, ptr %7, align 8, !tbaa !7
  %9 = and i32 %8, 536870912
  %.not17 = icmp eq i32 %9, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 304
  %11 = load i32, ptr %10, align 8, !tbaa !22
  br i1 %.not17, label %15, label %12

12:                                               ; preds = %6
  %13 = and i32 %11, 512
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %17, label %18

15:                                               ; preds = %6
  %16 = and i32 %11, 1024
  %.not18 = icmp eq i32 %16, 0
  br i1 %.not18, label %18, label %17

17:                                               ; preds = %15, %12
  call void @png_chunk_warning(ptr noundef nonnull %0, ptr noundef nonnull @.str.3) #5
  br label %19

18:                                               ; preds = %15, %12
  call void @png_chunk_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.3) #6
  unreachable

19:                                               ; preds = %._crit_edge, %17
  %.015 = phi i32 [ 1, %17 ], [ 0, %._crit_edge ]
  ret i32 %.015
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @png_crc_error(ptr noalias noundef) local_unnamed_addr #1

declare void @png_chunk_warning(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn
declare void @png_chunk_error(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #4

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass