; 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: nounwind uwtable
declare dso_local i32 @TPE_sqrt(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @TPE_sign(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyMultiplyKineticEnergy(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  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 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp eq i32 %8, 2147483647
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %72

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TPE_Body, ptr %12, i32 0, i32 6
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TPE_Body, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %18 = load i64, ptr %17, align 8
  %19 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %20 = load i64, ptr %19, align 8
  call void @TPE_vec3Multiply(i64 %18, i64 %20, i32 noundef %14, ptr noundef %16)
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = mul nsw i32 %21, 512
  %23 = call i32 @TPE_sqrt(i32 noundef %22)
  store i32 %23, ptr %4, align 4, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TPE_Body, ptr %24, i32 0, i32 6
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TPE_Body, ptr %27, i32 0, i32 6
  %29 = getelementptr inbounds { i64, i64 }, ptr %25, i32 0, i32 0
  %30 = load i64, ptr %29, align 8
  %31 = getelementptr inbounds { i64, i64 }, ptr %25, i32 0, i32 1
  %32 = load i64, ptr %31, align 8
  call void @TPE_vec3Multiply(i64 %30, i64 %32, i32 noundef %26, ptr noundef %28)
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TPE_Body, ptr %33, i32 0, i32 7
  %35 = getelementptr inbounds %struct.TPE_RotationState, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.TPE_Vec4, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = call signext i8 @TPE_sign(i32 noundef %37)
  store i8 %38, ptr %5, align 1, !tbaa !16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TPE_Body, ptr %39, i32 0, i32 7
  %41 = getelementptr inbounds %struct.TPE_RotationState, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.TPE_Vec4, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = mul nsw i32 %43, %44
  %46 = sdiv i32 %45, 512
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TPE_Body, ptr %47, i32 0, i32 7
  %49 = getelementptr inbounds %struct.TPE_RotationState, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds %struct.TPE_Vec4, ptr %49, i32 0, i32 3
  store i32 %46, ptr %50, align 4, !tbaa !15
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %71

53:                                               ; preds = %11
  %54 = load i8, ptr %5, align 1, !tbaa !16
  %55 = sext i8 %54 to i32
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %71

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

64:                                               ; preds = %57
  %65 = load i8, ptr %5, align 1, !tbaa !16
  %66 = sext i8 %65 to i32
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TPE_Body, ptr %67, i32 0, i32 7
  %69 = getelementptr inbounds %struct.TPE_RotationState, ptr %68, i32 0, i32 1
  %70 = getelementptr inbounds %struct.TPE_Vec4, ptr %69, i32 0, i32 3
  store i32 %66, ptr %70, align 4, !tbaa !15
  br label %71

71:                                               ; preds = %64, %57, %53, %11
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  br label %72

72:                                               ; preds = %71, %10
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Multiply(i64, i64, i32 noundef, ptr noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}
!16 = !{!7, !7, i64 0}


; 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_sqrt(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @TPE_sign(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyMultiplyKineticEnergy(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 2147483647
  br i1 %5, label %26, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load i64, ptr %7, align 8
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load i64, ptr %9, align 8
  tail call void @TPE_vec3Multiply(i64 %8, i64 %10, i32 noundef %1, ptr noundef nonnull %7)
  %11 = shl nsw i32 %1, 9
  %12 = tail call i32 @TPE_sqrt(i32 noundef %11)
  %13 = load i64, ptr %7, align 8
  %14 = load i64, ptr %9, align 8
  tail call void @TPE_vec3Multiply(i64 %13, i64 %14, i32 noundef %12, ptr noundef nonnull %7)
  %15 = getelementptr inbounds i8, ptr %0, i64 100
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = tail call signext i8 @TPE_sign(i32 noundef %16)
  %18 = load i32, ptr %15, align 4, !tbaa !12
  %19 = mul nsw i32 %18, %12
  %20 = sdiv i32 %19, 512
  store i32 %20, ptr %15, align 4, !tbaa !12
  %21 = icmp ne i32 %12, 0
  %22 = icmp ne i8 %17, 0
  %or.cond = select i1 %21, i1 %22, i1 false
  %.off = add i32 %19, 511
  %23 = icmp ult i32 %.off, 1023
  %or.cond18 = select i1 %or.cond, i1 %23, i1 false
  br i1 %or.cond18, label %24, label %26

24:                                               ; preds = %6
  %25 = sext i8 %17 to i32
  store i32 %25, ptr %15, align 4, !tbaa !12
  br label %26

26:                                               ; preds = %6, %24, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Multiply(i64, i64, i32 noundef, ptr 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,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass