; 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

declare double @Math_acos(double noundef) #1

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

27:                                               ; preds = %1
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 1
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = call double @Math_dsign(double noundef %30)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 0
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load double, ptr %4, align 8, !tbaa !9
  %36 = fdiv double %34, %35
  %37 = call double @Math_acos(double noundef %36)
  %38 = fmul double %31, %37
  store double %38, ptr %5, align 8, !tbaa !9
  br label %40

39:                                               ; preds = %1
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %39, %27
  %41 = load double, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #5
  ret double %41
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @Vec3d_getLength(ptr noundef) #2

declare double @Math_dsign(double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 "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 = !{!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

declare double @Math_acos(double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local double @Vec3d_getPolarTheta(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  %3 = load double, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load double, ptr %4, align 8, !tbaa !5
  call void @Vec3d_set(ptr noundef nonnull %2, double noundef %3, double noundef %5, double noundef 0.000000e+00)
  %6 = load double, ptr %2, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = call double @Vec3d_getLength(ptr noundef nonnull %2)
  %10 = fcmp ogt double %9, 1.000000e-08
  br i1 %10, label %11, label %20

11:                                               ; preds = %1
  %12 = fmul double %8, %8
  %13 = call double @llvm.fmuladd.f64(double %6, double %6, double %12)
  %sqrt = call double @llvm.sqrt.f64(double %13)
  %14 = load double, ptr %4, align 8, !tbaa !5
  %15 = call double @Math_dsign(double noundef %14) #5
  %16 = load double, ptr %0, align 8, !tbaa !5
  %17 = fdiv double %16, %sqrt
  %18 = call double @Math_acos(double noundef %17) #5
  %19 = fmul double %15, %18
  br label %20

20:                                               ; preds = %1, %11
  %.0 = phi double [ %19, %11 ], [ 0.000000e+00, %1 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  ret double %.0
}

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

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

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

declare double @Math_dsign(double noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!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,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass