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

; 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._MatNd = type { ptr, i32, i32, i32, i8 }
%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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

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

declare void @MatNd_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8, i32 noundef, i32 noundef, ptr noundef) #2

declare ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local double @Rcs_directDynamics(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @Rcs_directDynamicsIntegrationStep(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct._MatNd, align 8
  %13 = alloca %struct._MatNd, align 8
  %14 = alloca %struct._MatNd, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  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 double %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._RcsGraph, ptr %19, i32 0, i32 8
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  store ptr %21, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._RcsGraph, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %11, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #4
  %25 = load i32, ptr %11, align 4, !tbaa !15
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %26, i64 0
  call void @MatNd_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8 %12, i32 noundef %25, i32 noundef 1, ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #4
  %28 = load i32, ptr %11, align 4, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  call void @MatNd_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8 %13, i32 noundef %28, i32 noundef 1, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #4
  %33 = load i32, ptr %11, align 4, !tbaa !15
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !15
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %34, i64 %36
  call void @MatNd_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8 %14, i32 noundef %33, i32 noundef 1, ptr noundef %37)
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = call zeroext i1 @RcsGraph_setState(ptr noundef %38, ptr noundef %12, ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._RcsGraph, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  store ptr %42, ptr %15, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %74, %4
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %77

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._RcsBody, ptr %48, i32 0, i32 18
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  store ptr %50, ptr %17, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %69, %47
  %52 = load ptr, ptr %17, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %73

55:                                               ; preds = %51
  %56 = load ptr, ptr %17, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._RcsJoint, ptr %56, i32 0, i32 24
  %58 = load ptr, ptr %57, align 8, !tbaa !20
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %68

60:                                               ; preds = %55
  %61 = getelementptr inbounds %struct._MatNd, ptr %13, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = load ptr, ptr %17, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._RcsJoint, ptr %63, i32 0, i32 12
  %65 = load i32, ptr %64, align 8, !tbaa !25
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %62, i64 %66
  store double 0.000000e+00, ptr %67, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %60, %55
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %17, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._RcsJoint, ptr %70, i32 0, i32 23
  %72 = load ptr, ptr %71, align 8, !tbaa !26
  store ptr %72, ptr %17, align 8, !tbaa !5
  br label %51, !llvm.loop !27

73:                                               ; preds = %54
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = call ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef %75)
  store ptr %76, ptr %15, align 8, !tbaa !5
  br label %43, !llvm.loop !29

77:                                               ; preds = %46
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = call double @Rcs_directDynamics(ptr noundef %78, ptr noundef %79, ptr noundef null, ptr noundef %14)
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds double, ptr %81, i64 0
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i32, ptr %11, align 4, !tbaa !15
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  %87 = load i32, ptr %11, align 4, !tbaa !15
  %88 = sext i32 %87 to i64
  %89 = mul i64 %88, 8
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %82, ptr align 8 %86, i64 %89, i1 false)
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

declare zeroext i1 @RcsGraph_setState(ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #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 1888}
!12 = !{!"_RcsGraph", !6, i64 0, !7, i64 8, !13, i64 1848, !13, i64 1852, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 1852}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !6, i64 168}
!18 = !{!"_RcsBody", !10, i64 0, !19, i64 8, !13, i64 12, !7, i64 16, !7, i64 40, !10, 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}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!21, !6, i64 264}
!21 = !{!"_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, !19, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !13, i64 80, !6, i64 88, !22, i64 96, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !13, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264}
!22 = !{!"", !7, i64 0, !7, i64 24}
!23 = !{!24, !6, i64 0}
!24 = !{!"_MatNd", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !19, i64 20}
!25 = !{!21, !13, i64 80}
!26 = !{!21, !6, i64 256}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}


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

%struct._MatNd = type { ptr, i32, i32, i32, i8 }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; 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_fromPtr(ptr dead_on_unwind writable sret(%struct._MatNd) align 8, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local double @Rcs_directDynamics(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @Rcs_directDynamicsIntegrationStep(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct._MatNd, align 8
  %6 = alloca %struct._MatNd, align 8
  %7 = alloca %struct._MatNd, align 8
  %8 = getelementptr inbounds i8, ptr %1, i64 1888
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 1852
  %11 = load i32, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @MatNd_fromPtr(ptr dead_on_unwind nonnull writable sret(%struct._MatNd) align 8 %5, i32 noundef %11, i32 noundef 1, ptr noundef %0) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds double, ptr %0, i64 %12
  call void @MatNd_fromPtr(ptr dead_on_unwind nonnull writable sret(%struct._MatNd) align 8 %6, i32 noundef %11, i32 noundef 1, ptr noundef %13) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #4
  %14 = getelementptr inbounds double, ptr %2, i64 %12
  call void @MatNd_fromPtr(ptr dead_on_unwind nonnull writable sret(%struct._MatNd) align 8 %7, i32 noundef %11, i32 noundef 1, ptr noundef %14) #4
  %15 = call zeroext i1 @RcsGraph_setState(ptr noundef %1, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %16 = load ptr, ptr %1, align 8, !tbaa !12
  %.not31 = icmp eq ptr %16, null
  br i1 %.not31, label %._crit_edge35, label %.lr.ph34

._crit_edge35:                                    ; preds = %._crit_edge, %4
  %17 = call double @Rcs_directDynamics(ptr noundef nonnull %1, ptr noundef %9, ptr noundef null, ptr noundef nonnull %7)
  %18 = shl nsw i64 %12, 3
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %2, ptr align 8 %13, i64 %18, i1 false)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  ret void

.lr.ph34:                                         ; preds = %4, %._crit_edge
  %.02532 = phi ptr [ %21, %._crit_edge ], [ %16, %4 ]
  %19 = getelementptr inbounds i8, ptr %.02532, i64 168
  %.028 = load ptr, ptr %19, align 8, !tbaa !13
  %.not2629 = icmp eq ptr %.028, null
  br i1 %.not2629, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph34
  %20 = load ptr, ptr %6, align 8
  br label %22

._crit_edge:                                      ; preds = %30, %.lr.ph34
  %21 = call ptr @RcsBody_depthFirstTraversalGetNext(ptr noundef nonnull %.02532) #4
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !14

22:                                               ; preds = %.lr.ph, %30
  %.030 = phi ptr [ %.028, %.lr.ph ], [ %.0, %30 ]
  %23 = getelementptr inbounds i8, ptr %.030, i64 264
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %.not27 = icmp eq ptr %24, null
  br i1 %.not27, label %30, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %.030, i64 80
  %27 = load i32, ptr %26, align 8, !tbaa !21
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %20, i64 %28
  store double 0.000000e+00, ptr %29, align 8, !tbaa !22
  br label %30

30:                                               ; preds = %22, %25
  %31 = getelementptr inbounds i8, ptr %.030, i64 256
  %.0 = load ptr, ptr %31, align 8, !tbaa !13
  %.not26 = icmp eq ptr %.0, null
  br i1 %.not26, label %._crit_edge, label %22, !llvm.loop !23
}

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

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


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