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

declare ptr @RcsBody_lastJointBeforeBody(ptr noundef) #1

declare zeroext i1 @RcsJoint_isRotation(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_rotationJacobian(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [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 ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._RcsGraph, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !9
  call void @MatNd_reshapeAndSetZero(ptr noundef %12, i32 noundef 3, i32 noundef %15)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %73

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call ptr @RcsBody_lastJointBeforeBody(ptr noundef %20)
  store ptr %21, ptr %9, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %68, %37, %19
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %72

25:                                               ; preds = %22
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._RcsJoint, ptr %26, i32 0, i32 8
  %28 = load i8, ptr %27, align 8, !tbaa !12, !range !17, !noundef !18
  %29 = trunc i8 %28 to i1
  %30 = zext i1 %29 to i32
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %37, label %32

32:                                               ; preds = %25
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = call zeroext i1 @RcsJoint_isRotation(ptr noundef %33)
  %35 = zext i1 %34 to i32
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %32, %25
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._RcsJoint, ptr %38, i32 0, i32 22
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  store ptr %40, ptr %9, align 8, !tbaa !5
  br label %22, !llvm.loop !20

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._RcsJoint, ptr %42, i32 0, i32 14
  %44 = getelementptr inbounds %struct.HTr, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._RcsJoint, ptr %45, i32 0, i32 10
  %47 = load i32, ptr %46, align 8, !tbaa !22
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [3 x [3 x double]], ptr %44, i64 0, i64 %48
  %50 = getelementptr inbounds [3 x double], ptr %49, i64 0, i64 0
  store ptr %50, ptr %10, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %62

53:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #3
  %54 = getelementptr inbounds [3 x double], ptr %11, i64 0, i64 0
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @Vec3d_rotate(ptr noundef %54, ptr noundef %55, ptr noundef %56)
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._RcsJoint, ptr %58, i32 0, i32 12
  %60 = load i32, ptr %59, align 8, !tbaa !23
  %61 = getelementptr inbounds [3 x double], ptr %11, i64 0, i64 0
  call void @MatNd_setColumn(ptr noundef %57, i32 noundef %60, ptr noundef %61, i32 noundef 3)
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #3
  br label %68

62:                                               ; preds = %41
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._RcsJoint, ptr %64, i32 0, i32 12
  %66 = load i32, ptr %65, align 8, !tbaa !23
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  call void @MatNd_setColumn(ptr noundef %63, i32 noundef %66, ptr noundef %67, i32 noundef 3)
  br label %68

68:                                               ; preds = %62, %53
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._RcsJoint, ptr %69, i32 0, i32 22
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  store ptr %71, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %22, !llvm.loop !20

72:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %73

73:                                               ; preds = %72, %18
  ret void
}

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

declare void @MatNd_setColumn(ptr noundef, i32 noundef, ptr noundef, i32 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, !11, i64 1852}
!10 = !{!"_RcsGraph", !6, i64 0, !7, i64 8, !11, i64 1848, !11, i64 1852, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !15, i64 64}
!13 = !{!"_RcsJoint", !6, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !15, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !6, i64 88, !16, i64 96, !14, i64 192, !14, i64 200, !14, i64 208, !14, i64 216, !11, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!14 = !{!"double", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 24}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!13, !6, i64 248}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!13, !11, i64 72}
!23 = !{!13, !11, i64 80}


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

declare ptr @RcsBody_lastJointBeforeBody(ptr noundef) local_unnamed_addr #1

declare zeroext i1 @RcsJoint_isRotation(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_rotationJacobian(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca [3 x double], align 16
  %6 = getelementptr inbounds i8, ptr %0, i64 1852
  %7 = load i32, ptr %6, align 4, !tbaa !5
  tail call void @MatNd_reshapeAndSetZero(ptr noundef %3, i32 noundef 3, i32 noundef %7) #3
  %8 = icmp eq ptr %1, null
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %4
  %10 = tail call ptr @RcsBody_lastJointBeforeBody(ptr noundef nonnull %1) #3
  %.not22 = icmp eq ptr %10, null
  br i1 %.not22, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %.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, %.backedge.us
  %.023.us = phi ptr [ %.0.be.us, %.backedge.us ], [ %10, %.lr.ph ]
  %11 = getelementptr inbounds i8, ptr %.023.us, i64 64
  %12 = load i8, ptr %11, align 8, !tbaa !11, !range !16, !noundef !17
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %.backedge.us, label %14

14:                                               ; preds = %.lr.ph.split.us
  %15 = tail call zeroext i1 @RcsJoint_isRotation(ptr noundef nonnull %.023.us) #3
  br i1 %15, label %16, label %.backedge.us

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %.023.us, i64 120
  %18 = getelementptr inbounds i8, ptr %.023.us, i64 72
  %19 = load i32, ptr %18, align 8, !tbaa !18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3 x [3 x double]], ptr %17, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %.023.us, i64 80
  %23 = load i32, ptr %22, align 8, !tbaa !19
  tail call void @MatNd_setColumn(ptr noundef %3, i32 noundef %23, ptr noundef nonnull %21, i32 noundef 3) #3
  br label %.backedge.us

.backedge.us:                                     ; preds = %.lr.ph.split.us, %14, %16
  %.0.be.us.in = getelementptr inbounds i8, ptr %.023.us, i64 248
  %.0.be.us = load ptr, ptr %.0.be.us.in, align 8, !tbaa !20
  %.not.us = icmp eq ptr %.0.be.us, null
  br i1 %.not.us, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !21

.lr.ph.split:                                     ; preds = %.lr.ph, %.backedge
  %.023 = phi ptr [ %.0.be, %.backedge ], [ %10, %.lr.ph ]
  %24 = getelementptr inbounds i8, ptr %.023, i64 64
  %25 = load i8, ptr %24, align 8, !tbaa !11, !range !16, !noundef !17
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %.backedge, label %27

27:                                               ; preds = %.lr.ph.split
  %28 = call zeroext i1 @RcsJoint_isRotation(ptr noundef nonnull %.023) #3
  br i1 %28, label %29, label %.backedge

.backedge:                                        ; preds = %.lr.ph.split, %27, %29
  %.0.be.in = getelementptr inbounds i8, ptr %.023, i64 248
  %.0.be = load ptr, ptr %.0.be.in, align 8, !tbaa !20
  %.not = icmp eq ptr %.0.be, null
  br i1 %.not, label %.loopexit, label %.lr.ph.split, !llvm.loop !21

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %.023, i64 120
  %31 = getelementptr inbounds i8, ptr %.023, i64 72
  %32 = load i32, ptr %31, align 8, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [3 x [3 x double]], ptr %30, i64 0, i64 %33
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @Vec3d_rotate(ptr noundef nonnull %5, ptr noundef nonnull %2, ptr noundef nonnull %34) #3
  %35 = getelementptr inbounds i8, ptr %.023, i64 80
  %36 = load i32, ptr %35, align 8, !tbaa !19
  call void @MatNd_setColumn(ptr noundef %3, i32 noundef %36, ptr noundef nonnull %5, i32 noundef 3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  br label %.backedge

.loopexit:                                        ; preds = %.backedge, %.backedge.us, %9, %4
  ret void
}

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

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


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