; LLVM IR from jdeokkim/ferox :: src (rigid_body)

; 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.frVector2_ = type { float, float }
%struct.frBody_ = type { %struct.frMotionData_, %struct.frTransform_, ptr, i32, i32, %struct.frAABB_, ptr }
%struct.frMotionData_ = type { float, float, float, float, %struct.frVector2_, float, float, %struct.frVector2_, float }
%struct.frTransform_ = type { %struct.frVector2_, %struct.anon, float }
%struct.anon = type { float, float }
%struct.frAABB_ = type { float, float, float, float }

; Function Attrs: nounwind uwtable
define dso_local ptr @frCreateBody(i32 noundef %0, <2 x float> %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.frVector2_, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store <2 x float> %1, ptr %4, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = icmp ult i32 %7, 1
  br i1 %8, label %12, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp ugt i32 %10, 3
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %2
  store ptr null, ptr %3, align 8
  br label %33

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %14 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 104) #5
  store ptr %14, ptr %6, align 8, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.frBody_, ptr %16, i32 0, i32 3
  store i32 %15, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.frBody_, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.frTransform_, ptr %19, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !19
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.frBody_, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.frTransform_, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 0
  store float 0.000000e+00, ptr %24, align 4, !tbaa !21
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.frBody_, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.frTransform_, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 1
  store float 1.000000e+00, ptr %28, align 4, !tbaa !22
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.frBody_, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.frMotionData_, ptr %30, i32 0, i32 6
  store float 1.000000e+00, ptr %31, align 4, !tbaa !23
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %32, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %33

33:                                               ; preds = %13, %12
  %34 = load ptr, ptr %3, align 8
  ret ptr %34
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { nounwind uwtable "min-legal-vector-width"="64" "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 allocsize(0,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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 72}
!12 = !{!"frBody_", !13, i64 0, !16, i64 44, !10, i64 64, !6, i64 72, !6, i64 76, !18, i64 80, !10, i64 96}
!13 = !{!"frMotionData_", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !15, i64 16, !14, i64 24, !14, i64 28, !15, i64 32, !14, i64 40}
!14 = !{!"float", !7, i64 0}
!15 = !{!"frVector2_", !14, i64 0, !14, i64 4}
!16 = !{!"frTransform_", !15, i64 0, !17, i64 8, !14, i64 16}
!17 = !{!"", !14, i64 0, !14, i64 4}
!18 = !{!"frAABB_", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!19 = !{i64 0, i64 4, !20, i64 4, i64 4, !20}
!20 = !{!14, !14, i64 0}
!21 = !{!12, !14, i64 52}
!22 = !{!12, !14, i64 56}
!23 = !{!12, !14, i64 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"

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @frCreateBody(i32 noundef %0, <2 x float> %1) local_unnamed_addr #0 {
  %3 = add i32 %0, -4
  %or.cond = icmp ult i32 %3, -3
  br i1 %or.cond, label %10, label %4

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(104) ptr @calloc(i64 noundef 1, i64 noundef 104) #2
  %6 = getelementptr inbounds i8, ptr %5, i64 72
  store i32 %0, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 44
  store <2 x float> %1, ptr %7, align 4
  %8 = getelementptr inbounds i8, ptr %5, i64 56
  store float 1.000000e+00, ptr %8, align 4, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %5, i64 28
  store float 1.000000e+00, ptr %9, align 4, !tbaa !18
  br label %10

10:                                               ; preds = %2, %4
  %.0 = phi ptr [ %5, %4 ], [ null, %2 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) uwtable "min-legal-vector-width"="64" "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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0,1) }

!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, !15, i64 72}
!6 = !{!"frBody_", !7, i64 0, !12, i64 44, !14, i64 64, !15, i64 72, !15, i64 76, !16, i64 80, !14, i64 96}
!7 = !{!"frMotionData_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28, !11, i64 32, !8, i64 40}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"frVector2_", !8, i64 0, !8, i64 4}
!12 = !{!"frTransform_", !11, i64 0, !13, i64 8, !8, i64 16}
!13 = !{!"", !8, i64 0, !8, i64 4}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!"frAABB_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!17 = !{!6, !8, i64 56}
!18 = !{!6, !8, i64 28}


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