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

; 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_image = type { ptr, i32, i32, i32, i32, i32, i32, i32, [64 x i8] }
%struct.png_control = type { ptr, ptr, ptr, ptr, i64, i8 }
%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.19 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_read_init(ptr noundef) #0

declare i32 @png_safe_execute(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_read_header(ptr noundef) #0

declare i32 @png_image_error(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_image_begin_read_from_memory(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %57

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.png_image, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %57

15:                                               ; preds = %10
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %53

18:                                               ; preds = %15
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %21, label %53

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @png_image_read_init(ptr noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %52

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.png_image, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.png_control, ptr %29, i32 0, i32 3
  store ptr %26, ptr %30, align 8, !tbaa !15
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.png_image, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = getelementptr inbounds %struct.png_control, ptr %34, i32 0, i32 4
  store i64 %31, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.png_image, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = getelementptr inbounds %struct.png_control, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = getelementptr inbounds %struct.png_struct_def, ptr %41, i32 0, i32 9
  store ptr %36, ptr %42, align 8, !tbaa !19
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.png_image, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds %struct.png_control, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct.png_struct_def, ptr %47, i32 0, i32 8
  store ptr @png_image_memory_read, ptr %48, align 8, !tbaa !29
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 @png_safe_execute(ptr noundef %49, ptr noundef @png_image_read_header, ptr noundef %50)
  store i32 %51, ptr %4, align 4
  br label %65

52:                                               ; preds = %21
  br label %56

53:                                               ; preds = %18, %15
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call i32 @png_image_error(ptr noundef %54, ptr noundef @.str.19)
  store i32 %55, ptr %4, align 4
  br label %65

56:                                               ; preds = %52
  br label %64

57:                                               ; preds = %10, %3
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %63

60:                                               ; preds = %57
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call i32 @png_image_error(ptr noundef %61, ptr noundef @.str.20)
  store i32 %62, ptr %4, align 4
  br label %65

63:                                               ; preds = %57
  br label %64

64:                                               ; preds = %63, %56
  store i32 0, ptr %4, align 4
  br label %65

65:                                               ; preds = %64, %60, %53, %25
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

; Function Attrs: nounwind uwtable
declare hidden void @png_image_memory_read(ptr noundef, ptr noundef, i64 noundef) #0

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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !7, i64 36}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 24}
!16 = !{!"png_control", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !13, i64 40}
!17 = !{!16, !10, i64 32}
!18 = !{!16, !6, i64 0}
!19 = !{!20, !6, i64 264}
!20 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !10, 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, !13, i64 300, !13, i64 304, !13, i64 308, !13, i64 312, !21, i64 320, !6, 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, !10, i64 520, !13, i64 528, !13, i64 532, !13, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !10, i64 576, !13, i64 584, !13, i64 588, !6, i64 592, !22, i64 600, !13, i64 604, !22, 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, !22, i64 626, !7, i64 628, !13, i64 632, !23, i64 636, !23, i64 646, !6, i64 656, !13, i64 664, !13, i64 668, !13, i64 672, !13, i64 676, !6, i64 680, !6, i64 688, !6, i64 696, !6, i64 704, !6, i64 712, !6, i64 720, !24, i64 728, !24, i64 733, !6, i64 744, !23, 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, !13, i64 840, !13, i64 844, !10, i64 848, !10, i64 856, !10, i64 864, !10, i64 872, !13, i64 880, !13, i64 884, !6, i64 888, !6, i64 896, !13, i64 904, !7, i64 908, !13, i64 940, !6, i64 944, !6, i64 952, !13, i64 960, !13, i64 964, !6, i64 968, !7, i64 976, !7, i64 977, !22, i64 978, !22, i64 980, !13, 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, !13, i64 1052, !13, i64 1056, !13, i64 1060, !10, i64 1064, !25, i64 1072, !10, i64 1104, !6, i64 1112, !10, i64 1120, !13, i64 1128, !13, i64 1132, !6, i64 1136, !7, i64 1144, !26, i64 1176}
!21 = !{!"z_stream_s", !6, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !10, i64 96, !10, i64 104}
!22 = !{!"short", !7, i64 0}
!23 = !{!"png_color_16_struct", !7, i64 0, !22, i64 2, !22, i64 4, !22, i64 6, !22, i64 8}
!24 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!25 = !{!"png_unknown_chunk_t", !7, i64 0, !6, i64 8, !10, i64 16, !7, i64 24}
!26 = !{!"png_colorspace", !13, i64 0, !27, i64 4, !28, i64 36, !22, i64 72, !22, i64 74}
!27 = !{!"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}
!28 = !{!"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}
!29 = !{!20, !6, i64 256}


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

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

declare i32 @png_safe_execute(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @png_image_read_header(ptr noundef) #0

declare i32 @png_image_error(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_image_begin_read_from_memory(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %23

8:                                                ; preds = %4
  %9 = icmp ne ptr %1, null
  %10 = icmp ne i64 %2, 0
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %11, label %21

11:                                               ; preds = %8
  %12 = tail call i32 @png_image_read_init(ptr noundef nonnull %0)
  %.not21 = icmp eq i32 %12, 0
  br i1 %.not21, label %.critedge, label %13

13:                                               ; preds = %11
  %14 = load ptr, ptr %0, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr %1, ptr %15, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %14, i64 32
  store i64 %2, ptr %16, align 8, !tbaa !15
  %17 = load ptr, ptr %14, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %17, i64 264
  store ptr %0, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %17, i64 256
  store ptr @png_image_memory_read, ptr %19, align 8, !tbaa !27
  %20 = tail call i32 @png_safe_execute(ptr noundef nonnull %0, ptr noundef nonnull @png_image_read_header, ptr noundef nonnull %0) #2
  br label %.critedge

21:                                               ; preds = %8
  %22 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.19) #2
  br label %.critedge

23:                                               ; preds = %4
  %24 = tail call i32 @png_image_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.20) #2
  br label %.critedge

.critedge:                                        ; preds = %11, %3, %23, %21, %13
  %.0 = phi i32 [ %20, %13 ], [ %22, %21 ], [ %24, %23 ], [ 0, %3 ], [ 0, %11 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @png_image_memory_read(ptr noundef, ptr noundef, i64 noundef) #0

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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !8, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 24}
!13 = !{!"png_control", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !14, i64 32, !10, i64 40, !10, i64 40}
!14 = !{!"long", !8, i64 0}
!15 = !{!13, !14, i64 32}
!16 = !{!13, !7, i64 0}
!17 = !{!18, !7, i64 264}
!18 = !{!"png_struct_def", !8, i64 0, !7, i64 200, !7, i64 208, !14, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !8, i64 296, !8, i64 297, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !19, i64 320, !7, 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, !14, i64 520, !10, i64 528, !10, i64 532, !10, i64 536, !7, i64 544, !7, i64 552, !7, i64 560, !7, i64 568, !14, i64 576, !10, i64 584, !10, i64 588, !7, i64 592, !20, i64 600, !10, i64 604, !20, 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, !20, i64 626, !8, i64 628, !10, i64 632, !21, i64 636, !21, i64 646, !7, i64 656, !10, i64 664, !10, i64 668, !10, i64 672, !10, i64 676, !7, i64 680, !7, i64 688, !7, i64 696, !7, i64 704, !7, i64 712, !7, i64 720, !22, i64 728, !22, i64 733, !7, i64 744, !21, i64 752, !7, i64 768, !7, i64 776, !7, i64 784, !7, i64 792, !7, i64 800, !7, i64 808, !7, i64 816, !7, i64 824, !7, i64 832, !10, i64 840, !10, i64 844, !14, i64 848, !14, i64 856, !14, i64 864, !14, i64 872, !10, i64 880, !10, i64 884, !7, i64 888, !7, i64 896, !10, i64 904, !8, i64 908, !10, i64 940, !7, i64 944, !7, i64 952, !10, i64 960, !10, i64 964, !7, i64 968, !8, i64 976, !8, i64 977, !20, i64 978, !20, i64 980, !10, i64 984, !8, i64 988, !7, i64 992, !7, i64 1000, !7, i64 1008, !7, i64 1016, !7, i64 1024, !7, i64 1032, !7, i64 1040, !8, i64 1048, !10, i64 1052, !10, i64 1056, !10, i64 1060, !14, i64 1064, !23, i64 1072, !14, i64 1104, !7, i64 1112, !14, i64 1120, !10, i64 1128, !10, i64 1132, !7, i64 1136, !8, i64 1144, !24, i64 1176}
!19 = !{!"z_stream_s", !7, i64 0, !10, i64 8, !14, i64 16, !7, i64 24, !10, i64 32, !14, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !14, i64 96, !14, i64 104}
!20 = !{!"short", !8, i64 0}
!21 = !{!"png_color_16_struct", !8, i64 0, !20, i64 2, !20, i64 4, !20, i64 6, !20, i64 8}
!22 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!23 = !{!"png_unknown_chunk_t", !8, i64 0, !7, i64 8, !14, i64 16, !8, i64 24}
!24 = !{!"png_colorspace", !10, i64 0, !25, i64 4, !26, i64 36, !20, i64 72, !20, i64 74}
!25 = !{!"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}
!26 = !{!"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}
!27 = !{!18, !7, i64 256}


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