; 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: 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: nounwind uwtable
declare dso_local { i64, i64 } @TPE_vec3Plus(i64, i64, i64, i64) #2

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_createVecFromTo(i64, i64, i64, i64, i32 noundef) #2

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

17:                                               ; preds = %68, %4
  %18 = load i16, ptr %9, align 2, !tbaa !14
  %19 = zext i16 %18 to i32
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TPE_World, ptr %20, i32 0, i32 1
  %22 = load i16, ptr %21, align 8, !tbaa !15
  %23 = zext i16 %22 to i32
  %24 = icmp slt i32 %19, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  br label %71

26:                                               ; preds = %17
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TPE_Body, ptr %27, i32 0, i32 4
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = icmp ne i32 %29, 2147483647
  br i1 %30, label %31, label %65

31:                                               ; preds = %26
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TPE_Body, ptr %32, i32 0, i32 6
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TPE_Body, ptr %34, i32 0, i32 6
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TPE_Body, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = getelementptr inbounds { i64, i64 }, ptr %37, i32 0, i32 0
  %40 = load i64, ptr %39, align 8
  %41 = getelementptr inbounds { i64, i64 }, ptr %37, i32 0, i32 1
  %42 = load i64, ptr %41, align 8
  %43 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %44 = load i64, ptr %43, align 4
  %45 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %46 = load i64, ptr %45, align 4
  %47 = call { i64, i64 } @TPE_createVecFromTo(i64 %40, i64 %42, i64 %44, i64 %46, i32 noundef %38)
  %48 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %49 = extractvalue { i64, i64 } %47, 0
  store i64 %49, ptr %48, align 4
  %50 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %51 = extractvalue { i64, i64 } %47, 1
  store i64 %51, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i64 }, ptr %35, i32 0, i32 0
  %53 = load i64, ptr %52, align 8
  %54 = getelementptr inbounds { i64, i64 }, ptr %35, i32 0, i32 1
  %55 = load i64, ptr %54, align 8
  %56 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %57 = load i64, ptr %56, align 4
  %58 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %59 = load i64, ptr %58, align 4
  %60 = call { i64, i64 } @TPE_vec3Plus(i64 %53, i64 %55, i64 %57, i64 %59)
  %61 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %62 = extractvalue { i64, i64 } %60, 0
  store i64 %62, ptr %61, align 4
  %63 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %64 = extractvalue { i64, i64 } %60, 1
  store i64 %64, ptr %63, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %33, ptr align 4 %10, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  br label %65

65:                                               ; preds = %31, %26
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TPE_Body, ptr %66, i32 1
  store ptr %67, ptr %8, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %65
  %69 = load i16, ptr %9, align 2, !tbaa !14
  %70 = add i16 %69, 1
  store i16 %70, ptr %9, align 2, !tbaa !14
  br label %17, !llvm.loop !21

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

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"="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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!17, !10, i64 36}
!17 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !10, i64 36, !18, i64 40, !18, i64 56, !19, i64 72, !10, i64 108, !7, i64 112}
!18 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!19 = !{!"", !18, i64 0, !18, i64 16, !10, i64 32}
!20 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!21 = distinct !{!21, !22}
!22 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_vec3Plus(i64, i64, i64, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_createVecFromTo(i64, i64, i64, i64, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_worldApplyGravityCenter(ptr nocapture noundef readonly %0, i64 %1, i64 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i16, ptr %5, align 8, !tbaa !5
  %.not15 = icmp eq i16 %6, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %7 = load ptr, ptr %0, align 8, !tbaa !11
  br label %.lr.ph

._crit_edge:                                      ; preds = %26, %4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %8 = phi i16 [ %27, %26 ], [ %6, %.lr.ph.preheader ]
  %.014 = phi ptr [ %28, %26 ], [ %7, %.lr.ph.preheader ]
  %.01213 = phi i16 [ %29, %26 ], [ 0, %.lr.ph.preheader ]
  %9 = getelementptr inbounds i8, ptr %.014, i64 36
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %.not = icmp eq i32 %10, 2147483647
  br i1 %.not, label %26, label %11

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %.014, i64 56
  %13 = getelementptr inbounds i8, ptr %.014, i64 40
  %14 = load i64, ptr %13, align 8
  %15 = getelementptr inbounds i8, ptr %.014, i64 48
  %16 = load i64, ptr %15, align 8
  %17 = tail call { i64, i64 } @TPE_createVecFromTo(i64 %14, i64 %16, i64 %1, i64 %2, i32 noundef %3)
  %18 = extractvalue { i64, i64 } %17, 0
  %19 = extractvalue { i64, i64 } %17, 1
  %20 = load i64, ptr %12, align 8
  %21 = getelementptr inbounds i8, ptr %.014, i64 64
  %22 = load i64, ptr %21, align 8
  %23 = tail call { i64, i64 } @TPE_vec3Plus(i64 %20, i64 %22, i64 %18, i64 %19)
  %24 = extractvalue { i64, i64 } %23, 0
  %25 = extractvalue { i64, i64 } %23, 1
  store i64 %24, ptr %12, align 8
  store i64 %25, ptr %21, align 8
  %.pre = load i16, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %11, %.lr.ph
  %27 = phi i16 [ %.pre, %11 ], [ %8, %.lr.ph ]
  %28 = getelementptr inbounds i8, ptr %.014, i64 120
  %29 = add nuw i16 %.01213, 1
  %30 = icmp ult i16 %29, %27
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !17
}

attributes #0 = { 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" }

!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 = !{!13, !14, i64 36}
!13 = !{!"", !8, i64 0, !8, i64 4, !8, i64 16, !8, i64 32, !14, i64 36, !15, i64 40, !15, i64 56, !16, i64 72, !14, i64 108, !8, i64 112}
!14 = !{!"int", !8, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!16 = !{!"", !15, i64 0, !15, i64 16, !14, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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