; 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"

; 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_muldiv(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %50

14:                                               ; preds = %4
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %17, %14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %21, align 4, !tbaa !9
  store i32 1, ptr %5, align 4
  br label %51

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sitofp i32 %23 to double
  store double %24, ptr %10, align 8, !tbaa !11
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sitofp i32 %25 to double
  %27 = load double, ptr %10, align 8, !tbaa !11
  %28 = fmul double %27, %26
  store double %28, ptr %10, align 8, !tbaa !11
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sitofp i32 %29 to double
  %31 = load double, ptr %10, align 8, !tbaa !11
  %32 = fdiv double %31, %30
  store double %32, ptr %10, align 8, !tbaa !11
  %33 = load double, ptr %10, align 8, !tbaa !11
  %34 = fadd double %33, 5.000000e-01
  %35 = call double @llvm.floor.f64(double %34)
  store double %35, ptr %10, align 8, !tbaa !11
  %36 = load double, ptr %10, align 8, !tbaa !11
  %37 = fcmp ole double %36, 0x41DFFFFFFFC00000
  br i1 %37, label %38, label %45

38:                                               ; preds = %22
  %39 = load double, ptr %10, align 8, !tbaa !11
  %40 = fcmp oge double %39, 0xC1E0000000000000
  br i1 %40, label %41, label %45

41:                                               ; preds = %38
  %42 = load double, ptr %10, align 8, !tbaa !11
  %43 = fptosi double %42 to i32
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %43, ptr %44, align 4, !tbaa !9
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %46

45:                                               ; preds = %38, %22
  store i32 0, ptr %11, align 4
  br label %46

46:                                               ; preds = %45, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %47 = load i32, ptr %11, align 4
  switch i32 %47, label %53 [
    i32 0, label %48
    i32 1, label %51
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49, %4
  store i32 0, ptr %5, align 4
  br label %51

51:                                               ; preds = %50, %46, %20
  %52 = load i32, ptr %5, align 4
  ret i32 %52

53:                                               ; preds = %46
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(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, !12, i64 0}
!12 = !{!"double", !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local range(i32 0, 2) i32 @png_muldiv(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.thread, label %5

5:                                                ; preds = %4
  %6 = icmp eq i32 %1, 0
  %7 = icmp eq i32 %2, 0
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %.thread.sink.split, label %8

8:                                                ; preds = %5
  %9 = sitofp i32 %1 to double
  %10 = sitofp i32 %2 to double
  %11 = fmul double %9, %10
  %12 = sitofp i32 %3 to double
  %13 = fdiv double %11, %12
  %14 = fadd double %13, 5.000000e-01
  %15 = tail call double @llvm.floor.f64(double %14)
  %16 = fcmp ole double %15, 0x41DFFFFFFFC00000
  %17 = fcmp oge double %15, 0xC1E0000000000000
  %or.cond3 = and i1 %16, %17
  br i1 %or.cond3, label %18, label %.thread

18:                                               ; preds = %8
  %19 = fptosi double %15 to i32
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %5, %18
  %.sink = phi i32 [ %19, %18 ], [ 0, %5 ]
  store i32 %.sink, ptr %0, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %8, %4
  %.1 = phi i32 [ 0, %4 ], [ 0, %8 ], [ 1, %.thread.sink.split ]
  ret i32 %.1
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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