; LLVM IR from niessner/Matterport :: code/gaps/pkgs/png (pngset)

; 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_struct = type { i32, i32, i32, i64, ptr, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, [8 x i8], float, i8, 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, ptr, float, float, float, float, float, float, float, float, ptr, i32, i32, ptr, ptr, i8, i8, i32, ptr, i64, ptr, ptr, i32, i8, ptr, i32, i8, double, double, ptr, ptr, ptr, 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 }

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @png_set_gAMA(ptr noundef %0, ptr noundef %1, double noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, 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 double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %3
  store i32 1, ptr %8, align 4
  br label %41

15:                                               ; preds = %11
  %16 = load double, ptr %6, align 8, !tbaa !9
  %17 = fcmp ogt double %16, 0x40D4F8B51EB851EC
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @png_warning(ptr noundef %19, ptr noundef @.str)
  store double 0x40D4F8B51EB851EC, ptr %7, align 8, !tbaa !9
  br label %22

20:                                               ; preds = %15
  %21 = load double, ptr %6, align 8, !tbaa !9
  store double %21, ptr %7, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %20, %18
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = fptrunc double %23 to float
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.png_info_struct, ptr %25, i32 0, i32 16
  store float %24, ptr %26, align 4, !tbaa !11
  %27 = load double, ptr %7, align 8, !tbaa !9
  %28 = call double @llvm.fmuladd.f64(double %27, double 1.000000e+05, double 5.000000e-01)
  %29 = fptosi double %28 to i32
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.png_info_struct, ptr %30, i32 0, i32 63
  store i32 %29, ptr %31, align 8, !tbaa !20
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.png_info_struct, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !21
  %35 = or i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !21
  %36 = load double, ptr %7, align 8, !tbaa !9
  %37 = fcmp oeq double %36, 0.000000e+00
  br i1 %37, label %38, label %40

38:                                               ; preds = %22
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @png_warning(ptr noundef %39, ptr noundef @.str.1)
  br label %40

40:                                               ; preds = %38, %22
  store i32 0, ptr %8, align 4
  br label %41

41:                                               ; preds = %40, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %42 = load i32, ptr %8, align 4
  switch i32 %42, label %44 [
    i32 0, label %43
    i32 1, label %43
  ]

43:                                               ; preds = %41, %41
  ret void

44:                                               ; preds = %41
  unreachable
}

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

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

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

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

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !16, i64 52}
!12 = !{!"png_info_struct", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !6, i64 24, !15, i64 32, !15, 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, !16, i64 52, !7, i64 56, !13, i64 60, !13, i64 64, !6, i64 72, !17, i64 80, !18, i64 88, !6, i64 96, !19, i64 104, !19, i64 114, !13, i64 124, !13, i64 128, !7, i64 132, !13, i64 136, !13, i64 140, !7, i64 144, !6, i64 152, !16, i64 160, !16, i64 164, !16, i64 168, !16, i64 172, !16, i64 176, !16, i64 180, !16, i64 184, !16, i64 188, !6, i64 192, !13, i64 200, !13, i64 204, !6, i64 208, !6, i64 216, !7, i64 224, !7, i64 225, !13, i64 228, !6, i64 232, !14, i64 240, !6, i64 248, !6, i64 256, !13, i64 264, !7, i64 268, !6, i64 272, !13, i64 280, !7, i64 284, !10, i64 288, !10, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !13, i64 328, !13, i64 332, !13, i64 336, !13, i64 340, !13, i64 344, !13, i64 348, !13, i64 352, !13, i64 356, !13, i64 360}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!"png_time_struct", !15, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!18 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!19 = !{!"png_color_16_struct", !7, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !15, i64 8}
!20 = !{!12, !13, i64 328}
!21 = !{!12, !13, i64 8}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @png_set_gAMA(ptr noundef %0, ptr noundef %1, double noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %20, label %6

6:                                                ; preds = %3
  %7 = fcmp ogt double %2, 0x40D4F8B51EB851EC
  br i1 %7, label %8, label %9

8:                                                ; preds = %6
  tail call void @png_warning(ptr noundef nonnull %0, ptr noundef nonnull @.str) #3
  br label %9

9:                                                ; preds = %6, %8
  %.0 = phi double [ 0x40D4F8B51EB851EC, %8 ], [ %2, %6 ]
  %10 = fptrunc double %.0 to float
  %11 = getelementptr inbounds i8, ptr %1, i64 52
  store float %10, ptr %11, align 4, !tbaa !5
  %12 = tail call double @llvm.fmuladd.f64(double %.0, double 1.000000e+05, double 5.000000e-01)
  %13 = fptosi double %12 to i32
  %14 = getelementptr inbounds i8, ptr %1, i64 328
  store i32 %13, ptr %14, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !19
  %17 = or i32 %16, 1
  store i32 %17, ptr %15, align 8, !tbaa !19
  %18 = fcmp oeq double %.0, 0.000000e+00
  br i1 %18, label %19, label %20

19:                                               ; preds = %9
  tail call void @png_warning(ptr noundef nonnull %0, ptr noundef nonnull @.str.1) #3
  br label %20

20:                                               ; preds = %9, %19, %3
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !13, i64 52}
!6 = !{!"png_info_struct", !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, !8, i64 56, !7, i64 60, !7, i64 64, !11, i64 72, !14, i64 80, !15, i64 88, !11, i64 96, !16, i64 104, !16, i64 114, !7, i64 124, !7, i64 128, !8, i64 132, !7, i64 136, !7, i64 140, !8, i64 144, !11, i64 152, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !13, i64 184, !13, i64 188, !11, i64 192, !7, i64 200, !7, i64 204, !11, i64 208, !11, i64 216, !8, i64 224, !8, i64 225, !7, i64 228, !11, i64 232, !10, i64 240, !11, i64 248, !11, i64 256, !7, i64 264, !8, i64 268, !11, i64 272, !7, i64 280, !8, i64 284, !17, i64 288, !17, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !7, i64 328, !7, i64 332, !7, i64 336, !7, i64 340, !7, i64 344, !7, i64 348, !7, i64 352, !7, i64 356, !7, i64 360}
!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 = !{!"float", !8, i64 0}
!14 = !{!"png_time_struct", !12, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6}
!15 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!16 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!17 = !{!"double", !8, i64 0}
!18 = !{!6, !7, i64 328}
!19 = !{!6, !7, i64 8}


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