; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

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

@VelDecayLinSqrt.vel = external hidden global double, align 8

; Function Attrs: nounwind
declare double @sqrt(double noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local double @VelDecayLinSqrt(double noundef %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4) #2 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store double %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !5
  store double %2, ptr %9, align 8, !tbaa !5
  store double %3, ptr %10, align 8, !tbaa !5
  store double %4, ptr %11, align 8, !tbaa !5
  %12 = load double, ptr %7, align 8, !tbaa !5
  %13 = load double, ptr %11, align 8, !tbaa !5
  %14 = fsub double %12, %13
  %15 = load double, ptr %8, align 8, !tbaa !5
  %16 = fmul double %14, %15
  store double %16, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %17 = load double, ptr %9, align 8, !tbaa !5
  %18 = fcmp ole double %17, 0.000000e+00
  br i1 %18, label %25, label %19

19:                                               ; preds = %5
  %20 = load double, ptr %8, align 8, !tbaa !5
  %21 = fcmp ole double %20, 0.000000e+00
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %24 = fcmp ole double %23, 0.000000e+00
  br i1 %24, label %25, label %26

25:                                               ; preds = %22, %19, %5
  store double 0.000000e+00, ptr %6, align 8
  br label %63

26:                                               ; preds = %22
  %27 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %28 = load double, ptr %9, align 8, !tbaa !5
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = fdiv double %28, %29
  %31 = fcmp olt double %27, %30
  br i1 %31, label %32, label %40

32:                                               ; preds = %26
  %33 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %34 = load double, ptr %10, align 8, !tbaa !5
  %35 = fcmp oge double %33, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = load double, ptr %10, align 8, !tbaa !5
  store double %37, ptr %6, align 8
  br label %63

38:                                               ; preds = %32
  %39 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  store double %39, ptr %6, align 8
  br label %63

40:                                               ; preds = %26
  %41 = load double, ptr %9, align 8, !tbaa !5
  %42 = fmul double 2.000000e+00, %41
  %43 = load double, ptr %7, align 8, !tbaa !5
  %44 = load double, ptr %11, align 8, !tbaa !5
  %45 = fsub double %43, %44
  %46 = load double, ptr %9, align 8, !tbaa !5
  %47 = load double, ptr %9, align 8, !tbaa !5
  %48 = fmul double %46, %47
  %49 = load double, ptr %8, align 8, !tbaa !5
  %50 = fdiv double %48, %49
  %51 = load double, ptr %8, align 8, !tbaa !5
  %52 = fdiv double %50, %51
  %53 = fneg double %52
  %54 = call double @llvm.fmuladd.f64(double %42, double %45, double %53)
  %55 = call double @sqrt(double noundef %54) #3
  store double %55, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %56 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %57 = load double, ptr %10, align 8, !tbaa !5
  %58 = fcmp oge double %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %40
  %60 = load double, ptr %10, align 8, !tbaa !5
  store double %60, ptr %6, align 8
  br label %63

61:                                               ; preds = %40
  %62 = load double, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  store double %62, ptr %6, align 8
  br label %63

63:                                               ; preds = %61, %59, %38, %36, %25
  %64 = load double, ptr %6, align 8
  ret double %64
}

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


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

@VelDecayLinSqrt.vel = external hidden local_unnamed_addr global double, align 8

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write) uwtable
define dso_local double @VelDecayLinSqrt(double noundef %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #2 {
  %6 = fsub double %0, %4
  %7 = fmul double %6, %1
  store double %7, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %8 = fcmp ole double %2, 0.000000e+00
  %9 = fcmp ole double %1, 0.000000e+00
  %or.cond = or i1 %9, %8
  %10 = fcmp ole double %7, 0.000000e+00
  %or.cond3 = or i1 %or.cond, %10
  br i1 %or.cond3, label %23, label %11

11:                                               ; preds = %5
  %12 = fdiv double %2, %1
  %13 = fcmp olt double %7, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  %.inv28 = fcmp oge double %7, %3
  %. = select i1 %.inv28, double %3, double %7
  br label %23

15:                                               ; preds = %11
  %16 = fmul double %2, 2.000000e+00
  %17 = fneg double %2
  %18 = fmul double %17, %2
  %19 = fdiv double %18, %1
  %20 = fdiv double %19, %1
  %21 = tail call double @llvm.fmuladd.f64(double %16, double %6, double %20)
  %22 = tail call double @sqrt(double noundef %21) #3
  store double %22, ptr @VelDecayLinSqrt.vel, align 8, !tbaa !5
  %.inv = fcmp oge double %22, %3
  %.27 = select i1 %.inv, double %3, double %22
  br label %23

23:                                               ; preds = %15, %14, %5
  %.0 = phi double [ 0.000000e+00, %5 ], [ %., %14 ], [ %.27, %15 ]
  ret double %.0
}

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


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