; LLVM IR from sgtlaugh/algovault :: code_library/digits_of_factorial.ll (Z19digits_of_factorialxx)

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

@_ZL17HALF_LOG_TWICE_PI = external hidden global x86_fp80, align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__._Z19digits_of_factorialxx = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z19digits_of_factorialxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca x86_fp80, align 16
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %5, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 1
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %12

10:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 19, ptr noundef @__PRETTY_FUNCTION__._Z19digits_of_factorialxx) #5
  unreachable

11:                                               ; No predecessors!
  br label %12

12:                                               ; preds = %11, %9
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %18, label %15

15:                                               ; preds = %12
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp eq i64 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %12
  store i64 1, ptr %3, align 8
  br label %40

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = sitofp i64 %20 to double
  %22 = fadd double %21, 5.000000e-01
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = call noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %23)
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = sitofp i64 %25 to double
  %27 = fneg double %26
  %28 = call double @llvm.fmuladd.f64(double %22, double %24, double %27)
  %29 = fpext double %28 to x86_fp80
  %30 = load x86_fp80, ptr @_ZL17HALF_LOG_TWICE_PI, align 16, !tbaa !9
  %31 = fadd x86_fp80 %29, %30
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = call noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %32)
  %34 = fpext double %33 to x86_fp80
  %35 = fdiv x86_fp80 %31, %34
  store x86_fp80 %35, ptr %6, align 16, !tbaa !9
  %36 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %37 = fsub x86_fp80 %36, 0xK3FDAAFEBFF0BCB24A800
  %38 = call noundef x86_fp80 @_ZSt4ceile(x86_fp80 noundef %37)
  %39 = fptosi x86_fp80 %38 to i64
  store i64 %39, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  br label %40

40:                                               ; preds = %19, %18
  %41 = load i64, ptr %3, align 8
  ret i64 %41
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt4ceile(x86_fp80 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 = { mustprogress 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 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long 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"

@_ZL17HALF_LOG_TWICE_PI = external hidden local_unnamed_addr global x86_fp80, align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__._Z19digits_of_factorialxx = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z19digits_of_factorialxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, 1
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, i32 noundef 19, ptr noundef nonnull @__PRETTY_FUNCTION__._Z19digits_of_factorialxx) #4
  unreachable

5:                                                ; preds = %2
  %or.cond = icmp ult i64 %0, 2
  br i1 %or.cond, label %21, label %6

6:                                                ; preds = %5
  %7 = sitofp i64 %0 to double
  %8 = fadd double %7, 5.000000e-01
  %9 = tail call noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %10 = fneg double %7
  %11 = tail call double @llvm.fmuladd.f64(double %8, double %9, double %10)
  %12 = fpext double %11 to x86_fp80
  %13 = load x86_fp80, ptr @_ZL17HALF_LOG_TWICE_PI, align 16, !tbaa !5
  %14 = fadd x86_fp80 %13, %12
  %15 = tail call noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %1)
  %16 = fpext double %15 to x86_fp80
  %17 = fdiv x86_fp80 %14, %16
  %18 = fadd x86_fp80 %17, 0xKBFDAAFEBFF0BCB24A800
  %19 = tail call noundef x86_fp80 @_ZSt4ceile(x86_fp80 noundef %18)
  %20 = fptosi x86_fp80 %19 to i64
  br label %21

21:                                               ; preds = %5, %6
  %.0 = phi i64 [ %20, %6 ], [ 1, %5 ]
  ret i64 %.0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3logIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt4ceile(x86_fp80 noundef) local_unnamed_addr #2

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 = { noreturn 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 #2 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { noreturn 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 = !{!"long double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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