; 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_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
declare dso_local i32 @TPE_vec3Len(i64, i64) #1

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

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

17:                                               ; preds = %1
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 512
  br i1 %19, label %20, label %23

20:                                               ; preds = %17, %1
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sdiv i32 %21, 512
  br label %24

23:                                               ; preds = %17
  br label %24

24:                                               ; preds = %23, %20
  %25 = phi i32 [ %22, %20 ], [ 1, %23 ]
  store i32 %25, ptr %3, align 4, !tbaa !9
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TPE_Body, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = mul nsw i32 %28, %29
  %31 = sdiv i32 %30, 1024
  store i32 %31, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = call i32 @TPE_bodyGetMaxExtent(ptr noundef %32)
  store i32 %33, ptr %4, align 4, !tbaa !9
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = call i32 @TPE_timesAntiZero(i32 noundef %34, i32 noundef %35)
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Body, ptr %37, i32 0, i32 7
  %39 = getelementptr inbounds %struct.TPE_RotationState, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.TPE_Vec4, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TPE_Body, ptr %42, i32 0, i32 7
  %44 = getelementptr inbounds %struct.TPE_RotationState, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds %struct.TPE_Vec4, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !15
  %47 = call i32 @TPE_timesAntiZero(i32 noundef %41, i32 noundef %46)
  %48 = call i32 @TPE_timesAntiZero(i32 noundef %36, i32 noundef %47)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TPE_Body, ptr %49, i32 0, i32 4
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = mul nsw i32 %48, %51
  %53 = sdiv i32 %52, 2560
  store i32 %53, ptr %4, align 4, !tbaa !9
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %64

56:                                               ; preds = %24
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TPE_Body, ptr %57, i32 0, i32 7
  %59 = getelementptr inbounds %struct.TPE_RotationState, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.TPE_Vec4, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 4, !tbaa !15
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %56
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %63, %56, %24
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %65, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %67
}

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

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, !10, i64 36}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !10, i64 36, !13, i64 40, !13, i64 56, !14, i64 72, !10, i64 108, !7, i64 112}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!14 = !{!"", !13, i64 0, !13, i64 16, !10, i64 32}
!15 = !{!12, !10, i64 100}


; 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 i32 @TPE_vec3Len(i64, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_bodyGetMaxExtent(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2936012, 2936012) i32 @TPE_bodyGetKineticEnergy(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load i64, ptr %2, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i64, ptr %4, align 8
  %6 = tail call i32 @TPE_vec3Len(i64 %3, i64 %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call i32 @TPE_bodyGetMaxExtent(ptr noundef %0)
  %10 = tail call i32 @TPE_timesAntiZero(i32 noundef %9, i32 noundef %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 100
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = tail call i32 @TPE_timesAntiZero(i32 noundef %12, i32 noundef %12)
  %14 = tail call i32 @TPE_timesAntiZero(i32 noundef %10, i32 noundef %13)
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = mul nsw i32 %15, %14
  %17 = sdiv i32 %16, 2560
  %.off = add i32 %16, 2559
  %18 = icmp ult i32 %.off, 5119
  br i1 %18, label %19, label %21

19:                                               ; preds = %1
  %20 = load i32, ptr %11, align 4, !tbaa !12
  %.not = icmp ne i32 %20, 0
  %spec.select19 = zext i1 %.not to i32
  br label %21

21:                                               ; preds = %19, %1
  %.0 = phi i32 [ %17, %1 ], [ %spec.select19, %19 ]
  %22 = icmp eq i32 %6, 0
  %23 = mul nsw i32 %6, %6
  %24 = icmp ugt i32 %23, 511
  %or.cond = select i1 %22, i1 true, i1 %24
  %25 = lshr i32 %23, 9
  %spec.select = select i1 %or.cond, i32 %25, i32 1
  %26 = mul nsw i32 %spec.select, %8
  %27 = sdiv i32 %26, 1024
  %28 = add nsw i32 %.0, %27
  ret i32 %28
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_timesAntiZero(i32 noundef, i32 noundef) local_unnamed_addr #0

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, !9, i64 36}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 16, !7, i64 32, !9, i64 36, !10, i64 40, !10, i64 56, !11, i64 72, !9, i64 108, !7, i64 112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12}
!11 = !{!"", !10, i64 0, !10, i64 16, !9, i64 32}
!12 = !{!6, !9, i64 100}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass