; 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_Vec3 = type { i32, i32, i32 }
%struct.TPE_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyRotateByAxis(ptr noundef %0, i64 %1, i32 %2) #2 {
  %4 = alloca %struct.TPE_Vec3, align 4
  %5 = alloca { i64, i32 }, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.TPE_Vec3, align 4
  %8 = alloca { i64, i32 }, align 8
  %9 = alloca i32, align 4
  %10 = alloca { i64, i32 }, align 4
  %11 = alloca i16, align 2
  %12 = alloca %struct.TPE_Vec3, align 4
  %13 = alloca { i64, i32 }, align 4
  %14 = alloca { i64, i32 }, align 4
  %15 = alloca { i64, i32 }, align 8
  %16 = alloca %struct.TPE_Vec3, align 4
  %17 = alloca %struct.TPE_Vec3, align 4
  %18 = alloca { i64, i32 }, align 4
  %19 = alloca { i64, i32 }, align 4
  %20 = alloca { i64, i32 }, align 8
  %21 = alloca { i64, i32 }, align 4
  %22 = alloca { i64, i32 }, align 4
  %23 = alloca { i64, i32 }, align 8
  %24 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %24, align 4
  %25 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %25, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %5, i64 12, i1 false)
  store ptr %0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef %26)
  store { i64, i32 } %27, ptr %8, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %8, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %4, i64 12, i1 false)
  %28 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  %29 = load i64, ptr %28, align 4
  %30 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  %31 = load i32, ptr %30, align 4
  %32 = call i32 @TPE_vec3Len(i64 %29, i32 %31)
  store i32 %32, ptr %9, align 4, !tbaa !9
  call void @TPE_vec3Normalize(ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  store i16 0, ptr %11, align 2, !tbaa !11
  br label %33

33:                                               ; preds = %85, %3
  %34 = load i16, ptr %11, align 2, !tbaa !11
  %35 = zext i16 %34 to i32
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TPE_Body, ptr %36, i32 0, i32 1
  %38 = load i8, ptr %37, align 8, !tbaa !13
  %39 = zext i8 %38 to i32
  %40 = icmp slt i32 %35, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  br label %88

42:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #3
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TPE_Body, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load i16, ptr %11, align 2, !tbaa !11
  %47 = zext i16 %46 to i64
  %48 = getelementptr inbounds %struct.TPE_Joint, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.TPE_Joint, ptr %48, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %49, i64 12, i1 false)
  %50 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %53 = load i32, ptr %52, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %7, i64 12, i1 false)
  %54 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %55 = load i64, ptr %54, align 4
  %56 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %57 = load i32, ptr %56, align 4
  %58 = call { i64, i32 } @TPE_vec3Minus(i64 %51, i32 %53, i64 %55, i32 %57)
  store { i64, i32 } %58, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 8 %15, i64 12, i1 false)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TPE_Body, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load i16, ptr %11, align 2, !tbaa !11
  %63 = zext i16 %62 to i64
  %64 = getelementptr inbounds %struct.TPE_Joint, ptr %61, i64 %63
  %65 = getelementptr inbounds %struct.TPE_Joint, ptr %64, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 12, ptr %16) #3
  %66 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %12, i64 12, i1 false)
  %67 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 0
  %68 = load i64, ptr %67, align 4
  %69 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 1
  %70 = load i32, ptr %69, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %4, i64 12, i1 false)
  %71 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 0
  %72 = load i64, ptr %71, align 4
  %73 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 1
  %74 = load i32, ptr %73, align 4
  %75 = call { i64, i32 } @_TPE_rotateByAxis(i64 %68, i32 %70, i64 %72, i32 %74, i32 noundef %66)
  store { i64, i32 } %75, ptr %20, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 8 %20, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr align 4 %7, i64 12, i1 false)
  %76 = getelementptr inbounds { i64, i32 }, ptr %21, i32 0, i32 0
  %77 = load i64, ptr %76, align 4
  %78 = getelementptr inbounds { i64, i32 }, ptr %21, i32 0, i32 1
  %79 = load i32, ptr %78, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %17, i64 12, i1 false)
  %80 = getelementptr inbounds { i64, i32 }, ptr %22, i32 0, i32 0
  %81 = load i64, ptr %80, align 4
  %82 = getelementptr inbounds { i64, i32 }, ptr %22, i32 0, i32 1
  %83 = load i32, ptr %82, align 4
  %84 = call { i64, i32 } @TPE_vec3Plus(i64 %77, i32 %79, i64 %81, i32 %83)
  store { i64, i32 } %84, ptr %23, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 8 %23, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %65, ptr align 4 %16, i64 12, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 12, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #3
  br label %85

85:                                               ; preds = %42
  %86 = load i16, ptr %11, align 2, !tbaa !11
  %87 = add i16 %86, 1
  store i16 %87, ptr %11, align 2, !tbaa !11
  br label %33, !llvm.loop !17

88:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !7, i64 8}
!14 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !12, i64 26, !12, i64 28, !12, i64 30, !7, i64 32, !7, i64 33}
!15 = !{!14, !6, i64 0}
!16 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!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_Vec3 = type { i32, i32, i32 }
%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @_TPE_rotateByAxis(i64, i32, i64, i32, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyRotateByAxis(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %4 = alloca %struct.TPE_Vec3, align 8
  store i64 %1, ptr %4, align 8
  %.sroa.243.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %2, ptr %.sroa.243.0..sroa_idx, align 8
  %5 = tail call { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef %0)
  %.fca.0.extract32 = extractvalue { i64, i32 } %5, 0
  %.fca.1.extract33 = extractvalue { i64, i32 } %5, 1
  %6 = tail call i32 @TPE_vec3Len(i64 %1, i32 %2)
  call void @TPE_vec3Normalize(ptr noundef nonnull %4)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i8, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.TPE_Joint, ptr %9, i64 %indvars.iv
  %.sroa.022.0.copyload = load i64, ptr %10, align 4
  %.sroa.223.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 8
  %.sroa.223.0.copyload = load i32, ptr %.sroa.223.0..sroa_idx, align 4
  %11 = call { i64, i32 } @TPE_vec3Minus(i64 %.sroa.022.0.copyload, i32 %.sroa.223.0.copyload, i64 %.fca.0.extract32, i32 %.fca.1.extract33)
  %.fca.0.extract16 = extractvalue { i64, i32 } %11, 0
  %.fca.1.extract17 = extractvalue { i64, i32 } %11, 1
  %12 = load ptr, ptr %0, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.TPE_Joint, ptr %12, i64 %indvars.iv
  %.sroa.09.0.copyload = load i64, ptr %4, align 8
  %.sroa.210.0.copyload = load i32, ptr %.sroa.243.0..sroa_idx, align 8
  %14 = call { i64, i32 } @_TPE_rotateByAxis(i64 %.fca.0.extract16, i32 %.fca.1.extract17, i64 %.sroa.09.0.copyload, i32 %.sroa.210.0.copyload, i32 noundef %6)
  %.fca.0.extract5 = extractvalue { i64, i32 } %14, 0
  %.fca.1.extract6 = extractvalue { i64, i32 } %14, 1
  %15 = call { i64, i32 } @TPE_vec3Plus(i64 %.fca.0.extract32, i32 %.fca.1.extract33, i64 %.fca.0.extract5, i32 %.fca.1.extract6)
  %.fca.0.extract = extractvalue { i64, i32 } %15, 0
  %.fca.1.extract = extractvalue { i64, i32 } %15, 1
  store i64 %.fca.0.extract, ptr %13, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 8
  store i32 %.fca.1.extract, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i8, ptr %7, align 8, !tbaa !5
  %17 = zext i8 %16 to i64
  %18 = icmp ult i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

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, !8, i64 8}
!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, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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