; LLVM IR from Mithreindeir/VelocityRaptor :: VelocityRaptor/src (vrManifold)

; 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.vrLocalPoint = type { float, %struct.vrVec2, ptr }
%struct.vrVec2 = type { float, float }
%struct.vrManifold = type { ptr, ptr, [2 x %struct.vrContactPoint], i32, %struct.vrVec2, %struct.vrVec2, float, float, float, %struct.vrBlockSolverData, i32, i32, i32, i32 }
%struct.vrContactPoint = type { %struct.vrVec2, %struct.vrVec2, float, float, float, float, %struct.vrVec2, %struct.vrVec2, float, float, float, float, %struct.vrLocalPoint }
%struct.vrBlockSolverData = type { %struct.vrVec2, %struct.vrMat2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2, %struct.vrVec2 }
%struct.vrMat2 = type { %struct.vrVec2, %struct.vrVec2 }

; 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.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias 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

; Function Attrs: nounwind uwtable
define dso_local void @vrManifoldSetBodies(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.vrLocalPoint, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.vrManifold, ptr %10, i32 0, i32 10
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %21

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.vrManifold, ptr %16, i32 0, i32 0
  store ptr %15, ptr %17, align 8, !tbaa !16
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.vrManifold, ptr %19, i32 0, i32 1
  store ptr %18, ptr %20, align 8, !tbaa !17
  br label %28

21:                                               ; preds = %3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.vrManifold, ptr %23, i32 0, i32 0
  store ptr %22, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.vrManifold, ptr %26, i32 0, i32 1
  store ptr %25, ptr %27, align 8, !tbaa !17
  br label %28

28:                                               ; preds = %21, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %29

29:                                               ; preds = %51, %28
  %30 = load i32, ptr %7, align 4, !tbaa !18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.vrManifold, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %54

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.vrManifold, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds [2 x %struct.vrContactPoint], ptr %38, i64 0, i64 0
  %40 = load i32, ptr %7, align 4, !tbaa !18
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.vrContactPoint, ptr %39, i64 %41
  store ptr %42, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.vrContactPoint, ptr %43, i32 0, i32 12
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #4
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.vrManifold, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.vrContactPoint, ptr %48, i32 0, i32 1
  %50 = load <2 x float>, ptr %49, align 8
  call void @vrLocalPointInit(ptr dead_on_unwind writable sret(%struct.vrLocalPoint) align 8 %9, ptr noundef %47, <2 x float> %50)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %9, i64 24, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %51

51:                                               ; preds = %36
  %52 = load i32, ptr %7, align 4, !tbaa !18
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !18
  br label %29, !llvm.loop !22

54:                                               ; preds = %35
  ret void
}

declare void @vrLocalPointInit(ptr dead_on_unwind writable sret(%struct.vrLocalPoint) align 8, ptr noundef, <2 x float>) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 280}
!10 = !{!"vrManifold", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 192, !12, i64 196, !12, i64 204, !13, i64 212, !13, i64 216, !13, i64 220, !14, i64 224, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292}
!11 = !{!"int", !7, i64 0}
!12 = !{!"vrVec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!"vrBlockSolverData", !12, i64 0, !15, i64 8, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!15 = !{!"vrMat2", !12, i64 0, !12, i64 8}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !6, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !11, i64 192}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 16, i64 8, !5}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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.vrLocalPoint = type { float, %struct.vrVec2, ptr }
%struct.vrVec2 = type { float, float }
%struct.vrContactPoint = type { %struct.vrVec2, %struct.vrVec2, float, float, float, float, %struct.vrVec2, %struct.vrVec2, float, float, float, float, %struct.vrLocalPoint }

; 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.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias 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

; Function Attrs: nounwind uwtable
define dso_local void @vrManifoldSetBodies(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.vrLocalPoint, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 280
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  %spec.select = select i1 %.not, ptr %2, ptr %1
  %spec.select19 = select i1 %.not, ptr %1, ptr %2
  store ptr %spec.select, ptr %0, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %spec.select19, ptr %7, align 8
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

._crit_edge:                                      ; preds = %12, %3
  ret void

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = getelementptr inbounds %struct.vrContactPoint, ptr %11, i64 %indvars.iv
  %14 = getelementptr inbounds i8, ptr %13, i64 64
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  %17 = load <2 x float>, ptr %16, align 8
  call void @vrLocalPointInit(ptr dead_on_unwind nonnull writable sret(%struct.vrLocalPoint) align 8 %4, ptr noundef %15, <2 x float> %17) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(24) %4, i64 24, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr %8, align 8, !tbaa !15
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %12, label %._crit_edge, !llvm.loop !20
}

declare void @vrLocalPointInit(ptr dead_on_unwind writable sret(%struct.vrLocalPoint) align 8, ptr noundef, <2 x float>) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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, !10, i64 280}
!6 = !{!"vrManifold", !7, i64 0, !7, i64 8, !8, i64 16, !10, i64 192, !11, i64 196, !11, i64 204, !12, i64 212, !12, i64 216, !12, i64 220, !13, i64 224, !10, i64 280, !10, i64 284, !10, i64 288, !10, i64 292}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"vrVec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!"vrBlockSolverData", !11, i64 0, !14, i64 8, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!14 = !{!"vrMat2", !11, i64 0, !11, i64 8}
!15 = !{!6, !10, i64 192}
!16 = !{!6, !7, i64 8}
!17 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18, i64 16, i64 8, !19}
!18 = !{!12, !12, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass