; LLVM IR from buresjan/optim_lbm :: nomad/ext/sgtelib/src/Surrogate_Utils.ll (ZN7SGTELIB22lower_incomplete_gammaEdd)

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind
declare double @exp(double noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN7SGTELIB22lower_incomplete_gammaEdd(double noundef %0, double noundef %1) #3 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  %9 = load double, ptr %4, align 8, !tbaa !5
  %10 = fcmp olt double %9, 1.000000e-13
  br i1 %10, label %14, label %11

11:                                               ; preds = %2
  %12 = load double, ptr %5, align 8, !tbaa !5
  %13 = fcmp olt double %12, 1.000000e-13
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store double 0.000000e+00, ptr %3, align 8
  br label %46

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = call double @log(double noundef %17) #4
  %19 = load double, ptr %5, align 8, !tbaa !5
  %20 = fadd double %19, 1.000000e+00
  %21 = call double @lgamma(double noundef %20) #4
  %22 = fneg double %21
  %23 = call double @llvm.fmuladd.f64(double %16, double %18, double %22)
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = fsub double %23, %24
  %26 = call double @exp(double noundef %25) #4
  store double %26, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 1.000000e+00, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 1.000000e+00, ptr %8, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %32, %15
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = fdiv double %29, 1.000000e+09
  %31 = fcmp ogt double %28, %30
  br i1 %31, label %32, label %42

32:                                               ; preds = %27
  %33 = load double, ptr %4, align 8, !tbaa !5
  %34 = load double, ptr %5, align 8, !tbaa !5
  %35 = fadd double %34, 1.000000e+00
  store double %35, ptr %5, align 8, !tbaa !5
  %36 = fdiv double %33, %35
  %37 = load double, ptr %7, align 8, !tbaa !5
  %38 = fmul double %37, %36
  store double %38, ptr %7, align 8, !tbaa !5
  %39 = load double, ptr %7, align 8, !tbaa !5
  %40 = load double, ptr %8, align 8, !tbaa !5
  %41 = fadd double %40, %39
  store double %41, ptr %8, align 8, !tbaa !5
  br label %27, !llvm.loop !9

42:                                               ; preds = %27
  %43 = load double, ptr %8, align 8, !tbaa !5
  %44 = load double, ptr %6, align 8, !tbaa !5
  %45 = fmul double %43, %44
  store double %45, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %46

46:                                               ; preds = %42, %14
  %47 = load double, ptr %3, align 8
  ret double %47
}

; Function Attrs: nounwind
declare double @log(double noundef) #2

; Function Attrs: nounwind
declare double @lgamma(double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind "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 = { mustprogress 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN7SGTELIB22lower_incomplete_gammaEdd(double noundef %0, double noundef %1) local_unnamed_addr #2 {
  %3 = fcmp olt double %0, 1.000000e-13
  %4 = fcmp olt double %1, 1.000000e-13
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %22, label %5

5:                                                ; preds = %2
  %6 = tail call double @log(double noundef %0) #4
  %7 = fadd double %1, 1.000000e+00
  %8 = tail call double @lgamma(double noundef %7) #4
  %9 = fneg double %8
  %10 = tail call double @llvm.fmuladd.f64(double %1, double %6, double %9)
  %11 = fsub double %10, %0
  %12 = tail call double @exp(double noundef %11) #4
  br label %13

13:                                               ; preds = %5, %13
  %.024 = phi double [ 1.000000e+00, %5 ], [ %17, %13 ]
  %.01723 = phi double [ 1.000000e+00, %5 ], [ %16, %13 ]
  %.01922 = phi double [ %1, %5 ], [ %14, %13 ]
  %14 = fadd double %.01922, 1.000000e+00
  %15 = fdiv double %0, %14
  %16 = fmul double %.01723, %15
  %17 = fadd double %.024, %16
  %18 = fdiv double %17, 1.000000e+09
  %19 = fcmp ogt double %16, %18
  br i1 %19, label %13, label %20, !llvm.loop !5

20:                                               ; preds = %13
  %21 = fmul double %12, %17
  br label %22

22:                                               ; preds = %2, %20
  %.018 = phi double [ %21, %20 ], [ 0.000000e+00, %2 ]
  ret double %.018
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare double @lgamma(double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress 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 #3 = { nounwind "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass