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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Add(i64, i64, i64, i64, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyAddRotation(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3) #0 {
  %5 = alloca %struct.TPE_Vec4, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %8, align 4
  %9 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  store i64 %2, ptr %9, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %4
  br label %104

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TPE_Body, ptr %14, i32 0, i32 7
  %16 = getelementptr inbounds %struct.TPE_RotationState, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.TPE_Vec4, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TPE_Body, ptr %19, i32 0, i32 7
  %21 = getelementptr inbounds %struct.TPE_RotationState, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.TPE_Vec4, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = mul nsw i32 %18, %23
  %25 = sdiv i32 %24, 512
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TPE_Body, ptr %26, i32 0, i32 7
  %28 = getelementptr inbounds %struct.TPE_RotationState, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.TPE_Vec4, ptr %28, i32 0, i32 0
  store i32 %25, ptr %29, align 8, !tbaa !11
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TPE_Body, ptr %30, i32 0, i32 7
  %32 = getelementptr inbounds %struct.TPE_RotationState, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.TPE_Vec4, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TPE_Body, ptr %35, i32 0, i32 7
  %37 = getelementptr inbounds %struct.TPE_RotationState, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.TPE_Vec4, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = mul nsw i32 %34, %39
  %41 = sdiv i32 %40, 512
  %42 = load ptr, ptr %6, 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 1
  store i32 %41, ptr %45, align 4, !tbaa !16
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TPE_Body, ptr %46, i32 0, i32 7
  %48 = getelementptr inbounds %struct.TPE_RotationState, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.TPE_Vec4, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TPE_Body, ptr %51, i32 0, i32 7
  %53 = getelementptr inbounds %struct.TPE_RotationState, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.TPE_Vec4, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = mul nsw i32 %50, %55
  %57 = sdiv i32 %56, 512
  %58 = load ptr, ptr %6, 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 2
  store i32 %57, ptr %61, align 8, !tbaa !17
  call void @TPE_vec3Normalize(ptr noundef %5)
  %62 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !18
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = mul nsw i32 %63, %64
  %66 = sdiv i32 %65, 512
  %67 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 0
  store i32 %66, ptr %67, align 4, !tbaa !18
  %68 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !19
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = mul nsw i32 %69, %70
  %72 = sdiv i32 %71, 512
  %73 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 1
  store i32 %72, ptr %73, align 4, !tbaa !19
  %74 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 2
  %75 = load i32, ptr %74, align 4, !tbaa !20
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = mul nsw i32 %75, %76
  %78 = sdiv i32 %77, 512
  %79 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 2
  store i32 %78, ptr %79, align 4, !tbaa !20
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TPE_Body, ptr %80, i32 0, i32 7
  %82 = getelementptr inbounds %struct.TPE_RotationState, ptr %81, i32 0, i32 1
  %83 = getelementptr inbounds { i64, i64 }, ptr %82, i32 0, i32 0
  %84 = load i64, ptr %83, align 8
  %85 = getelementptr inbounds { i64, i64 }, ptr %82, i32 0, i32 1
  %86 = load i64, ptr %85, align 8
  %87 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %88 = load i64, ptr %87, align 4
  %89 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %90 = load i64, ptr %89, align 4
  call void @TPE_vec3Add(i64 %84, i64 %86, i64 %88, i64 %90, ptr noundef %5)
  %91 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %92 = load i64, ptr %91, align 4
  %93 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %94 = load i64, ptr %93, align 4
  %95 = call i32 @TPE_vec3Len(i64 %92, i64 %94)
  %96 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 3
  store i32 %95, ptr %96, align 4, !tbaa !21
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 3
  %99 = load i32, ptr %98, align 4, !tbaa !21
  %100 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %101 = load i64, ptr %100, align 4
  %102 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %103 = load i64, ptr %102, align 4
  call void @TPE_bodySetRotation(ptr noundef %97, i64 %101, i64 %103, i32 noundef %99)
  br label %104

104:                                              ; preds = %13, %12
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Normalize(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodySetRotation(ptr noundef, i64, i64, i32 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" }

!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 88}
!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 = !{!12, !10, i64 92}
!17 = !{!12, !10, i64 96}
!18 = !{!13, !10, i64 0}
!19 = !{!13, !10, i64 4}
!20 = !{!13, !10, i64 8}
!21 = !{!13, !10, i64 12}


; 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_Vec4 = type { i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Add(i64, i64, i64, i64, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyAddRotation(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.TPE_Vec4, align 8
  store i64 %1, ptr %5, align 8
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %2, ptr %6, align 8
  %7 = icmp eq i32 %3, 0
  br i1 %7, label %41, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 88
  %10 = getelementptr inbounds i8, ptr %0, i64 100
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load <2 x i32>, ptr %9, align 8, !tbaa !12
  %13 = insertelement <2 x i32> poison, i32 %11, i64 0
  %14 = shufflevector <2 x i32> %13, <2 x i32> poison, <2 x i32> zeroinitializer
  %15 = mul nsw <2 x i32> %12, %14
  %16 = sdiv <2 x i32> %15, <i32 512, i32 512>
  store <2 x i32> %16, ptr %9, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = mul nsw i32 %18, %11
  %20 = sdiv i32 %19, 512
  store i32 %20, ptr %17, align 8, !tbaa !13
  call void @TPE_vec3Normalize(ptr noundef nonnull %5)
  %21 = load i32, ptr %5, align 8, !tbaa !14
  %22 = mul nsw i32 %21, %3
  %23 = sdiv i32 %22, 512
  store i32 %23, ptr %5, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %5, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = mul nsw i32 %25, %3
  %27 = sdiv i32 %26, 512
  store i32 %27, ptr %24, align 4, !tbaa !15
  %28 = load i32, ptr %6, align 8, !tbaa !16
  %29 = mul nsw i32 %28, %3
  %30 = sdiv i32 %29, 512
  store i32 %30, ptr %6, align 8, !tbaa !16
  %31 = load i64, ptr %9, align 8
  %32 = load i64, ptr %17, align 8
  %33 = load i64, ptr %5, align 8
  %34 = load i64, ptr %6, align 8
  call void @TPE_vec3Add(i64 %31, i64 %32, i64 %33, i64 %34, ptr noundef nonnull %5)
  %35 = load i64, ptr %5, align 8
  %36 = load i64, ptr %6, align 8
  %37 = call i32 @TPE_vec3Len(i64 %35, i64 %36)
  %38 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %37, ptr %38, align 4, !tbaa !17
  %39 = load i64, ptr %5, align 8
  %40 = load i64, ptr %6, align 8
  call void @TPE_bodySetRotation(ptr noundef %0, i64 %39, i64 %40, i32 noundef %37)
  br label %41

41:                                               ; preds = %4, %8
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodySetRotation(ptr noundef, i64, i64, 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 100}
!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 = !{!9, !9, i64 0}
!13 = !{!6, !9, i64 96}
!14 = !{!10, !9, i64 0}
!15 = !{!10, !9, i64 4}
!16 = !{!10, !9, i64 8}
!17 = !{!10, !9, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass