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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @Vec3d_normalizeSelf(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @Vec3d_innerProduct(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @Vec3d_orthonormalVec(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca [3 x double], align 16
  %7 = alloca double, align 8
  %8 = alloca [3 x double], align 16
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %10, i64 0
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %13, i64 0
  %15 = load double, ptr %14, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds double, ptr %16, i64 1
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 1
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fmul double %18, %21
  %23 = call double @llvm.fmuladd.f64(double %12, double %15, double %22)
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i64 2
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %27, i64 2
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = call double @llvm.fmuladd.f64(double %26, double %29, double %23)
  store double %30, ptr %7, align 8, !tbaa !9
  %31 = load double, ptr %7, align 8, !tbaa !9
  %32 = fcmp oeq double %31, 0.000000e+00
  br i1 %32, label %33, label %35

33:                                               ; preds = %2
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Vec3d_set(ptr noundef %34, double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  store i32 1, ptr %9, align 4
  br label %57

35:                                               ; preds = %2
  %36 = getelementptr inbounds [3 x double], ptr %8, i64 0, i64 0
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load double, ptr %7, align 8, !tbaa !9
  %39 = call double @sqrt(double noundef %38) #4
  %40 = fdiv double 1.000000e+00, %39
  call void @Vec3d_constMul(ptr noundef %36, ptr noundef %37, double noundef %40)
  %41 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  call void @Vec3d_set(ptr noundef %41, double noundef 0.000000e+00, double noundef 0.000000e+00, double noundef 1.000000e+00)
  %42 = getelementptr inbounds [3 x double], ptr %8, i64 0, i64 0
  %43 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  %44 = call double @Vec3d_innerProduct(ptr noundef %42, ptr noundef %43)
  store double %44, ptr %5, align 8, !tbaa !9
  %45 = load double, ptr %5, align 8, !tbaa !9
  %46 = load double, ptr %5, align 8, !tbaa !9
  %47 = fmul double %45, %46
  %48 = fcmp ogt double %47, 0x3FEFAE147AE147AE
  br i1 %48, label %49, label %51

49:                                               ; preds = %35
  %50 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  call void @Vec3d_set(ptr noundef %50, double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  br label %51

51:                                               ; preds = %49, %35
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds [3 x double], ptr %8, i64 0, i64 0
  %54 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 0
  call void @Vec3d_crossProduct(ptr noundef %52, ptr noundef %53, ptr noundef %54)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = call double @Vec3d_normalizeSelf(ptr noundef %55)
  store i32 0, ptr %9, align 4
  br label %57

57:                                               ; preds = %51, %33
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %58 = load i32, ptr %9, align 4
  switch i32 %58, label %60 [
    i32 0, label %59
    i32 1, label %59
  ]

59:                                               ; preds = %57, %57
  ret void

60:                                               ; preds = %57
  unreachable
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 void @Vec3d_set(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @Vec3d_normalizeSelf(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @Vec3d_innerProduct(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Vec3d_constMul(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Vec3d_orthonormalVec(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [3 x double], align 16
  %4 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fmul double %7, %7
  %9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
  %13 = fcmp oeq double %12, 0.000000e+00
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  tail call void @Vec3d_set(ptr noundef %0, double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  br label %23

15:                                               ; preds = %2
  %sqrt = tail call double @llvm.sqrt.f64(double %12)
  %16 = fdiv double 1.000000e+00, %sqrt
  call void @Vec3d_constMul(ptr noundef nonnull %4, ptr noundef nonnull %1, double noundef %16)
  call void @Vec3d_set(ptr noundef nonnull %3, double noundef 0.000000e+00, double noundef 0.000000e+00, double noundef 1.000000e+00)
  %17 = call double @Vec3d_innerProduct(ptr noundef nonnull %4, ptr noundef nonnull %3)
  %18 = fmul double %17, %17
  %19 = fcmp ogt double %18, 0x3FEFAE147AE147AE
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  call void @Vec3d_set(ptr noundef nonnull %3, double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  br label %21

21:                                               ; preds = %20, %15
  call void @Vec3d_crossProduct(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull %3)
  %22 = call double @Vec3d_normalizeSelf(ptr noundef %0)
  br label %23

23:                                               ; preds = %21, %14
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass