; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_Vec3d)

; 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 double @Vec3d_getLength(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Vec3d_setZero(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @Vec3d_constSaturateSelf(ptr noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %8 = load double, ptr %5, align 8, !tbaa !9
  %9 = fcmp ole double %8, 0.000000e+00
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @Vec3d_setZero(ptr noundef %11)
  store double 0.000000e+00, ptr %3, align 8
  br label %39

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call double @Vec3d_getLength(ptr noundef %13)
  store double %14, ptr %7, align 8, !tbaa !9
  %15 = load double, ptr %7, align 8, !tbaa !9
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = fcmp ogt double %15, %16
  br i1 %17, label %18, label %37

18:                                               ; preds = %12
  %19 = load double, ptr %5, align 8, !tbaa !9
  %20 = load double, ptr %7, align 8, !tbaa !9
  %21 = fdiv double %19, %20
  store double %21, ptr %6, align 8, !tbaa !9
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds double, ptr %23, i64 0
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fmul double %25, %22
  store double %26, ptr %24, align 8, !tbaa !9
  %27 = load double, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 1
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = fmul double %30, %27
  store double %31, ptr %29, align 8, !tbaa !9
  %32 = load double, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds double, ptr %33, i64 2
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fmul double %35, %32
  store double %36, ptr %34, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %18, %12
  %38 = load double, ptr %6, align 8, !tbaa !9
  store double %38, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %39

39:                                               ; preds = %37, %10
  %40 = load double, ptr %3, align 8
  ret double %40
}

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 }

!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 = !{!"any pointer", !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 double @Vec3d_getLength(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @Vec3d_setZero(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @Vec3d_constSaturateSelf(ptr noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fcmp ugt double %1, 0.000000e+00
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @Vec3d_setZero(ptr noundef %0)
  br label %17

5:                                                ; preds = %2
  %6 = tail call double @Vec3d_getLength(ptr noundef %0)
  %7 = fcmp ogt double %6, %1
  br i1 %7, label %8, label %17

8:                                                ; preds = %5
  %9 = fdiv double %1, %6
  %10 = load <2 x double>, ptr %0, align 8, !tbaa !5
  %11 = insertelement <2 x double> poison, double %9, i64 0
  %12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
  %13 = fmul <2 x double> %12, %10
  store <2 x double> %13, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fmul double %9, %15
  store double %16, ptr %14, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %5, %8, %4
  %.0 = phi double [ 0.000000e+00, %4 ], [ %9, %8 ], [ 1.000000e+00, %5 ]
  ret double %.0
}

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

!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,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass