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

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

%struct._RcsJoint = type { ptr, double, double, double, double, double, double, double, i8, i32, i32, i32, i32, ptr, %struct.HTr, double, double, double, double, i32, ptr, ptr, ptr, ptr, ptr }
%struct.HTr = type { [3 x double], [3 x [3 x double]] }
%struct._MatNd = type { ptr, i32, i32, i32, i8 }

@stderr = external global ptr, align 8
@.str.27 = external hidden unnamed_addr constant [68 x i8], align 1
@RCS_GLOBAL_RLOG_CB = external global ptr, align 8
@.str.30 = external hidden unnamed_addr constant [35 x i8], align 1
@RcsLogLevel = external global i32, align 4
@.str.31 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.RcsJoint_computeSlaveJointVelocity = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden double @RcsJoint_calcCouplingPolynomialDerivative(double noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @RcsJoint_computeSlaveJointVelocity(ptr noundef %0, double noundef %1, double noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._RcsJoint, ptr %13, i32 0, i32 24
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %43

18:                                               ; preds = %3
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._RcsJoint, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  call void (i32, ptr, ptr, i32, ptr, ...) %23(i32 noundef 1, ptr noundef @.str.27, ptr noundef @__func__.RcsJoint_computeSlaveJointVelocity, i32 noundef 441, ptr noundef @.str.30, ptr noundef %26)
  br label %27

27:                                               ; preds = %22, %19
  %28 = load i32, ptr @RcsLogLevel, align 4, !tbaa !17
  %29 = icmp sle i32 1, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %27
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.31, ptr noundef @.str.27, ptr noundef @__func__.RcsJoint_computeSlaveJointVelocity, i32 noundef 441) #4
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._RcsJoint, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.30, ptr noundef %36) #4
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str.32) #4
  br label %40

40:                                               ; preds = %30, %27
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  store double 0.000000e+00, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %79

43:                                               ; preds = %3
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._RcsJoint, ptr %44, i32 0, i32 21
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %struct._MatNd, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %60

50:                                               ; preds = %43
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._RcsJoint, ptr %51, i32 0, i32 21
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = getelementptr inbounds %struct._MatNd, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = getelementptr inbounds double, ptr %55, i64 0
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = fmul double %57, %58
  store double %59, ptr %9, align 8, !tbaa !9
  br label %77

60:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %61 = load double, ptr %6, align 8, !tbaa !9
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._RcsJoint, ptr %62, i32 0, i32 3
  %64 = load double, ptr %63, align 8, !tbaa !22
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._RcsJoint, ptr %65, i32 0, i32 4
  %67 = load double, ptr %66, align 8, !tbaa !23
  %68 = call double @Math_clip(double noundef %61, double noundef %64, double noundef %67)
  store double %68, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %69 = load double, ptr %11, align 8, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._RcsJoint, ptr %70, i32 0, i32 21
  %72 = load ptr, ptr %71, align 8, !tbaa !18
  %73 = call double @RcsJoint_calcCouplingPolynomialDerivative(double noundef %69, ptr noundef %72)
  store double %73, ptr %12, align 8, !tbaa !9
  %74 = load double, ptr %12, align 8, !tbaa !9
  %75 = load double, ptr %7, align 8, !tbaa !9
  %76 = fmul double %74, %75
  store double %76, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %77

77:                                               ; preds = %60, %50
  %78 = load double, ptr %9, align 8, !tbaa !9
  store double %78, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %79

79:                                               ; preds = %77, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %80 = load double, ptr %4, align 8
  ret double %80
}

