; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @Math_weightedMeanEulerAngles(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %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 double, align 8
  %11 = alloca double, align 8
  %12 = alloca [3 x double], align 16
  %13 = alloca [3 x double], align 16
  %14 = alloca [3 x double], align 16
  %15 = alloca [3 x [3 x double]], align 16
  %16 = alloca [3 x [3 x double]], align 16
  %17 = alloca [3 x [3 x double]], align 16
  %18 = alloca i8, align 1
  %19 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = uitofp i32 %20 to double
  %22 = fdiv double 1.000000e+00, %21
  store double %22, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0x4004F1A6C638D03F, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %18) #3
  store i8 1, ptr %18, align 1, !tbaa !13
  %23 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  call void @Vec3d_setZero(ptr noundef %23)
  %24 = getelementptr inbounds [3 x [3 x double]], ptr %15, i64 0, i64 0
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Mat3d_fromEulerAngles(ptr noundef %24, ptr noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %71, %4
  %27 = load i32, ptr %19, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp ult i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %74

31:                                               ; preds = %26
  %32 = getelementptr inbounds [3 x [3 x double]], ptr %16, i64 0, i64 0
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %19, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [3 x double], ptr %33, i64 %35
  %37 = getelementptr inbounds [3 x double], ptr %36, i64 0, i64 0
  call void @Mat3d_fromEulerAngles(ptr noundef %32, ptr noundef %37)
  %38 = getelementptr inbounds [3 x [3 x double]], ptr %17, i64 0, i64 0
  %39 = getelementptr inbounds [3 x [3 x double]], ptr %16, i64 0, i64 0
  %40 = getelementptr inbounds [3 x [3 x double]], ptr %15, i64 0, i64 0
  call void @Mat3d_mulTranspose(ptr noundef %38, ptr noundef %39, ptr noundef %40)
  %41 = getelementptr inbounds [3 x double], ptr %12, i64 0, i64 0
  %42 = getelementptr inbounds [3 x [3 x double]], ptr %17, i64 0, i64 0
  %43 = call double @Mat3d_getAxisAngleSelf(ptr noundef %41, ptr noundef %42)
  store double %43, ptr %11, align 8, !tbaa !11
  %44 = load double, ptr %11, align 8, !tbaa !11
  %45 = fcmp ogt double %44, 0x4004F1A6C638D03F
  br i1 %45, label %46, label %47

46:                                               ; preds = %31
  store i8 0, ptr %18, align 1, !tbaa !13
  br label %47

47:                                               ; preds = %46, %31
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %47
  %51 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %52 = getelementptr inbounds [3 x double], ptr %12, i64 0, i64 0
  %53 = load double, ptr %11, align 8, !tbaa !11
  %54 = load double, ptr %9, align 8, !tbaa !11
  %55 = fmul double %53, %54
  call void @Vec3d_constMul(ptr noundef %51, ptr noundef %52, double noundef %55)
  br label %68

56:                                               ; preds = %47
  %57 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  %58 = getelementptr inbounds [3 x double], ptr %12, i64 0, i64 0
  %59 = load double, ptr %11, align 8, !tbaa !11
  %60 = load double, ptr %9, align 8, !tbaa !11
  %61 = fmul double %59, %60
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i32, ptr %19, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  %67 = fmul double %61, %66
  call void @Vec3d_constMul(ptr noundef %57, ptr noundef %58, double noundef %67)
  br label %68

68:                                               ; preds = %56, %50
  %69 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  %70 = getelementptr inbounds [3 x double], ptr %13, i64 0, i64 0
  call void @Vec3d_addSelf(ptr noundef %69, ptr noundef %70)
  br label %71

71:                                               ; preds = %68
  %72 = load i32, ptr %19, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %19, align 4, !tbaa !9
  br label %26, !llvm.loop !15

74:                                               ; preds = %30
  %75 = getelementptr inbounds [3 x [3 x double]], ptr %15, i64 0, i64 0
  %76 = getelementptr inbounds [3 x double], ptr %14, i64 0, i64 0
  call void @Mat3d_rotateOmegaSelf(ptr noundef %75, ptr noundef %76, i1 noundef zeroext false)
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds [3 x [3 x double]], ptr %15, i64 0, i64 0
  call void @Mat3d_toEulerAngles(ptr noundef %77, ptr noundef %78)
  %79 = load i8, ptr %18, align 1, !tbaa !13, !range !17, !noundef !18
  %80 = trunc i8 %79 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i1 %80
}

