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

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

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

20:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  br label %54

21:                                               ; preds = %12
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TPE_Joint, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [3 x i16], ptr %23, i64 0, i64 0
  %25 = load i16, ptr %24, align 4, !tbaa !12
  %26 = sext i16 %25 to i32
  %27 = call i32 @TPE_abs(i32 noundef %26)
  %28 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = add nsw i32 %29, %27
  store i32 %30, ptr %28, align 4, !tbaa !14
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TPE_Joint, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds [3 x i16], ptr %32, i64 0, i64 1
  %34 = load i16, ptr %33, align 2, !tbaa !12
  %35 = sext i16 %34 to i32
  %36 = call i32 @TPE_abs(i32 noundef %35)
  %37 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !17
  %39 = add nsw i32 %38, %36
  store i32 %39, ptr %37, align 4, !tbaa !17
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TPE_Joint, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds [3 x i16], ptr %41, i64 0, i64 2
  %43 = load i16, ptr %42, align 4, !tbaa !12
  %44 = sext i16 %43 to i32
  %45 = call i32 @TPE_abs(i32 noundef %44)
  %46 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !18
  %48 = add nsw i32 %47, %45
  store i32 %48, ptr %46, align 4, !tbaa !18
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TPE_Joint, ptr %49, i32 1
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %21
  %52 = load i16, ptr %6, align 2, !tbaa !12
  %53 = add i16 %52, 1
  store i16 %53, ptr %6, align 2, !tbaa !12
  br label %12, !llvm.loop !19

54:                                               ; preds = %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %3, i64 12, i1 false)
  %55 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  %56 = load i64, ptr %55, align 4
  %57 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  %58 = load i32, ptr %57, align 4
  %59 = call i32 @TPE_vec3LenApprox(i64 %56, i32 %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %3) #4
  ret i32 %59
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_abs(i32 noundef) #3

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 = { inlinehint 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 #4 = { 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 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !16, i64 4}
!18 = !{!15, !16, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; 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 i32 @TPE_vec3LenApprox(i64, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @TPE_bodyGetNetSpeed(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)
  %.fca.0.extract = extractvalue { i64, i32 } %2, 0
  %.fca.1.extract = extractvalue { i64, i32 } %2, 1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %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:                                      ; preds = %.lr.ph, %1
  %.sroa.07.0.lcssa = phi i64 [ %.fca.0.extract, %1 ], [ %.sroa.07.4.insert.insert, %.lr.ph ]
  %.sroa.8.0.lcssa = phi i32 [ %.fca.1.extract, %1 ], [ %21, %.lr.ph ]
  %6 = tail call i32 @TPE_vec3LenApprox(i64 %.sroa.07.0.lcssa, i32 %.sroa.8.0.lcssa)
  ret i32 %6

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.sroa.8.016 = phi i32 [ %21, %.lr.ph ], [ %.fca.1.extract, %.lr.ph.preheader ]
  %.sroa.07.015 = phi i64 [ %.sroa.07.4.insert.insert, %.lr.ph ], [ %.fca.0.extract, %.lr.ph.preheader ]
  %.014 = phi i16 [ %23, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.01213 = phi ptr [ %22, %.lr.ph ], [ %5, %.lr.ph.preheader ]
  %7 = getelementptr inbounds i8, ptr %.01213, i64 12
  %8 = load i16, ptr %7, align 4, !tbaa !12
  %9 = sext i16 %8 to i32
  %10 = tail call i32 @TPE_abs(i32 noundef %9)
  %.sroa.07.0.extract.trunc = trunc i64 %.sroa.07.015 to i32
  %11 = add nsw i32 %10, %.sroa.07.0.extract.trunc
  %.sroa.07.0.insert.ext = zext i32 %11 to i64
  %12 = getelementptr inbounds i8, ptr %.01213, i64 14
  %13 = load i16, ptr %12, align 2, !tbaa !12
  %14 = sext i16 %13 to i32
  %15 = tail call i32 @TPE_abs(i32 noundef %14)
  %.sroa.07.4.extract.shift = lshr i64 %.sroa.07.015, 32
  %.sroa.07.4.extract.trunc = trunc nuw i64 %.sroa.07.4.extract.shift to i32
  %16 = add nsw i32 %15, %.sroa.07.4.extract.trunc
  %.sroa.07.4.insert.ext = zext i32 %16 to i64
  %.sroa.07.4.insert.shift = shl nuw i64 %.sroa.07.4.insert.ext, 32
  %.sroa.07.4.insert.insert = or disjoint i64 %.sroa.07.4.insert.shift, %.sroa.07.0.insert.ext
  %17 = getelementptr inbounds i8, ptr %.01213, i64 16
  %18 = load i16, ptr %17, align 4, !tbaa !12
  %19 = sext i16 %18 to i32
  %20 = tail call i32 @TPE_abs(i32 noundef %19)
  %21 = add nsw i32 %20, %.sroa.8.016
  %22 = getelementptr inbounds i8, ptr %.01213, i64 20
  %23 = add nuw nsw i16 %.014, 1
  %24 = load i8, ptr %3, align 8, !tbaa !5
  %25 = zext i8 %24 to i16
  %26 = icmp ult i16 %23, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_abs(i32 noundef) local_unnamed_addr #1

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 = { inlinehint 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 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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