; 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_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_Vec4 = type { i32, i32, i32, i32 }
%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
define dso_local void @TPE_worldApplyGravityDown(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.TPE_World, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  store i16 0, ptr %6, align 2, !tbaa !14
  br label %10

10:                                               ; preds = %34, %2
  %11 = load i16, ptr %6, align 2, !tbaa !14
  %12 = zext i16 %11 to i32
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TPE_World, ptr %13, i32 0, i32 1
  %15 = load i16, ptr %14, align 8, !tbaa !15
  %16 = zext i16 %15 to i32
  %17 = icmp slt i32 %12, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  br label %37

19:                                               ; preds = %10
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TPE_Body, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = icmp ne i32 %22, 2147483647
  br i1 %23, label %24, label %31

24:                                               ; preds = %19
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TPE_Body, ptr %26, i32 0, i32 6
  %28 = getelementptr inbounds %struct.TPE_Vec4, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !20
  %30 = sub nsw i32 %29, %25
  store i32 %30, ptr %28, align 4, !tbaa !20
  br label %31

31:                                               ; preds = %24, %19
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TPE_Body, ptr %32, i32 1
  store ptr %33, ptr %5, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %31
  %35 = load i16, ptr %6, align 2, !tbaa !14
  %36 = add i16 %35, 1
  store i16 %36, ptr %6, align 2, !tbaa !14
  br label %10, !llvm.loop !21

37:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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, !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 = !{!17, !10, i64 60}
!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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @TPE_worldApplyGravityDown(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %.not10 = icmp eq i16 %4, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %xtraiter = and i16 %4, 1
  %6 = icmp eq i16 %4, 1
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i16 %4, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %25, %.lr.ph.preheader
  %.078.unr = phi ptr [ %5, %.lr.ph.preheader ], [ %26, %25 ]
  %lcmp.mod.not = icmp eq i16 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %7 = getelementptr inbounds i8, ptr %.078.unr, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %.not.epil = icmp eq i32 %8, 2147483647
  br i1 %.not.epil, label %._crit_edge, label %9

9:                                                ; preds = %.lr.ph.epil
  %10 = getelementptr inbounds i8, ptr %.078.unr, i64 60
  %11 = load i32, ptr %10, align 4, !tbaa !17
  %12 = sub nsw i32 %11, %1
  store i32 %12, ptr %10, align 4, !tbaa !17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %9, %.lr.ph.epil, %2
  ret void

.lr.ph:                                           ; preds = %25, %.lr.ph.preheader.new
  %.078 = phi ptr [ %5, %.lr.ph.preheader.new ], [ %26, %25 ]
  %niter = phi i16 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %25 ]
  %13 = getelementptr inbounds i8, ptr %.078, i64 36
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %.not = icmp eq i32 %14, 2147483647
  br i1 %.not, label %.lr.ph.1, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.078, i64 60
  %17 = load i32, ptr %16, align 4, !tbaa !17
  %18 = sub nsw i32 %17, %1
  store i32 %18, ptr %16, align 4, !tbaa !17
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %15, %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.078, i64 156
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %.not.1 = icmp eq i32 %20, 2147483647
  br i1 %.not.1, label %25, label %21

21:                                               ; preds = %.lr.ph.1
  %22 = getelementptr inbounds i8, ptr %.078, i64 180
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = sub nsw i32 %23, %1
  store i32 %24, ptr %22, align 4, !tbaa !17
  br label %25

25:                                               ; preds = %21, %.lr.ph.1
  %26 = getelementptr inbounds i8, ptr %.078, i64 240
  %niter.next.1 = add i16 %niter, 2
  %niter.ncmp.1 = icmp eq i16 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !18
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!13, !14, i64 60}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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