declare double @Math_clip(double noundef, double noundef, double noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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}
!11 = !{!12, !6, i64 264}
!12 = !{!"_RcsJoint", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !13, i64 64, !14, i64 68, !14, i64 72, !14, i64 76, !14, i64 80, !6, i64 88, !15, i64 96, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !14, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 24}
!16 = !{!12, !6, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{!12, !6, i64 240}
!19 = !{!20, !14, i64 16}
!20 = !{!"_MatNd", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !13, i64 20}
!21 = !{!20, !6, i64 0}
!22 = !{!12, !10, i64 24}
!23 = !{!12, !10, i64 32}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.27 = external hidden unnamed_addr constant [68 x i8], align 1
@RCS_GLOBAL_RLOG_CB = external local_unnamed_addr global ptr, align 8
@.str.30 = external hidden unnamed_addr constant [35 x i8], align 1
@RcsLogLevel = external local_unnamed_addr global i32, align 4
@.str.31 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.RcsJoint_computeSlaveJointVelocity = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local double @RcsJoint_computeSlaveJointVelocity(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 264
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %22

7:                                                ; preds = %3
  %8 = load ptr, ptr @RCS_GLOBAL_RLOG_CB, align 8, !tbaa !14
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %11, label %9

9:                                                ; preds = %7
  %10 = load ptr, ptr %0, align 8, !tbaa !15
  tail call void (i32, ptr, ptr, i32, ptr, ...) %8(i32 noundef 1, ptr noundef nonnull @.str.27, ptr noundef nonnull @__func__.RcsJoint_computeSlaveJointVelocity, i32 noundef 441, ptr noundef nonnull @.str.30, ptr noundef %10) #3
  br label %11

11:                                               ; preds = %9, %7
  %12 = load i32, ptr @RcsLogLevel, align 4, !tbaa !16
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %40

14:                                               ; preds = %11
  %15 = load ptr, ptr @stderr, align 8, !tbaa !14
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.31, ptr noundef nonnull @.str.27, ptr noundef nonnull @__func__.RcsJoint_computeSlaveJointVelocity, i32 noundef 441) #4
  %17 = load ptr, ptr @stderr, align 8, !tbaa !14
  %18 = load ptr, ptr %0, align 8, !tbaa !15
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.30, ptr noundef %18) #4
  %20 = load ptr, ptr @stderr, align 8, !tbaa !14
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.32) #4
  br label %40

22:                                               ; preds = %3
  %23 = getelementptr inbounds i8, ptr %0, i64 240
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %31

28:                                               ; preds = %22
  %29 = load ptr, ptr %24, align 8, !tbaa !20
  %30 = load double, ptr %29, align 8, !tbaa !21
  br label %39

31:                                               ; preds = %22
  %32 = getelementptr inbounds i8, ptr %5, i64 24
  %33 = load double, ptr %32, align 8, !tbaa !22
  %34 = getelementptr inbounds i8, ptr %5, i64 32
  %35 = load double, ptr %34, align 8, !tbaa !23
  %36 = tail call double @Math_clip(double noundef %1, double noundef %33, double noundef %35) #3
  %37 = load ptr, ptr %23, align 8, !tbaa !17
  %38 = tail call double @RcsJoint_calcCouplingPolynomialDerivative(double noundef %36, ptr noundef %37)
  br label %39

39:                                               ; preds = %31, %28
  %.pn = phi double [ %30, %28 ], [ %38, %31 ]
  %.016 = fmul double %.pn, %2
  br label %40

40:                                               ; preds = %11, %14, %39
  %.0 = phi double [ %.016, %39 ], [ 0.000000e+00, %14 ], [ 0.000000e+00, %11 ]
  ret double %.0
}

declare double @Math_clip(double noundef, double noundef, double noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 #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 }
attributes #4 = { cold 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, !7, i64 264}
!6 = !{!"_RcsJoint", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !11, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !7, i64 88, !13, i64 96, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !12, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !8, i64 0, !8, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !7, i64 240}
!18 = !{!19, !12, i64 16}
!19 = !{!"_MatNd", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !11, i64 20}
!20 = !{!19, !7, i64 0}
!21 = !{!10, !10, i64 0}
!22 = !{!6, !10, i64 24}
!23 = !{!6, !10, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass