; LLVM IR from jordan4ibanez/tinyphysicsengine :: old (test)

; 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.TPE_Vec4 = type { i32, i32, i32, i32 }
%struct.TPE_World = type { ptr, i16 }
%struct.TPE_Body = type { i8, [3 x i32], [2 x ptr], i8, i32, %struct.TPE_Vec4, %struct.TPE_Vec4, %struct.TPE_RotationState, i32, i8 }
%struct.TPE_RotationState = type { %struct.TPE_Vec4, %struct.TPE_Vec4, i32 }

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_bodyCollides(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_resolveCollision(ptr noundef, ptr noundef, i64, i64, i64, i64, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @TPE_worldResolveCollisionNaive(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.TPE_Vec4, align 4
  %8 = alloca %struct.TPE_Vec4, align 4
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TPE_World, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  store i16 0, ptr %4, align 2, !tbaa !12
  br label %14

14:                                               ; preds = %84, %1
  %15 = load i16, ptr %4, align 2, !tbaa !12
  %16 = zext i16 %15 to i32
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TPE_World, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 8, !tbaa !13
  %20 = zext i16 %19 to i32
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %16, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %14
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  br label %87

24:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TPE_World, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = load i16, ptr %4, align 2, !tbaa !12
  %29 = zext i16 %28 to i32
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.TPE_Body, ptr %27, i64 %31
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #2
  %33 = load i16, ptr %4, align 2, !tbaa !12
  %34 = zext i16 %33 to i32
  %35 = add nsw i32 %34, 1
  %36 = trunc i32 %35 to i16
  store i16 %36, ptr %9, align 2, !tbaa !12
  br label %37

37:                                               ; preds = %78, %24
  %38 = load i16, ptr %9, align 2, !tbaa !12
  %39 = zext i16 %38 to i32
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TPE_World, ptr %40, i32 0, i32 1
  %42 = load i16, ptr %41, align 8, !tbaa !13
  %43 = zext i16 %42 to i32
  %44 = icmp slt i32 %39, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %37
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #2
  br label %81

46:                                               ; preds = %37
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TPE_Body, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 4, !tbaa !14
  %50 = icmp ne i32 %49, 2147483647
  br i1 %50, label %56, label %51

51:                                               ; preds = %46
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TPE_Body, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = icmp ne i32 %54, 2147483647
  br i1 %55, label %56, label %75

56:                                               ; preds = %51, %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call i32 @TPE_bodyCollides(ptr noundef %57, ptr noundef %58, ptr noundef %7, ptr noundef %8)
  store i32 %59, ptr %10, align 4, !tbaa !19
  %60 = load i32, ptr %10, align 4, !tbaa !19
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %74

62:                                               ; preds = %56
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !19
  %66 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %67 = load i64, ptr %66, align 4
  %68 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %69 = load i64, ptr %68, align 4
  %70 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %71 = load i64, ptr %70, align 4
  %72 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %73 = load i64, ptr %72, align 4
  call void @TPE_resolveCollision(ptr noundef %63, ptr noundef %64, i64 %67, i64 %69, i64 %71, i64 %73, i32 noundef %65, i32 noundef 300)
  br label %74

74:                                               ; preds = %62, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %75

75:                                               ; preds = %74, %51
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TPE_Body, ptr %76, i32 1
  store ptr %77, ptr %6, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %75
  %79 = load i16, ptr %9, align 2, !tbaa !12
  %80 = add i16 %79, 1
  store i16 %80, ptr %9, align 2, !tbaa !12
  br label %37, !llvm.loop !20

81:                                               ; preds = %45
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.TPE_Body, ptr %82, i32 1
  store ptr %83, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %84

84:                                               ; preds = %81
  %85 = load i16, ptr %4, align 2, !tbaa !12
  %86 = add i16 %85, 1
  store i16 %86, ptr %4, align 2, !tbaa !12
  br label %14, !llvm.loop !22

87:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !16, i64 36}
!15 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !16, i64 36, !17, i64 40, !17, i64 56, !18, i64 72, !16, i64 108, !7, i64 112}
!16 = !{!"int", !7, i64 0}
!17 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!18 = !{!"", !17, i64 0, !17, i64 16, !16, i64 32}
!19 = !{!16, !16, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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.TPE_Vec4 = type { i32, i32, i32, i32 }
%struct.TPE_Body = type { i8, [3 x i32], [2 x ptr], i8, i32, %struct.TPE_Vec4, %struct.TPE_Vec4, %struct.TPE_RotationState, i32, i8 }
%struct.TPE_RotationState = type { %struct.TPE_Vec4, %struct.TPE_Vec4, i32 }

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_bodyCollides(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_resolveCollision(ptr noundef, ptr noundef, i64, i64, i64, i64, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TPE_worldResolveCollisionNaive(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca %struct.TPE_Vec4, align 8
  %3 = alloca %struct.TPE_Vec4, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i16, ptr %4, align 8, !tbaa !5
  %6 = icmp ugt i16 %5, 1
  br i1 %6, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  br label %10

._crit_edge32:                                    ; preds = %._crit_edge, %1
  ret void

10:                                               ; preds = %.lr.ph31, %._crit_edge
  %11 = phi i16 [ %5, %.lr.ph31 ], [ %20, %._crit_edge ]
  %12 = phi i32 [ 0, %.lr.ph31 ], [ %23, %._crit_edge ]
  %.029 = phi ptr [ %7, %.lr.ph31 ], [ %21, %._crit_edge ]
  %.02128 = phi i16 [ 0, %.lr.ph31 ], [ %22, %._crit_edge ]
  %13 = load ptr, ptr %0, align 8, !tbaa !11
  %14 = add nuw nsw i32 %12, 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  %15 = trunc nuw i32 %14 to i16
  %16 = icmp ugt i16 %11, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10
  %17 = zext nneg i32 %14 to i64
  %18 = getelementptr inbounds %struct.TPE_Body, ptr %13, i64 %17
  %19 = getelementptr inbounds i8, ptr %.029, i64 36
  br label %27

._crit_edge:                                      ; preds = %39, %10
  %20 = phi i16 [ %11, %10 ], [ %42, %39 ]
  %21 = getelementptr inbounds i8, ptr %.029, i64 120
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #2
  %22 = add nuw i16 %.02128, 1
  %23 = zext i16 %22 to i32
  %24 = zext i16 %20 to i32
  %25 = add nsw i32 %24, -1
  %26 = icmp sgt i32 %25, %23
  br i1 %26, label %10, label %._crit_edge32, !llvm.loop !12

27:                                               ; preds = %.lr.ph, %39
  %.01927 = phi i16 [ %15, %.lr.ph ], [ %41, %39 ]
  %.02026 = phi ptr [ %18, %.lr.ph ], [ %40, %39 ]
  %28 = load i32, ptr %19, align 4, !tbaa !14
  %.not = icmp eq i32 %28, 2147483647
  br i1 %.not, label %29, label %32

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %.02026, i64 36
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %.not24 = icmp eq i32 %31, 2147483647
  br i1 %.not24, label %39, label %32

32:                                               ; preds = %29, %27
  %33 = call i32 @TPE_bodyCollides(ptr noundef nonnull %.029, ptr noundef nonnull %.02026, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not25 = icmp eq i32 %33, 0
  br i1 %.not25, label %39, label %34

34:                                               ; preds = %32
  %35 = load i64, ptr %2, align 8
  %36 = load i64, ptr %8, align 8
  %37 = load i64, ptr %3, align 8
  %38 = load i64, ptr %9, align 8
  call void @TPE_resolveCollision(ptr noundef nonnull %.029, ptr noundef nonnull %.02026, i64 %35, i64 %36, i64 %37, i64 %38, i32 noundef %33, i32 noundef 300)
  br label %39

39:                                               ; preds = %32, %34, %29
  %40 = getelementptr inbounds i8, ptr %.02026, i64 120
  %41 = add nuw i16 %.01927, 1
  %42 = load i16, ptr %4, align 8, !tbaa !5
  %43 = icmp ult i16 %41, %42
  br i1 %43, label %27, label %._crit_edge, !llvm.loop !19
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 36}
!15 = !{!"", !8, i64 0, !8, i64 4, !8, i64 16, !8, i64 32, !16, i64 36, !17, i64 40, !17, i64 56, !18, i64 72, !16, i64 108, !8, i64 112}
!16 = !{!"int", !8, i64 0}
!17 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!18 = !{!"", !17, i64 0, !17, i64 16, !16, i64 32}
!19 = distinct !{!19, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass