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

; 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._RcsGraph = type { ptr, [10 x %struct._RcsBody], i32, i32, ptr, ptr, ptr, ptr, ptr }
%struct._RcsBody = type { double, i8, i32, [3 x double], [3 x double], double, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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]] }

; 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 @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) #1

declare ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef) #1

declare void @MatNd_setZero(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_jointLimitHessian(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %19

15:                                               ; preds = %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._RcsGraph, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  br label %23

19:                                               ; preds = %3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._RcsGraph, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %19, %15
  %24 = phi i32 [ %18, %15 ], [ %22, %19 ]
  store i32 %24, ptr %7, align 4, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  call void @MatNd_reshape(ptr noundef %25, i32 noundef %26, i32 noundef %27)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @MatNd_setZero(ptr noundef %28)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._RcsGraph, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %97, %23
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %100

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._RcsBody, ptr %37, i32 0, i32 18
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  store ptr %39, ptr %10, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %92, %36
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %96

44:                                               ; preds = %40
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._RcsJoint, ptr %45, i32 0, i32 12
  %47 = load i32, ptr %46, align 8, !tbaa !19
  %48 = icmp eq i32 %47, -1
  br i1 %48, label %49, label %53

49:                                               ; preds = %44
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  br label %92

53:                                               ; preds = %49, %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._RcsJoint, ptr %54, i32 0, i32 4
  %56 = load double, ptr %55, align 8, !tbaa !22
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._RcsJoint, ptr %57, i32 0, i32 3
  %59 = load double, ptr %58, align 8, !tbaa !23
  %60 = fsub double %56, %59
  store double %60, ptr %11, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 1
  br i1 %62, label %63, label %67

63:                                               ; preds = %53
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._RcsJoint, ptr %64, i32 0, i32 12
  %66 = load i32, ptr %65, align 8, !tbaa !19
  br label %71

67:                                               ; preds = %53
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._RcsJoint, ptr %68, i32 0, i32 11
  %70 = load i32, ptr %69, align 4, !tbaa !25
  br label %71

71:                                               ; preds = %67, %63
  %72 = phi i32 [ %66, %63 ], [ %70, %67 ]
  store i32 %72, ptr %12, align 4, !tbaa !9
  %73 = load double, ptr %11, align 8, !tbaa !24
  %74 = fcmp ogt double %73, 0.000000e+00
  br i1 %74, label %75, label %91

75:                                               ; preds = %71
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._RcsJoint, ptr %76, i32 0, i32 12
  %78 = load i32, ptr %77, align 8, !tbaa !19
  %79 = icmp ne i32 %78, -1
  br i1 %79, label %80, label %91

80:                                               ; preds = %75
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = load i32, ptr %12, align 4, !tbaa !9
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._RcsJoint, ptr %84, i32 0, i32 5
  %86 = load double, ptr %85, align 8, !tbaa !26
  %87 = load double, ptr %11, align 8, !tbaa !24
  %88 = load double, ptr %11, align 8, !tbaa !24
  %89 = fmul double %87, %88
  %90 = fdiv double %86, %89
  call void @MatNd_set(ptr noundef %81, i32 noundef %82, i32 noundef %83, double noundef %90)
  br label %91

91:                                               ; preds = %80, %75, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %92

92:                                               ; preds = %91, %52
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._RcsJoint, ptr %93, i32 0, i32 23
  %95 = load ptr, ptr %94, align 8, !tbaa !27
  store ptr %95, ptr %10, align 8, !tbaa !5
  br label %40, !llvm.loop !28

96:                                               ; preds = %43
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = call ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef %98)
  store ptr %99, ptr %8, align 8, !tbaa !5
  br label %32, !llvm.loop !30

100:                                              ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

declare void @MatNd_set(ptr noundef, i32 noundef, i32 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, !10, i64 1848}
!12 = !{!"_RcsGraph", !6, i64 0, !7, i64 8, !10, i64 1848, !10, i64 1852, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888}
!13 = !{!12, !10, i64 1852}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 168}
!16 = !{!"_RcsBody", !17, i64 0, !18, i64 8, !10, i64 12, !7, i64 16, !7, i64 40, !17, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176}
!17 = !{!"double", !7, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!20, !10, i64 80}
!20 = !{!"_RcsJoint", !6, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !18, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !6, i64 88, !21, i64 96, !17, i64 192, !17, i64 200, !17, i64 208, !17, i64 216, !10, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!21 = !{!"", !7, i64 0, !7, i64 24}
!22 = !{!20, !17, i64 32}
!23 = !{!20, !17, i64 24}
!24 = !{!17, !17, i64 0}
!25 = !{!20, !10, i64 76}
!26 = !{!20, !17, i64 40}
!27 = !{!20, !6, i64 256}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !29}


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

declare void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef) local_unnamed_addr #0

declare void @MatNd_setZero(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_jointLimitHessian(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i32 %2, 0
  %.in.v = select i1 %4, i64 1848, i64 1852
  %.in = getelementptr inbounds i8, ptr %0, i64 %.in.v
  %5 = load i32, ptr %.in, align 4, !tbaa !5
  tail call void @MatNd_reshape(ptr noundef %1, i32 noundef %5, i32 noundef %5) #2
  tail call void @MatNd_setZero(ptr noundef %1) #2
  %6 = load ptr, ptr %0, align 8, !tbaa !9
  %.not36 = icmp eq ptr %6, null
  br i1 %.not36, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %3
  %7 = icmp eq i32 %2, 1
  br i1 %7, label %.lr.ph39.split.us, label %.lr.ph39.split

.lr.ph39.split.us:                                ; preds = %.lr.ph39, %._crit_edge.split.us.us
  %.037.us = phi ptr [ %9, %._crit_edge.split.us.us ], [ %6, %.lr.ph39 ]
  %8 = getelementptr inbounds i8, ptr %.037.us, i64 168
  %.02833.us = load ptr, ptr %8, align 8, !tbaa !12
  %.not3034.us = icmp eq ptr %.02833.us, null
  br i1 %.not3034.us, label %._crit_edge.split.us.us, label %.lr.ph.us

._crit_edge.split.us.us:                          ; preds = %25, %.lr.ph39.split.us
  %9 = tail call ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef nonnull %.037.us) #2
  %.not.us = icmp eq ptr %9, null
  br i1 %.not.us, label %._crit_edge40, label %.lr.ph39.split.us, !llvm.loop !13

.lr.ph.us:                                        ; preds = %.lr.ph39.split.us, %25
  %.02835.us.us = phi ptr [ %.028.us.us, %25 ], [ %.02833.us, %.lr.ph39.split.us ]
  %10 = getelementptr inbounds i8, ptr %.02835.us.us, i64 80
  %11 = load i32, ptr %10, align 8, !tbaa !15
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %25, label %13

13:                                               ; preds = %.lr.ph.us
  %14 = getelementptr inbounds i8, ptr %.02835.us.us, i64 32
  %15 = load double, ptr %14, align 8, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %.02835.us.us, i64 24
  %17 = load double, ptr %16, align 8, !tbaa !21
  %18 = fsub double %15, %17
  %19 = fcmp ule double %18, 0.000000e+00
  br i1 %19, label %25, label %20

20:                                               ; preds = %13
  %21 = getelementptr inbounds i8, ptr %.02835.us.us, i64 40
  %22 = load double, ptr %21, align 8, !tbaa !22
  %23 = fmul double %18, %18
  %24 = fdiv double %22, %23
  tail call void @MatNd_set(ptr noundef %1, i32 noundef %11, i32 noundef %11, double noundef %24) #2
  br label %25

25:                                               ; preds = %20, %13, %.lr.ph.us
  %26 = getelementptr inbounds i8, ptr %.02835.us.us, i64 256
  %.028.us.us = load ptr, ptr %26, align 8, !tbaa !12
  %.not30.us.us = icmp eq ptr %.028.us.us, null
  br i1 %.not30.us.us, label %._crit_edge.split.us.us, label %.lr.ph.us, !llvm.loop !23

._crit_edge40:                                    ; preds = %._crit_edge.split, %._crit_edge.split.us.us, %3
  ret void

.lr.ph39.split:                                   ; preds = %.lr.ph39, %._crit_edge.split
  %.037 = phi ptr [ %28, %._crit_edge.split ], [ %6, %.lr.ph39 ]
  %27 = getelementptr inbounds i8, ptr %.037, i64 168
  %.02833 = load ptr, ptr %27, align 8, !tbaa !12
  %.not3034 = icmp eq ptr %.02833, null
  br i1 %.not3034, label %._crit_edge.split, label %.lr.ph

._crit_edge.split:                                ; preds = %45, %.lr.ph39.split
  %28 = tail call ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef nonnull %.037) #2
  %.not = icmp eq ptr %28, null
  br i1 %.not, label %._crit_edge40, label %.lr.ph39.split, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph39.split, %45
  %.02835 = phi ptr [ %.028, %45 ], [ %.02833, %.lr.ph39.split ]
  %29 = getelementptr inbounds i8, ptr %.02835, i64 80
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = icmp eq i32 %30, -1
  %32 = getelementptr inbounds i8, ptr %.02835, i64 32
  %33 = load double, ptr %32, align 8, !tbaa !20
  %34 = getelementptr inbounds i8, ptr %.02835, i64 24
  %35 = load double, ptr %34, align 8, !tbaa !21
  %36 = fsub double %33, %35
  %37 = fcmp ule double %36, 0.000000e+00
  %brmerge = or i1 %31, %37
  br i1 %brmerge, label %45, label %38

38:                                               ; preds = %.lr.ph
  %39 = getelementptr inbounds i8, ptr %.02835, i64 76
  %40 = load i32, ptr %39, align 4, !tbaa !24
  %41 = getelementptr inbounds i8, ptr %.02835, i64 40
  %42 = load double, ptr %41, align 8, !tbaa !22
  %43 = fmul double %36, %36
  %44 = fdiv double %42, %43
  tail call void @MatNd_set(ptr noundef %1, i32 noundef %40, i32 noundef %40, double noundef %44) #2
  br label %45

45:                                               ; preds = %.lr.ph, %38
  %46 = getelementptr inbounds i8, ptr %.02835, i64 256
  %.028 = load ptr, ptr %46, align 8, !tbaa !12
  %.not30 = icmp eq ptr %.028, null
  br i1 %.not30, label %._crit_edge.split, label %.lr.ph, !llvm.loop !23
}

declare void @MatNd_set(ptr noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #0

attributes #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 #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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_RcsGraph", !11, i64 0, !7, i64 8, !6, i64 1848, !6, i64 1852, !11, i64 1856, !11, i64 1864, !11, i64 1872, !11, i64 1880, !11, i64 1888}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 80}
!16 = !{!"_RcsJoint", !11, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !17, i64 56, !18, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !11, i64 88, !19, i64 96, !17, i64 192, !17, i64 200, !17, i64 208, !17, i64 216, !6, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264}
!17 = !{!"double", !7, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!"", !7, i64 0, !7, i64 24}
!20 = !{!16, !17, i64 32}
!21 = !{!16, !17, i64 24}
!22 = !{!16, !17, i64 40}
!23 = distinct !{!23, !14}
!24 = !{!16, !6, i64 76}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass