; 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: 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_bodyGetOrientation(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_vec3DotProductPlain(i64, i64, i64, i64) #2

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

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

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TPE_Body, ptr %17, i32 0, i32 7
  %19 = getelementptr inbounds %struct.TPE_RotationState, ptr %18, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call { i64, i64 } @TPE_bodyGetOrientation(ptr noundef %20)
  %22 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %23 = extractvalue { i64, i64 } %21, 0
  store i64 %23, ptr %22, align 4
  %24 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %25 = extractvalue { i64, i64 } %21, 1
  store i64 %25, ptr %24, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  br label %26

26:                                               ; preds = %16, %4
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %41

29:                                               ; preds = %26
  %30 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = mul nsw i32 %31, -1
  store i32 %32, ptr %30, align 4, !tbaa !16
  %33 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = mul nsw i32 %34, -1
  store i32 %35, ptr %33, align 4, !tbaa !17
  %36 = getelementptr inbounds %struct.TPE_Vec4, ptr %5, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = mul nsw i32 %37, -1
  store i32 %38, ptr %36, align 4, !tbaa !18
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = mul nsw i32 %39, -1
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %29, %26
  call void @TPE_vec3Normalize(ptr noundef %5)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TPE_Body, ptr %42, i32 0, i32 9
  %44 = load i8, ptr %43, align 8, !tbaa !19
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 127
  %47 = load ptr, ptr %6, 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 { i64, i64 }, ptr %5, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %53 = load i64, ptr %52, align 4
  %54 = getelementptr inbounds { i64, i64 }, ptr %49, i32 0, i32 0
  %55 = load i64, ptr %54, align 8
  %56 = getelementptr inbounds { i64, i64 }, ptr %49, i32 0, i32 1
  %57 = load i64, ptr %56, align 8
  %58 = call i32 @TPE_vec3DotProductPlain(i64 %51, i64 %53, i64 %55, i64 %57)
  %59 = icmp sle i32 %58, 0
  %60 = zext i1 %59 to i32
  %61 = shl i32 %60, 7
  %62 = or i32 %46, %61
  %63 = trunc i32 %62 to i8
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TPE_Body, ptr %64, i32 0, i32 9
  store i8 %63, ptr %65, align 8, !tbaa !19
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TPE_Body, ptr %66, i32 0, i32 7
  %68 = getelementptr inbounds %struct.TPE_RotationState, ptr %67, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 4 %5, i64 16, i1 false), !tbaa.struct !15
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TPE_Body, ptr %70, i32 0, i32 7
  %72 = getelementptr inbounds %struct.TPE_RotationState, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct.TPE_Vec4, ptr %72, i32 0, i32 3
  store i32 %69, ptr %73, align 4, !tbaa !20
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.TPE_Body, ptr %74, i32 0, i32 7
  %76 = getelementptr inbounds %struct.TPE_RotationState, ptr %75, i32 0, i32 2
  store i32 0, ptr %76, align 8, !tbaa !11
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 104}
!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 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!16 = !{!13, !10, i64 0}
!17 = !{!13, !10, i64 4}
!18 = !{!13, !10, i64 8}
!19 = !{!12, !7, i64 112}
!20 = !{!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"

%struct.TPE_Vec4 = type { i32, i32, i32, i32 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_bodyGetOrientation(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodySetRotation(ptr noundef %0, i64 %1, i64 %2, i32 noundef %3) local_unnamed_addr #1 {
  %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 = getelementptr inbounds i8, ptr %0, i64 104
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %8, 0
  %9 = trunc i64 %1 to i32
  %10 = lshr i64 %1, 32
  %11 = trunc nuw i64 %10 to i32
  %12 = trunc i64 %2 to i32
  br i1 %.not, label %18, label %13

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 72
  %15 = tail call { i64, i64 } @TPE_bodyGetOrientation(ptr noundef nonnull %0)
  %16 = extractvalue { i64, i64 } %15, 0
  %17 = extractvalue { i64, i64 } %15, 1
  store i64 %16, ptr %14, align 8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 80
  store i64 %17, ptr %.sroa.4.0..sroa_idx, align 8
  br label %18

18:                                               ; preds = %13, %4
  %19 = icmp slt i32 %3, 0
  br i1 %19, label %20, label %26

20:                                               ; preds = %18
  %21 = sub nsw i32 0, %9
  store i32 %21, ptr %5, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %5, i64 4
  %23 = sub nsw i32 0, %11
  store i32 %23, ptr %22, align 4, !tbaa !13
  %24 = sub nsw i32 0, %12
  store i32 %24, ptr %6, align 8, !tbaa !14
  %25 = sub nsw i32 0, %3
  br label %26

26:                                               ; preds = %20, %18
  %.0 = phi i32 [ %25, %20 ], [ %3, %18 ]
  call void @TPE_vec3Normalize(ptr noundef nonnull %5)
  %27 = getelementptr inbounds i8, ptr %0, i64 112
  %28 = load i8, ptr %27, align 8, !tbaa !15
  %29 = and i8 %28, 127
  %30 = getelementptr inbounds i8, ptr %0, i64 88
  %31 = load i64, ptr %5, align 8
  %32 = load i64, ptr %6, align 8
  %33 = load i64, ptr %30, align 8
  %34 = getelementptr inbounds i8, ptr %0, i64 96
  %35 = load i64, ptr %34, align 8
  %36 = call i32 @TPE_vec3DotProductPlain(i64 %31, i64 %32, i64 %33, i64 %35)
  %.inv = icmp sgt i32 %36, 0
  %37 = select i1 %.inv, i8 0, i8 -128
  %38 = or disjoint i8 %37, %29
  store i8 %38, ptr %27, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %30, ptr noundef nonnull align 8 dereferenceable(16) %5, i64 16, i1 false), !tbaa.struct !16
  %39 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %.0, ptr %39, align 4, !tbaa !18
  store i32 0, ptr %7, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree 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" }

!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 104}
!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 = !{!10, !9, i64 0}
!13 = !{!10, !9, i64 4}
!14 = !{!10, !9, i64 8}
!15 = !{!6, !7, i64 112}
!16 = !{i64 0, i64 4, !17, i64 4, i64 4, !17, i64 8, i64 4, !17, i64 12, i64 4, !17}
!17 = !{!9, !9, i64 0}
!18 = !{!6, !9, i64 100}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,TailCallElimPass