; LLVM IR from sp-nitech/SPTK :: src/utils/misc_utils.ll (ZN4sptk33ComputeProbabilityOfTDistributionEdiPd)

; 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 @sqrt(double noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4sptk33ComputeProbabilityOfTDistributionEdiPd(double noundef %0, i32 noundef %1, ptr noundef %2) #3 {
  %4 = alloca i1, align 1
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  store double %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !11
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp sle i32 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !11
  %18 = icmp eq ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %3
  store i1 false, ptr %4, align 1
  br label %92

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sitofp i32 %21 to double
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sitofp i32 %23 to double
  %25 = load double, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %5, align 8, !tbaa !5
  %27 = call double @llvm.fmuladd.f64(double %25, double %26, double %24)
  %28 = fdiv double %22, %27
  store double %28, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = fcmp olt double %29, 0.000000e+00
  br i1 %30, label %31, label %36

31:                                               ; preds = %20
  %32 = load double, ptr %8, align 8, !tbaa !5
  %33 = fsub double 1.000000e+00, %32
  %34 = call double @sqrt(double noundef %33) #5
  %35 = fneg double %34
  br label %40

36:                                               ; preds = %20
  %37 = load double, ptr %8, align 8, !tbaa !5
  %38 = fsub double 1.000000e+00, %37
  %39 = call double @sqrt(double noundef %38) #5
  br label %40

40:                                               ; preds = %36, %31
  %41 = phi double [ %35, %31 ], [ %39, %36 ]
  store double %41, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %42 = load double, ptr %9, align 8, !tbaa !5
  store double %42, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = srem i32 %43, 2
  %45 = add nsw i32 %44, 2
  store i32 %45, ptr %12, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %65, %40
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %68

51:                                               ; preds = %46
  %52 = load double, ptr %11, align 8, !tbaa !5
  %53 = load double, ptr %10, align 8, !tbaa !5
  %54 = fadd double %53, %52
  store double %54, ptr %10, align 8, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = sub nsw i32 %55, 1
  %57 = sitofp i32 %56 to double
  %58 = load double, ptr %8, align 8, !tbaa !5
  %59 = fmul double %57, %58
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = sitofp i32 %60 to double
  %62 = fdiv double %59, %61
  %63 = load double, ptr %11, align 8, !tbaa !5
  %64 = fmul double %63, %62
  store double %64, ptr %11, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %51
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = add nsw i32 %66, 2
  store i32 %67, ptr %12, align 4, !tbaa !9
  br label %46, !llvm.loop !13

68:                                               ; preds = %50
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = srem i32 %69, 2
  %71 = icmp eq i32 0, %70
  br i1 %71, label %72, label %77

72:                                               ; preds = %68
  %73 = load double, ptr %10, align 8, !tbaa !5
  %74 = fadd double 1.000000e+00, %73
  %75 = fdiv double %74, 2.000000e+00
  %76 = load ptr, ptr %7, align 8, !tbaa !11
  store double %75, ptr %76, align 8, !tbaa !5
  br label %91

77:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %78 = load double, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %79)
  %81 = fdiv double %78, %80
  %82 = call double @atan(double noundef %81) #5
  store double %82, ptr %13, align 8, !tbaa !5
  %83 = load double, ptr %10, align 8, !tbaa !5
  %84 = load double, ptr %8, align 8, !tbaa !5
  %85 = call double @sqrt(double noundef %84) #5
  %86 = load double, ptr %13, align 8, !tbaa !5
  %87 = call double @llvm.fmuladd.f64(double %83, double %85, double %86)
  %88 = fdiv double %87, 0x400921FB54442D18
  %89 = fadd double 5.000000e-01, %88
  %90 = load ptr, ptr %7, align 8, !tbaa !11
  store double %89, ptr %90, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %91

91:                                               ; preds = %77, %72
  store i1 true, ptr %4, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %92

92:                                               ; preds = %91, %19
  %93 = load i1, ptr %4, align 1
  ret i1 %93
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #4

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 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 = { 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 #5 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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 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 @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4sptk33ComputeProbabilityOfTDistributionEdiPd(double noundef %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %4 = icmp sgt i32 %1, 0
  %5 = icmp ne ptr %2, null
  %or.cond.not = and i1 %4, %5
  br i1 %or.cond.not, label %6, label %37

6:                                                ; preds = %3
  %7 = uitofp nneg i32 %1 to double
  %8 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %7)
  %9 = fdiv double %7, %8
  %10 = fsub double 1.000000e+00, %9
  %11 = tail call double @sqrt(double noundef %10) #5
  %12 = and i32 %1, 1
  %13 = or disjoint i32 %12, 2
  %.not37 = icmp ugt i32 %13, %1
  br i1 %.not37, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %14 = fcmp olt double %0, 0.000000e+00
  %15 = fneg double %11
  %16 = select i1 %14, double %15, double %11
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.032.lcssa = phi double [ 0.000000e+00, %6 ], [ %18, %.lr.ph ]
  %17 = icmp eq i32 %12, 0
  br i1 %17, label %26, label %29

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.03040 = phi i32 [ %25, %.lr.ph ], [ %13, %.lr.ph.preheader ]
  %.03139 = phi double [ %24, %.lr.ph ], [ %16, %.lr.ph.preheader ]
  %.03238 = phi double [ %18, %.lr.ph ], [ 0.000000e+00, %.lr.ph.preheader ]
  %18 = fadd double %.03238, %.03139
  %19 = add nsw i32 %.03040, -1
  %20 = sitofp i32 %19 to double
  %21 = fmul double %9, %20
  %22 = uitofp nneg i32 %.03040 to double
  %23 = fdiv double %21, %22
  %24 = fmul double %.03139, %23
  %25 = add nuw nsw i32 %.03040, 2
  %.not = icmp sgt i32 %25, %1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

26:                                               ; preds = %._crit_edge
  %27 = fadd double %.032.lcssa, 1.000000e+00
  %28 = fmul double %27, 5.000000e-01
  br label %36

29:                                               ; preds = %._crit_edge
  %30 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %1)
  %31 = fdiv double %0, %30
  %32 = tail call double @atan(double noundef %31) #5
  %sqrt = tail call double @llvm.sqrt.f64(double %9)
  %33 = tail call double @llvm.fmuladd.f64(double %.032.lcssa, double %sqrt, double %32)
  %34 = fdiv double %33, 0x400921FB54442D18
  %35 = fadd double %34, 5.000000e-01
  br label %36

36:                                               ; preds = %29, %26
  %storemerge = phi double [ %35, %29 ], [ %28, %26 ]
  store double %storemerge, ptr %2, align 8, !tbaa !7
  br label %37

37:                                               ; preds = %3, %36
  ret i1 %or.cond.not
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #3

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

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 = { 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 = { 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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


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