; 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 }

@_TPE_joint1Index = external dso_local global i16, align 2

; 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: inlinehint nounwind uwtable
declare hidden i32 @TPE_dist(i64, i32, i64, i32) #2

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

38:                                               ; preds = %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %13, align 4
  br label %103

39:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #4
  store i8 0, ptr %14, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %15) #4
  store i16 0, ptr %15, align 2, !tbaa !12
  br label %40

40:                                               ; preds = %98, %39
  %41 = load i16, ptr %15, align 2, !tbaa !12
  %42 = zext i16 %41 to i32
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TPE_Body, ptr %43, i32 0, i32 1
  %45 = load i8, ptr %44, align 8, !tbaa !14
  %46 = zext i8 %45 to i32
  %47 = icmp slt i32 %42, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %40
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #4
  br label %101

49:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 12, ptr %16) #4
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TPE_Body, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  %53 = load i16, ptr %15, align 2, !tbaa !12
  %54 = zext i16 %53 to i64
  %55 = getelementptr inbounds %struct.TPE_Joint, ptr %52, i64 %54
  %56 = getelementptr inbounds %struct.TPE_Joint, ptr %55, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %56, i64 12, i1 false), !tbaa.struct !17
  %57 = load i16, ptr %15, align 2, !tbaa !12
  store i16 %57, ptr @_TPE_joint1Index, align 2, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %17) #4
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TPE_Body, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = load i16, ptr %15, align 2, !tbaa !12
  %62 = zext i16 %61 to i32
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %struct.TPE_Joint, ptr %60, i64 %63
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TPE_Body, ptr %65, i32 0, i32 6
  %67 = load i16, ptr %66, align 2, !tbaa !18
  %68 = sext i16 %67 to i32
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TPE_Body, ptr %69, i32 0, i32 5
  %71 = load i16, ptr %70, align 4, !tbaa !19
  %72 = sext i16 %71 to i32
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = call zeroext i8 @TPE_jointEnvironmentResolveCollision(ptr noundef %64, i32 noundef %68, i32 noundef %72, ptr noundef %73)
  store i8 %74, ptr %17, align 1, !tbaa !11
  %75 = load i8, ptr %17, align 1, !tbaa !11
  %76 = icmp ne i8 %75, 0
  br i1 %76, label %77, label %97

77:                                               ; preds = %49
  store i8 1, ptr %14, align 1, !tbaa !11
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.TPE_Body, ptr %78, i32 0, i32 7
  %80 = load i8, ptr %79, align 8, !tbaa !20
  %81 = zext i8 %80 to i32
  %82 = and i32 %81, 2
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %96

84:                                               ; preds = %77
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load i16, ptr %15, align 2, !tbaa !12
  %87 = load i8, ptr %17, align 1, !tbaa !11
  %88 = zext i8 %87 to i32
  %89 = icmp eq i32 %88, 1
  %90 = zext i1 %89 to i32
  %91 = trunc i32 %90 to i8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %16, i64 12, i1 false)
  %92 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 0
  %93 = load i64, ptr %92, align 4
  %94 = getelementptr inbounds { i64, i32 }, ptr %18, i32 0, i32 1
  %95 = load i32, ptr %94, align 4
  call void @_TPE_bodyNonrotatingJointCollided(ptr noundef %85, i16 noundef signext %86, i64 %93, i32 %95, i8 noundef zeroext %91)
  br label %96

96:                                               ; preds = %84, %77
  br label %97

97:                                               ; preds = %96, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %16) #4
  br label %98

98:                                               ; preds = %97
  %99 = load i16, ptr %15, align 2, !tbaa !12
  %100 = add i16 %99, 1
  store i16 %100, ptr %15, align 2, !tbaa !12
  br label %40, !llvm.loop !21

101:                                              ; preds = %48
  %102 = load i8, ptr %14, align 1, !tbaa !11
  store i8 %102, ptr %3, align 1
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #4
  br label %103

103:                                              ; preds = %101, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #4
  %104 = load i8, ptr %3, align 1
  ret i8 %104
}

; Function Attrs: nounwind uwtable
declare dso_local void @_TPE_bodyNonrotatingJointCollided(ptr noundef, i16 noundef signext, i64, i32, i8 noundef zeroext) #3

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @TPE_jointEnvironmentResolveCollision(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodyGetFastBSphere(ptr noundef, ptr noundef, ptr noundef) #3

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

@_TPE_joint1Index = external dso_local local_unnamed_addr global i16, align 2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_dist(i64, i32, i64, i32) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @TPE_bodyEnvironmentResolveCollision(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.TPE_Vec3, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @TPE_bodyGetFastBSphere(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.sroa.016.0.copyload = load i64, ptr %3, align 8
  %.sroa.217.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.217.0.copyload = load i32, ptr %.sroa.217.0..sroa_idx, align 8
  %6 = call { i64, i32 } %1(i64 %.sroa.016.0.copyload, i32 %.sroa.217.0.copyload, i32 noundef %5) #3
  %.fca.0.extract = extractvalue { i64, i32 } %6, 0
  %.fca.1.extract = extractvalue { i64, i32 } %6, 1
  %.sroa.012.0.copyload = load i64, ptr %3, align 8
  %.sroa.213.0.copyload = load i32, ptr %.sroa.217.0..sroa_idx, align 8
  %7 = call i32 @TPE_dist(i64 %.sroa.012.0.copyload, i32 %.sroa.213.0.copyload, i64 %.fca.0.extract, i32 %.fca.1.extract)
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp sgt i32 %7, %8
  br i1 %9, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i8, ptr %10, align 8, !tbaa !9
  %.not37 = icmp eq i8 %11, 0
  br i1 %.not37, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 30
  %13 = getelementptr inbounds i8, ptr %0, i64 28
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  br label %15

15:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %.03036 = phi i8 [ 0, %.lr.ph ], [ %.1, %30 ]
  %16 = load ptr, ptr %0, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct.TPE_Joint, ptr %16, i64 %indvars.iv
  %.sroa.02.0.copyload = load i64, ptr %17, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %17, i64 8
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %18 = trunc nuw nsw i64 %indvars.iv to i16
  store i16 %18, ptr @_TPE_joint1Index, align 2, !tbaa !14
  %19 = load i16, ptr %12, align 2, !tbaa !15
  %20 = sext i16 %19 to i32
  %21 = load i16, ptr %13, align 4, !tbaa !16
  %22 = sext i16 %21 to i32
  %23 = call zeroext i8 @TPE_jointEnvironmentResolveCollision(ptr noundef nonnull %17, i32 noundef %20, i32 noundef %22, ptr noundef %1)
  %.not = icmp eq i8 %23, 0
  br i1 %.not, label %30, label %24

24:                                               ; preds = %15
  %25 = load i8, ptr %14, align 8, !tbaa !17
  %26 = and i8 %25, 2
  %.not34 = icmp eq i8 %26, 0
  br i1 %.not34, label %30, label %27

27:                                               ; preds = %24
  %28 = icmp eq i8 %23, 1
  %29 = zext i1 %28 to i8
  call void @_TPE_bodyNonrotatingJointCollided(ptr noundef nonnull %0, i16 noundef signext %18, i64 %.sroa.02.0.copyload, i32 %.sroa.4.0.copyload, i8 noundef zeroext %29)
  br label %30

30:                                               ; preds = %24, %27, %15
  %.1 = phi i8 [ 1, %27 ], [ 1, %24 ], [ %.03036, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i8, ptr %10, align 8, !tbaa !9
  %32 = zext i8 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %15, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %30, %.preheader, %2
  %.0 = phi i8 [ 0, %2 ], [ 0, %.preheader ], [ %.1, %30 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  ret i8 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local void @_TPE_bodyNonrotatingJointCollided(ptr noundef, i16 noundef signext, i64, i32, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @TPE_jointEnvironmentResolveCollision(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 8}
!10 = !{!"", !11, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !12, i64 26, !12, i64 28, !12, i64 30, !7, i64 32, !7, i64 33}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 30}
!16 = !{!10, !12, i64 28}
!17 = !{!10, !7, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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