; 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._MatNd = type { ptr, i32, i32, i32, i8 }

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @MatNd_reshape(ptr noundef, i32 noundef, i32 noundef) #1

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

declare void @MatNd_destroy(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_rotationDotJacobian(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = 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 ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %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
  store i32 %15, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._RcsGraph, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = mul i32 3, %18
  store i32 %19, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr null, ptr %11, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !12
  %21 = load i32, ptr %9, align 4, !tbaa !12
  %22 = mul nsw i32 %20, %21
  %23 = icmp sgt i32 %22, 1296
  br i1 %23, label %24, label %28

24:                                               ; preds = %4
  %25 = load i32, ptr %10, align 4, !tbaa !12
  %26 = load i32, ptr %9, align 4, !tbaa !12
  %27 = call ptr @MatNd_create(i32 noundef %25, i32 noundef %26)
  store ptr %27, ptr %11, align 8, !tbaa !5
  br label %66

28:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %29 = load i32, ptr %10, align 4, !tbaa !12
  %30 = load i32, ptr %9, align 4, !tbaa !12
  %31 = mul nsw i32 %29, %30
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  br label %38

34:                                               ; preds = %28
  %35 = load i32, ptr %10, align 4, !tbaa !12
  %36 = load i32, ptr %9, align 4, !tbaa !12
  %37 = mul nsw i32 %35, %36
  br label %38

38:                                               ; preds = %34, %33
  %39 = phi i32 [ 1, %33 ], [ %37, %34 ]
  store i32 %39, ptr %12, align 4, !tbaa !12
  %40 = load i32, ptr %12, align 4, !tbaa !12
  %41 = zext i32 %40 to i64
  %42 = mul i64 %41, 8
  %43 = add i64 24, %42
  %44 = alloca i8, i64 %43, align 16
  store ptr %44, ptr %11, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._MatNd, ptr %45, i64 1
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._MatNd, ptr %47, i32 0, i32 0
  store ptr %46, ptr %48, align 8, !tbaa !13
  %49 = load i32, ptr %10, align 4, !tbaa !12
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._MatNd, ptr %50, i32 0, i32 1
  store i32 %49, ptr %51, align 8, !tbaa !16
  %52 = load i32, ptr %9, align 4, !tbaa !12
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._MatNd, ptr %53, i32 0, i32 2
  store i32 %52, ptr %54, align 4, !tbaa !17
  %55 = load i32, ptr %12, align 4, !tbaa !12
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._MatNd, ptr %56, i32 0, i32 3
  store i32 %55, ptr %57, align 8, !tbaa !18
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MatNd, ptr %58, i32 0, i32 4
  store i8 1, ptr %59, align 4, !tbaa !19
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._MatNd, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = load i32, ptr %12, align 4, !tbaa !12
  %64 = zext i32 %63 to i64
  %65 = mul i64 %64, 8
  call void @llvm.memset.p0.i64(ptr align 8 %62, i8 0, i64 %65, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %66

66:                                               ; preds = %38, %24
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  call void @RcsGraph_rotationHessian(ptr noundef %67, ptr noundef %68, ptr noundef null, ptr noundef %69)
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i32, ptr %10, align 4, !tbaa !12
  call void @MatNd_reshape(ptr noundef %70, i32 noundef %71, i32 noundef 1)
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  call void @MatNd_mul(ptr noundef %72, ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !12
  call void @MatNd_reshape(ptr noundef %75, i32 noundef 3, i32 noundef %76)
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  call void @MatNd_destroy(ptr noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_MatNd", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !15, i64 20}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!14, !11, i64 8}
!17 = !{!14, !11, i64 12}
!18 = !{!14, !11, i64 16}
!19 = !{!14, !15, i64 20}


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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare void @MatNd_mul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @MatNd_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @RcsGraph_rotationHessian(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @RcsGraph_rotationDotJacobian(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 1852
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = mul i32 %6, 3
  %8 = mul nsw i32 %7, %6
  %9 = icmp sgt i32 %8, 1296
  br i1 %9, label %10, label %12

10:                                               ; preds = %4
  %11 = tail call ptr @MatNd_create(i32 noundef %7, i32 noundef %6) #4
  br label %23

12:                                               ; preds = %4
  %13 = tail call i32 @llvm.umax.i32(i32 %8, i32 1)
  %14 = zext i32 %13 to i64
  %15 = shl nuw nsw i64 %14, 3
  %16 = add nuw nsw i64 %15, 24
  %17 = alloca i8, i64 %16, align 16
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  store ptr %18, ptr %17, align 16, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store i32 %7, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %17, i64 12
  store i32 %6, ptr %20, align 4, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %17, i64 16
  store i32 %13, ptr %21, align 16, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %17, i64 20
  store i8 1, ptr %22, align 4, !tbaa !17
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %18, i8 0, i64 %15, i1 false)
  br label %23

23:                                               ; preds = %12, %10
  %.0 = phi ptr [ %11, %10 ], [ %17, %12 ]
  call void @RcsGraph_rotationHessian(ptr noundef nonnull %0, ptr noundef %1, ptr noundef null, ptr noundef %.0)
  call void @MatNd_reshape(ptr noundef %3, i32 noundef %7, i32 noundef 1) #4
  call void @MatNd_mul(ptr noundef %3, ptr noundef %.0, ptr noundef %2) #4
  call void @MatNd_reshape(ptr noundef %3, i32 noundef 3, i32 noundef %6) #4
  call void @MatNd_destroy(ptr noundef %.0) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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, !7, i64 0}
!12 = !{!"_MatNd", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !13, i64 20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass