; LLVM IR from microsoft/LightAIMD :: src (special_func)

; 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
declare dso_local i64 @double_factorial(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @approximate_double_factorial(i64 noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca i64, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca { double, double }, align 8
  %7 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp slt i64 %8, 10
  br i1 %9, label %10, label %14

10:                                               ; preds = %1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = call i64 @double_factorial(i64 noundef %11)
  %13 = sitofp i64 %12 to double
  store double %13, ptr %2, align 8
  br label %49

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = sitofp i64 %15 to double
  %17 = fdiv double %16, 2.000000e+00
  store double %17, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = load double, ptr %4, align 8, !tbaa !9
  %19 = fadd double %18, 1.000000e+00
  %20 = call { double, double } @ln_gamma_f64(double noundef %19)
  %21 = extractvalue { double, double } %20, 0
  %22 = extractvalue { double, double } %20, 1
  %23 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %24 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  store double %21, ptr %23, align 8
  store double %22, ptr %24, align 8
  %25 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %26 = load double, ptr %25, align 8
  %27 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  %28 = load double, ptr %27, align 8
  %29 = call { double, double } @cexp(double noundef %26, double noundef %28) #3
  %30 = extractvalue { double, double } %29, 0
  %31 = extractvalue { double, double } %29, 1
  store double %30, ptr %5, align 8, !tbaa !9
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = srem i64 %32, 2
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %14
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = load double, ptr %4, align 8, !tbaa !9
  %38 = call double @pow(double noundef 2.000000e+00, double noundef %37) #3
  %39 = fmul double %36, %38
  store double %39, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %48

40:                                               ; preds = %14
  %41 = load double, ptr %5, align 8, !tbaa !9
  %42 = call double @sqrt(double noundef 0x400921FB54442D18) #3
  %43 = fdiv double %41, %42
  %44 = load double, ptr %4, align 8, !tbaa !9
  %45 = fadd double %44, 5.000000e-01
  %46 = call double @pow(double noundef 2.000000e+00, double noundef %45) #3
  %47 = fmul double %43, %46
  store double %47, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %48

48:                                               ; preds = %40, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %49

49:                                               ; preds = %48, %10
  %50 = load double, ptr %2, align 8
  ret double %50
}

; Function Attrs: nounwind
declare { double, double } @cexp(double noundef, double noundef) #2

; Function Attrs: nounwind uwtable
declare hidden { double, double } @ln_gamma_f64(double noundef) #1

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"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: nounwind uwtable
declare dso_local i64 @double_factorial(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @approximate_double_factorial(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 10
  br i1 %2, label %3, label %6

3:                                                ; preds = %1
  %4 = tail call i64 @double_factorial(i64 noundef %0)
  %5 = sitofp i64 %4 to double
  br label %23

6:                                                ; preds = %1
  %7 = uitofp nneg i64 %0 to double
  %8 = fmul double %7, 5.000000e-01
  %9 = fadd double %8, 1.000000e+00
  %10 = tail call { double, double } @ln_gamma_f64(double noundef %9)
  %11 = extractvalue { double, double } %10, 0
  %12 = extractvalue { double, double } %10, 1
  %13 = tail call { double, double } @cexp(double noundef %11, double noundef %12) #2
  %14 = extractvalue { double, double } %13, 0
  %15 = and i64 %0, 1
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %6
  %exp211 = tail call double @exp2(double %8) #2
  %18 = fmul double %14, %exp211
  br label %23

19:                                               ; preds = %6
  %20 = fdiv double %14, 0x3FFC5BF891B4EF6A
  %21 = fadd double %8, 5.000000e-01
  %exp2 = tail call double @exp2(double %21) #2
  %22 = fmul double %20, %exp2
  br label %23

23:                                               ; preds = %17, %19, %3
  %.1 = phi double [ %5, %3 ], [ %18, %17 ], [ %22, %19 ]
  ret double %.1
}

; Function Attrs: nounwind
declare { double, double } @cexp(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden { double, double } @ln_gamma_f64(double noundef) local_unnamed_addr #0

declare double @exp2(double) local_unnamed_addr

attributes #0 = { 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 = { 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 = { 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)"}


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