; 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: nounwind uwtable
declare dso_local { i64, i32 } @TPE_vec3(i32 noundef, i32 noundef, i32 noundef) #1

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

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

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

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

16:                                               ; preds = %39, %1
  %17 = load i16, ptr %6, align 2, !tbaa !12
  %18 = zext i16 %17 to i32
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TPE_Body, ptr %19, i32 0, i32 1
  %21 = load i8, ptr %20, align 8, !tbaa !13
  %22 = zext i8 %21 to i32
  %23 = icmp slt i32 %18, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  br label %42

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TPE_Joint, ptr %26, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %2, i64 12, i1 false)
  %28 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %29 = load i64, ptr %28, align 4
  %30 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %31 = load i32, ptr %30, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %27, i64 12, i1 false)
  %32 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 0
  %33 = load i64, ptr %32, align 4
  %34 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 1
  %35 = load i32, ptr %34, align 4
  %36 = call { i64, i32 } @TPE_vec3Plus(i64 %29, i32 %31, i64 %33, i32 %35)
  store { i64, i32 } %36, ptr %10, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %10, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Joint, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %25
  %40 = load i16, ptr %6, align 2, !tbaa !12
  %41 = add i16 %40, 1
  store i16 %41, ptr %6, align 2, !tbaa !12
  br label %16, !llvm.loop !17

42:                                               ; preds = %24
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TPE_Body, ptr %43, i32 0, i32 1
  %45 = load i8, ptr %44, align 8, !tbaa !13
  %46 = zext i8 %45 to i32
  %47 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !19
  %49 = sdiv i32 %48, %46
  store i32 %49, ptr %47, align 4, !tbaa !19
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TPE_Body, ptr %50, i32 0, i32 1
  %52 = load i8, ptr %51, align 8, !tbaa !13
  %53 = zext i8 %52 to i32
  %54 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !21
  %56 = sdiv i32 %55, %53
  store i32 %56, ptr %54, align 4, !tbaa !21
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TPE_Body, ptr %57, i32 0, i32 1
  %59 = load i8, ptr %58, align 8, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 2
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = sdiv i32 %62, %60
  store i32 %63, ptr %61, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 4 %2, i64 12, i1 false)
  %64 = load { i64, i32 }, ptr %11, align 8
  ret { i64, i32 } %64
}

attributes #0 = { 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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !11, i64 26, !11, i64 28, !11, i64 30, !7, i64 32, !7, i64 33}
!11 = !{!"short", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !7, i64 8}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !16, i64 0}
!20 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8}
!21 = !{!20, !16, i64 4}
!22 = !{!20, !16, i64 8}


; 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 { i64, i32 } @TPE_vec3(i32 noundef, i32 noundef, i32 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
define dso_local { i64, i32 } @TPE_bodyGetCenterOfMass(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call { i64, i32 } @TPE_vec3(i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.8.035 = extractvalue { i64, i32 } %2, 1
  %.sroa.019.0.in36 = extractvalue { i64, i32 } %2, 0
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %6 = zext i8 %13 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.sroa.8.0.lcssa = phi i32 [ %.sroa.8.035, %1 ], [ %.sroa.8.0, %._crit_edge.loopexit ]
  %.sroa.019.0.in.lcssa = phi i64 [ %.sroa.019.0.in36, %1 ], [ %.sroa.019.0.in, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ 0, %1 ], [ %6, %._crit_edge.loopexit ]
  %.sroa.019.0 = trunc i64 %.sroa.019.0.in.lcssa to i32
  %.sroa.6.0.in = lshr i64 %.sroa.019.0.in.lcssa, 32
  %.sroa.6.0 = trunc nuw i64 %.sroa.6.0.in to i32
  %7 = sdiv i32 %.sroa.019.0, %.lcssa
  %8 = sdiv i32 %.sroa.6.0, %.lcssa
  %9 = sdiv i32 %.sroa.8.0.lcssa, %.lcssa
  %.sroa.6.0.insert.ext = zext i32 %8 to i64
  %.sroa.6.0.insert.shift = shl nuw i64 %.sroa.6.0.insert.ext, 32
  %.sroa.019.0.insert.ext = zext i32 %7 to i64
  %.sroa.019.0.insert.insert = or disjoint i64 %.sroa.6.0.insert.shift, %.sroa.019.0.insert.ext
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.019.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %9, 1
  ret { i64, i32 } %.fca.1.insert

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.sroa.019.0.in40 = phi i64 [ %.sroa.019.0.in, %.lr.ph ], [ %.sroa.019.0.in36, %.lr.ph.preheader ]
  %.sroa.8.039 = phi i32 [ %.sroa.8.0, %.lr.ph ], [ %.sroa.8.035, %.lr.ph.preheader ]
  %.038 = phi ptr [ %11, %.lr.ph ], [ %5, %.lr.ph.preheader ]
  %.03237 = phi i16 [ %12, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.sroa.03.0.copyload = load i64, ptr %.038, align 4
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %.038, i64 8
  %.sroa.24.0.copyload = load i32, ptr %.sroa.24.0..sroa_idx, align 4
  %10 = tail call { i64, i32 } @TPE_vec3Plus(i64 %.sroa.019.0.in40, i32 %.sroa.8.039, i64 %.sroa.03.0.copyload, i32 %.sroa.24.0.copyload)
  %11 = getelementptr inbounds i8, ptr %.038, i64 20
  %12 = add nuw nsw i16 %.03237, 1
  %.sroa.8.0 = extractvalue { i64, i32 } %10, 1
  %.sroa.019.0.in = extractvalue { i64, i32 } %10, 0
  %13 = load i8, ptr %3, align 8, !tbaa !5
  %14 = zext i8 %13 to i16
  %15 = icmp ult i16 %12, %14
  br i1 %15, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12
}

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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass