; LLVM IR from sbu-fsl/kernel-ml :: src/math (math)

; 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
define dso_local double @fast_sqrt_d(double noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i64, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load i64, ptr %2, align 8, !tbaa !9
  store i64 %5, ptr %4, align 8, !tbaa !9
  %6 = load i64, ptr %4, align 8, !tbaa !9
  %7 = ashr i64 %6, 1
  %8 = sub nsw i64 6910469410427058089, %7
  store i64 %8, ptr %4, align 8, !tbaa !9
  %9 = load double, ptr %4, align 8, !tbaa !5
  store double %9, ptr %3, align 8, !tbaa !5
  %10 = load double, ptr %3, align 8, !tbaa !5
  %11 = load double, ptr %2, align 8, !tbaa !5
  %12 = fmul double 5.000000e-01, %11
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = fmul double %12, %13
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = fneg double %14
  %17 = call double @llvm.fmuladd.f64(double %16, double %15, double 1.500000e+00)
  %18 = fmul double %10, %17
  store double %18, ptr %3, align 8, !tbaa !5
  %19 = load double, ptr %3, align 8, !tbaa !5
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = fmul double 5.000000e-01, %20
  %22 = load double, ptr %3, align 8, !tbaa !5
  %23 = fmul double %21, %22
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = fneg double %23
  %26 = call double @llvm.fmuladd.f64(double %25, double %24, double 1.500000e+00)
  %27 = fmul double %19, %26
  store double %27, ptr %3, align 8, !tbaa !5
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = load double, ptr %2, align 8, !tbaa !5
  %30 = fmul double 5.000000e-01, %29
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = fmul double %30, %31
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = fneg double %32
  %35 = call double @llvm.fmuladd.f64(double %34, double %33, double 1.500000e+00)
  %36 = fmul double %28, %35
  store double %36, ptr %3, align 8, !tbaa !5
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = load double, ptr %2, align 8, !tbaa !5
  %39 = fmul double 5.000000e-01, %38
  %40 = load double, ptr %3, align 8, !tbaa !5
  %41 = fmul double %39, %40
  %42 = load double, ptr %3, align 8, !tbaa !5
  %43 = fneg double %41
  %44 = call double @llvm.fmuladd.f64(double %43, double %42, double 1.500000e+00)
  %45 = fmul double %37, %44
  store double %45, ptr %3, align 8, !tbaa !5
  %46 = load double, ptr %3, align 8, !tbaa !5
  %47 = load double, ptr %2, align 8, !tbaa !5
  %48 = fmul double 5.000000e-01, %47
  %49 = load double, ptr %3, align 8, !tbaa !5
  %50 = fmul double %48, %49
  %51 = load double, ptr %3, align 8, !tbaa !5
  %52 = fneg double %50
  %53 = call double @llvm.fmuladd.f64(double %52, double %51, double 1.500000e+00)
  %54 = fmul double %46, %53
  store double %54, ptr %3, align 8, !tbaa !5
  %55 = load double, ptr %3, align 8, !tbaa !5
  %56 = load double, ptr %2, align 8, !tbaa !5
  %57 = fmul double %55, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %57
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local double @fast_sqrt_d(double noundef %0) local_unnamed_addr #0 {
  %2 = bitcast double %0 to i64
  %3 = ashr i64 %2, 1
  %4 = sub nsw i64 6910469410427058089, %3
  %5 = bitcast i64 %4 to double
  %6 = fmul double %0, -5.000000e-01
  %7 = fmul double %6, %5
  %8 = tail call double @llvm.fmuladd.f64(double %7, double %5, double 1.500000e+00)
  %9 = fmul double %8, %5
  %10 = fmul double %6, %9
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %9, double 1.500000e+00)
  %12 = fmul double %9, %11
  %13 = fmul double %6, %12
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double 1.500000e+00)
  %15 = fmul double %12, %14
  %16 = fmul double %6, %15
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %15, double 1.500000e+00)
  %18 = fmul double %15, %17
  %19 = fmul double %6, %18
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %18, double 1.500000e+00)
  %21 = fmul double %18, %20
  %22 = fmul double %21, %0
  ret double %22
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass