; LLVM IR from ESPboy-edu/ESPboy_tinyphysicsengine :: programs (hello)

; 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_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, 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_bodyApplyGravity(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.TPE_Body, ptr %6, i32 0, i32 7
  %8 = load i8, ptr %7, align 8, !tbaa !11
  %9 = zext i8 %8 to i32
  %10 = and i32 %9, 1
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %19, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TPE_Body, ptr %13, i32 0, i32 7
  %15 = load i8, ptr %14, align 8, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = and i32 %16, 4
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %12, %2
  br label %47

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !14
  br label %21

21:                                               ; preds = %44, %20
  %22 = load i16, ptr %5, align 2, !tbaa !14
  %23 = zext i16 %22 to i32
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TPE_Body, ptr %24, i32 0, i32 1
  %26 = load i8, ptr %25, align 8, !tbaa !15
  %27 = zext i8 %26 to i32
  %28 = icmp slt i32 %23, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  br label %47

30:                                               ; preds = %21
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TPE_Body, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load i16, ptr %5, align 2, !tbaa !14
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds %struct.TPE_Joint, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.TPE_Joint, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds [3 x i16], ptr %38, i64 0, i64 1
  %40 = load i16, ptr %39, align 2, !tbaa !14
  %41 = sext i16 %40 to i32
  %42 = sub nsw i32 %41, %31
  %43 = trunc i32 %42 to i16
  store i16 %43, ptr %39, align 2, !tbaa !14
  br label %44

44:                                               ; preds = %30
  %45 = load i16, ptr %5, align 2, !tbaa !14
  %46 = add i16 %45, 1
  store i16 %46, ptr %5, align 2, !tbaa !14
  br label %21, !llvm.loop !17

47:                                               ; preds = %29, %19
  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, !7, i64 32}
!12 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !13, i64 26, !13, i64 28, !13, i64 30, !7, i64 32, !7, i64 33}
!13 = !{!"short", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !7, i64 8}
!16 = !{!12, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @TPE_bodyApplyGravity(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %5 = and i8 %4, 5
  %or.cond = icmp eq i8 %5, 0
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i8, ptr %6, align 8, !tbaa !11
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = trunc i32 %1 to i16
  %wide.trip.count = zext i8 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %10 = icmp ult i8 %7, 4
  br i1 %10, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 252
  br label %11

11:                                               ; preds = %11, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %11 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %11 ]
  %12 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv, i32 1, i64 1
  %13 = load i16, ptr %12, align 2, !tbaa !13
  %14 = sub i16 %13, %9
  store i16 %14, ptr %12, align 2, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %15 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv.next, i32 1, i64 1
  %16 = load i16, ptr %15, align 2, !tbaa !13
  %17 = sub i16 %16, %9
  store i16 %17, ptr %15, align 2, !tbaa !13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %18 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv.next.1, i32 1, i64 1
  %19 = load i16, ptr %18, align 2, !tbaa !13
  %20 = sub i16 %19, %9
  store i16 %20, ptr %18, align 2, !tbaa !13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %21 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv.next.2, i32 1, i64 1
  %22 = load i16, ptr %21, align 2, !tbaa !13
  %23 = sub i16 %22, %9
  store i16 %23, ptr %21, align 2, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %11, !llvm.loop !14

.loopexit.loopexit.unr-lcssa:                     ; preds = %11, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %11 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %24 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv.epil, i32 1, i64 1
  %25 = load i16, ptr %24, align 2, !tbaa !13
  %26 = sub i16 %25, %9
  store i16 %26, ptr %24, align 2, !tbaa !13
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.epil.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %2
  ret void
}

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, !8, i64 32}
!6 = !{!"", !7, i64 0, !8, i64 8, !7, i64 16, !8, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !8, i64 32, !8, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !8, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


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