declare void @Vec3d_setZero(ptr noundef) #2

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

declare void @Mat3d_mulTranspose(ptr noundef, ptr noundef, ptr noundef) #2

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

declare void @Vec3d_constMul(ptr noundef, ptr noundef, double noundef) #2

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

declare void @Mat3d_rotateOmegaSelf(ptr noundef, ptr noundef, i1 noundef zeroext) #2

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

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 = { "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 = !{!"_Bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}


; 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
define dso_local zeroext i1 @Math_weightedMeanEulerAngles(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [3 x double], align 16
  %6 = alloca [3 x double], align 16
  %7 = alloca [3 x double], align 16
  %8 = alloca [3 x [3 x double]], align 16
  %9 = alloca [3 x [3 x double]], align 16
  %10 = alloca [3 x [3 x double]], align 16
  %11 = uitofp i32 %3 to double
  %12 = fdiv double 1.000000e+00, %11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %10) #3
  call void @Vec3d_setZero(ptr noundef nonnull %7) #3
  call void @Mat3d_fromEulerAngles(ptr noundef nonnull %8, ptr noundef %0) #3
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %13 = icmp eq ptr %2, null
  %wide.trip.count23 = zext i32 %3 to i64
  br i1 %13, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %.01618.us = phi i1 [ %.1.us, %.lr.ph.split.us ], [ true, %.lr.ph ]
  %14 = getelementptr inbounds [3 x double], ptr %1, i64 %indvars.iv21
  call void @Mat3d_fromEulerAngles(ptr noundef nonnull %9, ptr noundef %14) #3
  call void @Mat3d_mulTranspose(ptr noundef nonnull %10, ptr noundef nonnull %9, ptr noundef nonnull %8) #3
  %15 = call double @Mat3d_getAxisAngleSelf(ptr noundef nonnull %5, ptr noundef nonnull %10) #3
  %16 = fcmp ule double %15, 0x4004F1A6C638D03F
  %.1.us = select i1 %16, i1 %.01618.us, i1 false
  %17 = fmul double %12, %15
  call void @Vec3d_constMul(ptr noundef nonnull %6, ptr noundef nonnull %5, double noundef %17) #3
  call void @Vec3d_addSelf(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond24.not = icmp eq i64 %indvars.iv.next22, %wide.trip.count23
  br i1 %exitcond24.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %4
  %.016.lcssa = phi i1 [ true, %4 ], [ %.1.us, %.lr.ph.split.us ], [ %.1, %.lr.ph.split ]
  call void @Mat3d_rotateOmegaSelf(ptr noundef nonnull %8, ptr noundef nonnull %7, i1 noundef zeroext false) #3
  call void @Mat3d_toEulerAngles(ptr noundef %0, ptr noundef nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  ret i1 %.016.lcssa

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.split ], [ 0, %.lr.ph ]
  %.01618 = phi i1 [ %.1, %.lr.ph.split ], [ true, %.lr.ph ]
  %18 = getelementptr inbounds [3 x double], ptr %1, i64 %indvars.iv
  call void @Mat3d_fromEulerAngles(ptr noundef nonnull %9, ptr noundef %18) #3
  call void @Mat3d_mulTranspose(ptr noundef nonnull %10, ptr noundef nonnull %9, ptr noundef nonnull %8) #3
  %19 = call double @Mat3d_getAxisAngleSelf(ptr noundef nonnull %5, ptr noundef nonnull %10) #3
  %20 = fcmp ule double %19, 0x4004F1A6C638D03F
  %.1 = select i1 %20, i1 %.01618, i1 false
  %21 = fmul double %12, %19
  %22 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !7
  %24 = fmul double %21, %23
  call void @Vec3d_constMul(ptr noundef nonnull %6, ptr noundef nonnull %5, double noundef %24) #3
  call void @Vec3d_addSelf(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count23
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !5
}

declare void @Vec3d_setZero(ptr noundef) local_unnamed_addr #2

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

declare void @Mat3d_mulTranspose(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @Vec3d_constMul(ptr noundef, ptr noundef, double noundef) local_unnamed_addr #2

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

declare void @Mat3d_rotateOmegaSelf(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

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

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 = { "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: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass