; LLVM IR from tivole/Numerary :: src/incgamma.ll (ZN8numerary8Numerary8incgammaERKdS2_S2_)

; 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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN8numerary8Numerary8incgammaERKdS2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fdiv double 1.000000e+00, %11
  store double %12, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %18, %3
  %14 = load double, ptr %7, align 8, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fcmp ogt double %14, %16
  br i1 %17, label %18, label %34

18:                                               ; preds = %13
  %19 = load double, ptr %8, align 8, !tbaa !9
  %20 = load double, ptr %7, align 8, !tbaa !9
  %21 = fadd double %19, %20
  store double %21, ptr %8, align 8, !tbaa !9
  %22 = load double, ptr %7, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = sitofp i32 %27 to double
  %29 = fadd double %26, %28
  %30 = fdiv double %24, %29
  %31 = fmul double %22, %30
  store double %31, ptr %7, align 8, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %9, align 4, !tbaa !11
  br label %13, !llvm.loop !13

34:                                               ; preds = %13
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = call double @pow(double noundef %36, double noundef %38) #3
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = fmul double -1.000000e+00, %41
  %43 = call double @exp(double noundef %42) #3
  %44 = fmul double %39, %43
  %45 = load double, ptr %8, align 8, !tbaa !9
  %46 = fmul double %44, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret double %46
}

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local noundef double @_ZN8numerary8Numerary8incgammaERKdS2_S2_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2) local_unnamed_addr #0 align 2 {
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = fdiv double 1.000000e+00, %4
  %6 = load double, ptr %2, align 8, !tbaa !5
  %7 = fcmp ogt double %5, %6
  %.pre = load double, ptr %1, align 8, !tbaa !5
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.017 = phi i32 [ %13, %.lr.ph ], [ 1, %3 ]
  %.01316 = phi double [ %8, %.lr.ph ], [ 0.000000e+00, %3 ]
  %.01415 = phi double [ %12, %.lr.ph ], [ %5, %3 ]
  %8 = fadd double %.01415, %.01316
  %9 = uitofp nneg i32 %.017 to double
  %10 = fadd double %4, %9
  %11 = fdiv double %.pre, %10
  %12 = fmul double %.01415, %11
  %13 = add nuw nsw i32 %.017, 1
  %14 = fcmp ogt double %12, %6
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.013.lcssa = phi double [ 0.000000e+00, %3 ], [ %8, %.lr.ph ]
  %15 = tail call double @pow(double noundef %.pre, double noundef %4) #2
  %16 = load double, ptr %1, align 8, !tbaa !5
  %17 = fneg double %16
  %18 = tail call double @exp(double noundef %17) #2
  %19 = fmul double %15, %18
  %20 = fmul double %.013.lcssa, %19
  ret double %20
}

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

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

attributes #0 = { mustprogress nofree nounwind memory(write, 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 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 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass