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

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

declare void @Mat3d_fromEulerAngles(ptr noundef, ptr noundef) #1

declare double @Mat3d_getAxisAngleSelf(ptr noundef, ptr noundef) #1

declare void @Vec3d_addSelf(ptr noundef, ptr noundef) #1

declare void @Mat3d_toEulerAngles(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Math_weightedMeanRotationAxes(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca [3 x double], align 16
  %11 = alloca i64, align 8
  %12 = alloca [3 x [3 x double]], align 16
  %13 = alloca [3 x double], align 16
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca [3 x [3 x double]], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Vec3d_setZero(ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  %20 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  call void @Vec3d_setZero(ptr noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %57, %4
  %22 = load i64, ptr %11, align 8, !tbaa !13
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %60

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 72, ptr %12) #3
  %28 = getelementptr inbounds [3 x [3 x double]], ptr %12, i64 0, i64 0
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !13
  %31 = getelementptr inbounds [3 x double], ptr %29, i64 %30
  %32 = getelementptr inbounds [3 x double], ptr %31, i64 0, i64 0
  call void @Mat3d_fromEulerAngles(ptr noundef %28, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %33 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %34 = getelementptr inbounds [3 x [3 x double]], ptr %12, i64 0, i64 0
  %35 = call double @Mat3d_getAxisAngleSelf(ptr noundef %33, ptr noundef %34)
  store double %35, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %36 = load double, ptr %14, align 8, !tbaa !11
  %37 = fdiv double %36, 2.000000e+00
  store double %37, ptr %15, align 8, !tbaa !11
  %38 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %39 = load double, ptr %15, align 8, !tbaa !11
  call void @Vec3d_constMulSelf(ptr noundef %38, double noundef %39)
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %54

42:                                               ; preds = %27
  %43 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %11, align 8, !tbaa !13
  %46 = getelementptr inbounds double, ptr %44, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  call void @Vec3d_constMulSelf(ptr noundef %43, double noundef %47)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %11, align 8, !tbaa !13
  %50 = getelementptr inbounds double, ptr %48, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = load double, ptr %9, align 8, !tbaa !11
  %53 = fadd double %52, %51
  store double %53, ptr %9, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %42, %27
  %55 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  %56 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  call void @Vec3d_addSelf(ptr noundef %55, ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %12) #3
  br label %57

57:                                               ; preds = %54
  %58 = load i64, ptr %11, align 8, !tbaa !13
  %59 = add i64 %58, 1
  store i64 %59, ptr %11, align 8, !tbaa !13
  br label %21, !llvm.loop !15

60:                                               ; preds = %26
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %67

63:                                               ; preds = %60
  %64 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  %65 = load double, ptr %9, align 8, !tbaa !11
  %66 = fdiv double 1.000000e+00, %65
  call void @Vec3d_constMulSelf(ptr noundef %64, double noundef %66)
  br label %72

67:                                               ; preds = %60
  %68 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = uitofp i32 %69 to double
  %71 = fdiv double 1.000000e+00, %70
  call void @Vec3d_constMulSelf(ptr noundef %68, double noundef %71)
  br label %72

72:                                               ; preds = %67, %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %73 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  %74 = call double @Vec3d_normalizeSelf(ptr noundef %73)
  store double %74, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %75 = load double, ptr %16, align 8, !tbaa !11
  %76 = fmul double 2.000000e+00, %75
  store double %76, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 72, ptr %18) #3
  %77 = getelementptr inbounds [3 x [3 x double]], ptr %18, i64 0, i64 0
  %78 = getelementptr inbounds [3 x double], ptr %10, i64 0, i64 0
  %79 = load double, ptr %17, align 8, !tbaa !11
  call void @Mat3d_fromAxisAngle(ptr noundef %77, ptr noundef %78, double noundef %79)
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds [3 x [3 x double]], ptr %18, i64 0, i64 0
  call void @Mat3d_toEulerAngles(ptr noundef %80, ptr noundef %81)
  call void @llvm.lifetime.end.p0(i64 72, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare void @Vec3d_constMulSelf(ptr noundef, double noundef) #1

declare double @Vec3d_normalizeSelf(ptr noundef) #1

declare void @Mat3d_fromAxisAngle(ptr noundef, ptr noundef, 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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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 void @Vec3d_setZero(ptr noundef) local_unnamed_addr #1

declare void @Mat3d_fromEulerAngles(ptr noundef, ptr noundef) local_unnamed_addr #1

declare double @Mat3d_getAxisAngleSelf(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @Vec3d_addSelf(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @Mat3d_toEulerAngles(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Math_weightedMeanRotationAxes(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [3 x double], align 16
  %6 = alloca [3 x [3 x double]], align 16
  %7 = alloca [3 x double], align 16
  %8 = alloca [3 x [3 x double]], align 16
  tail call void @Vec3d_setZero(ptr noundef %0) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @Vec3d_setZero(ptr noundef nonnull %5) #3
  %9 = zext i32 %3 to i64
  %.not24 = icmp eq i32 %3, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %.not21 = icmp eq ptr %2, null
  br i1 %.not21, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.01922.us = phi i64 [ %13, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %6) #3
  %10 = getelementptr inbounds [3 x double], ptr %1, i64 %.01922.us
  call void @Mat3d_fromEulerAngles(ptr noundef nonnull %6, ptr noundef %10) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  %11 = call double @Mat3d_getAxisAngleSelf(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %12 = fmul double %11, 5.000000e-01
  call void @Vec3d_constMulSelf(ptr noundef nonnull %7, double noundef %12) #3
  call void @Vec3d_addSelf(ptr noundef nonnull %5, ptr noundef nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %6) #3
  %13 = add nuw nsw i64 %.01922.us, 1
  %exitcond26.not = icmp eq i64 %13, %9
  br i1 %exitcond26.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph.split.us, %4
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %22, label %._crit_edge.thread

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.023 = phi double [ %20, %.lr.ph.split ], [ 0.000000e+00, %.lr.ph ]
  %.01922 = phi i64 [ %21, %.lr.ph.split ], [ 0, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %6) #3
  %14 = getelementptr inbounds [3 x double], ptr %1, i64 %.01922
  call void @Mat3d_fromEulerAngles(ptr noundef nonnull %6, ptr noundef %14) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  %15 = call double @Mat3d_getAxisAngleSelf(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %16 = fmul double %15, 5.000000e-01
  call void @Vec3d_constMulSelf(ptr noundef nonnull %7, double noundef %16) #3
  %17 = getelementptr inbounds double, ptr %2, i64 %.01922
  %18 = load double, ptr %17, align 8, !tbaa !7
  call void @Vec3d_constMulSelf(ptr noundef nonnull %7, double noundef %18) #3
  %19 = load double, ptr %17, align 8, !tbaa !7
  %20 = fadd double %.023, %19
  call void @Vec3d_addSelf(ptr noundef nonnull %5, ptr noundef nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %6) #3
  %21 = add nuw nsw i64 %.01922, 1
  %exitcond.not = icmp eq i64 %21, %9
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph.split, !llvm.loop !5

22:                                               ; preds = %._crit_edge
  %23 = uitofp i32 %3 to double
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph.split, %._crit_edge, %22
  %.sink30 = phi double [ %23, %22 ], [ 0.000000e+00, %._crit_edge ], [ %20, %.lr.ph.split ]
  %24 = fdiv double 1.000000e+00, %.sink30
  call void @Vec3d_constMulSelf(ptr noundef nonnull %5, double noundef %24) #3
  %25 = call double @Vec3d_normalizeSelf(ptr noundef nonnull %5) #3
  %26 = fmul double %25, 2.000000e+00
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %8) #3
  call void @Mat3d_fromAxisAngle(ptr noundef nonnull %8, ptr noundef nonnull %5, double noundef %26) #3
  call void @Mat3d_toEulerAngles(ptr noundef %0, ptr noundef nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  ret void
}

declare void @Vec3d_constMulSelf(ptr noundef, double noundef) local_unnamed_addr #1

declare double @Vec3d_normalizeSelf(ptr noundef) local_unnamed_addr #1

declare void @Mat3d_fromAxisAngle(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #1

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass