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

; 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_def = type { i32, i32, i32, i64, ptr, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, [8 x i8], %struct.png_colorspace, ptr, ptr, i32, i32, i32, ptr, %struct.png_time_struct, %struct.png_color_8_struct, ptr, %struct.png_color_16_struct, %struct.png_color_16_struct, i32, i32, i8, i32, i32, i8, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, i8, i8, i32, ptr, i32, ptr, i32, i8, ptr, ptr, ptr }
%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 }
%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: 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 i32 @png_get_pHYs_dpi(ptr noalias noundef %0, ptr noalias noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %80

14:                                               ; preds = %5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %80

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.png_info_def, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = and i32 %20, 128
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %80

23:                                               ; preds = %17
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %33

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.png_info_def, ptr %27, i32 0, i32 31
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %29, ptr %30, align 4, !tbaa !9
  %31 = load i32, ptr %11, align 4, !tbaa !9
  %32 = or i32 %31, 128
  store i32 %32, ptr %11, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %26, %23
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %43

36:                                               ; preds = %33
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.png_info_def, ptr %37, i32 0, i32 32
  %39 = load i32, ptr %38, align 4, !tbaa !22
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %39, ptr %40, align 4, !tbaa !9
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = or i32 %41, 128
  store i32 %42, ptr %11, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %36, %33
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %79

46:                                               ; preds = %43
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.png_info_def, ptr %47, i32 0, i32 33
  %49 = load i8, ptr %48, align 8, !tbaa !23
  %50 = zext i8 %49 to i32
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %50, ptr %51, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = or i32 %52, 128
  store i32 %53, ptr %11, align 4, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %78

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

60:                                               ; preds = %57
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = uitofp i32 %62 to double
  %64 = call double @llvm.fmuladd.f64(double %63, double 2.540000e-02, double 5.000000e-01)
  %65 = fptoui double %64 to i32
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %60, %57
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %77

70:                                               ; preds = %67
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = uitofp i32 %72 to double
  %74 = call double @llvm.fmuladd.f64(double %73, double 2.540000e-02, double 5.000000e-01)
  %75 = fptoui double %74 to i32
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %75, ptr %76, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %70, %67
  br label %78

78:                                               ; preds = %77, %46
  br label %79

79:                                               ; preds = %78, %43
  br label %80

80:                                               ; preds = %79, %17, %14, %5
  %81 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %81
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 8}
!12 = !{!"png_info_def", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !6, i64 24, !14, i64 32, !14, i64 34, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !15, i64 52, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148, !10, i64 152, !6, i64 160, !18, i64 168, !19, i64 176, !6, i64 184, !20, i64 192, !20, i64 202, !10, i64 212, !10, i64 216, !7, i64 220, !10, i64 224, !10, i64 228, !7, i64 232, !10, i64 236, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !10, i64 272, !10, i64 276, !6, i64 280, !6, i64 288, !7, i64 296, !7, i64 297, !10, i64 300, !6, i64 304, !10, i64 312, !6, i64 320, !10, i64 328, !7, i64 332, !6, i64 336, !6, i64 344, !6, i64 352}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"png_colorspace", !10, i64 0, !16, i64 4, !17, i64 36, !14, i64 72, !14, i64 74}
!16 = !{!"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}
!17 = !{!"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}
!18 = !{!"png_time_struct", !14, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!19 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!20 = !{!"png_color_16_struct", !7, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!21 = !{!12, !10, i64 224}
!22 = !{!12, !10, i64 228}
!23 = !{!12, !7, i64 232}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 129) i32 @png_get_pHYs_dpi(ptr noalias noundef readnone %0, ptr noalias noundef readonly %1, ptr noundef %2, ptr noundef %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %6 = icmp ne ptr %0, null
  %7 = icmp ne ptr %1, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %8, label %38

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = and i32 %10, 128
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %38, label %12

12:                                               ; preds = %8
  %.not29 = icmp eq ptr %2, null
  br i1 %.not29, label %16, label %13

13:                                               ; preds = %12
  %14 = getelementptr inbounds i8, ptr %1, i64 224
  %15 = load i32, ptr %14, align 8, !tbaa !19
  store i32 %15, ptr %2, align 4, !tbaa !20
  br label %16

16:                                               ; preds = %13, %12
  %.0 = phi i32 [ 128, %13 ], [ 0, %12 ]
  %.not30 = icmp eq ptr %3, null
  br i1 %.not30, label %20, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %1, i64 228
  %19 = load i32, ptr %18, align 4, !tbaa !21
  store i32 %19, ptr %3, align 4, !tbaa !20
  br label %20

20:                                               ; preds = %17, %16
  %.1 = phi i32 [ 128, %17 ], [ %.0, %16 ]
  %.not31 = icmp eq ptr %4, null
  br i1 %.not31, label %38, label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds i8, ptr %1, i64 232
  %23 = load i8, ptr %22, align 8, !tbaa !22
  %24 = zext i8 %23 to i32
  store i32 %24, ptr %4, align 4, !tbaa !20
  %25 = icmp eq i8 %23, 1
  br i1 %25, label %26, label %38

26:                                               ; preds = %21
  br i1 %.not29, label %32, label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %2, align 4, !tbaa !20
  %29 = uitofp i32 %28 to double
  %30 = tail call double @llvm.fmuladd.f64(double %29, double 2.540000e-02, double 5.000000e-01)
  %31 = fptoui double %30 to i32
  store i32 %31, ptr %2, align 4, !tbaa !20
  br label %32

32:                                               ; preds = %27, %26
  br i1 %.not30, label %38, label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %3, align 4, !tbaa !20
  %35 = uitofp i32 %34 to double
  %36 = tail call double @llvm.fmuladd.f64(double %35, double 2.540000e-02, double 5.000000e-01)
  %37 = fptoui double %36 to i32
  store i32 %37, ptr %3, align 4, !tbaa !20
  br label %38

38:                                               ; preds = %20, %32, %33, %21, %8, %5
  %.2 = phi i32 [ 128, %33 ], [ 128, %32 ], [ 128, %21 ], [ %.1, %20 ], [ 0, %8 ], [ 0, %5 ]
  ret i32 %.2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 8}
!6 = !{!"png_info_def", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !12, i64 34, !8, i64 36, !8, i64 37, !8, i64 38, !8, i64 39, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 43, !8, i64 44, !13, i64 52, !11, i64 128, !11, i64 136, !7, i64 144, !7, i64 148, !7, i64 152, !11, i64 160, !16, i64 168, !17, i64 176, !11, i64 184, !18, i64 192, !18, i64 202, !7, i64 212, !7, i64 216, !8, i64 220, !7, i64 224, !7, i64 228, !8, i64 232, !7, i64 236, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !7, i64 272, !7, i64 276, !11, i64 280, !11, i64 288, !8, i64 296, !8, i64 297, !7, i64 300, !11, i64 304, !7, i64 312, !11, i64 320, !7, i64 328, !8, i64 332, !11, i64 336, !11, i64 344, !11, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"png_colorspace", !7, i64 0, !14, i64 4, !15, i64 36, !12, i64 72, !12, i64 74}
!14 = !{!"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}
!15 = !{!"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}
!16 = !{!"png_time_struct", !12, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6}
!17 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!18 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!19 = !{!6, !7, i64 224}
!20 = !{!7, !7, i64 0}
!21 = !{!6, !7, i64 228}
!22 = !{!6, !8, i64 232}


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