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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @TPE_bodyEnvironmentCollide(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.TPE_Vec3, align 4
  %11 = alloca { i64, i32 }, align 4
  %12 = alloca { i64, i32 }, align 8
  %13 = alloca { i64, i32 }, align 4
  %14 = 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 2, ptr %6) #4
  store i16 0, ptr %6, align 2, !tbaa !9
  br label %15

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

23:                                               ; preds = %15
  store i32 2, ptr %7, align 4
  br label %67

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TPE_Body, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i16, ptr %6, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.TPE_Joint, ptr %27, i64 %30
  store ptr %31, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TPE_Joint, ptr %32, i32 0, i32 2
  %34 = load i8, ptr %33, align 2, !tbaa !14
  %35 = zext i8 %34 to i32
  %36 = mul nsw i32 %35, 32
  store i32 %36, ptr %9, align 4, !tbaa !18
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Joint, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TPE_Joint, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %9, align 4, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %41, i64 12, i1 false)
  %43 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %44 = load i64, ptr %43, align 4
  %45 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %46 = load i32, ptr %45, align 4
  %47 = call { i64, i32 } %39(i64 %44, i32 %46, i32 noundef %42)
  store { i64, i32 } %47, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %12, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %38, i64 12, i1 false)
  %48 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %49 = load i64, ptr %48, align 4
  %50 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %51 = load i32, ptr %50, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %10, i64 12, i1 false)
  %52 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %53 = load i64, ptr %52, align 4
  %54 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %55 = load i32, ptr %54, align 4
  %56 = call i32 @TPE_dist(i64 %49, i32 %51, i64 %53, i32 %55)
  %57 = load i32, ptr %9, align 4, !tbaa !18
  %58 = icmp sle i32 %56, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %24
  store i8 1, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

60:                                               ; preds = %24
  store i32 0, ptr %7, align 4
  br label %61

61:                                               ; preds = %60, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %62 = load i32, ptr %7, align 4
  switch i32 %62, label %67 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  %65 = load i16, ptr %6, align 2, !tbaa !9
  %66 = add i16 %65, 1
  store i16 %66, ptr %6, align 2, !tbaa !9
  br label %15, !llvm.loop !19

67:                                               ; preds = %61, %23
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  %68 = load i32, ptr %7, align 4
  switch i32 %68, label %72 [
    i32 2, label %69
    i32 1, label %70
  ]

69:                                               ; preds = %67
  store i8 0, ptr %3, align 1
  br label %70

70:                                               ; preds = %69, %67
  %71 = load i8, ptr %3, align 1
  ret i8 %71

72:                                               ; preds = %67
  unreachable
}

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 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !7, i64 32, !7, i64 33}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !7, i64 18}
!15 = !{!"", !16, i64 0, !7, i64 12, !7, i64 18}
!16 = !{!"", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"int", !7, i64 0}
!18 = !{!17, !17, i64 0}
!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"

%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i8 @TPE_bodyEnvironmentCollide(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %.not2526.not = icmp eq i8 %4, 0
  br i1 %.not2526.not, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i8, ptr %3, align 8, !tbaa !5
  %7 = zext i8 %6 to i64
  %.not25 = icmp ult i64 %indvars.iv.next, %7
  br i1 %.not25, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

.lr.ph:                                           ; preds = %2, %5
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 0, %2 ]
  %8 = load ptr, ptr %0, align 8, !tbaa !13
  %9 = getelementptr inbounds %struct.TPE_Joint, ptr %8, i64 %indvars.iv
  %10 = getelementptr inbounds i8, ptr %9, i64 18
  %11 = load i8, ptr %10, align 2, !tbaa !14
  %12 = zext i8 %11 to i32
  %13 = shl nuw nsw i32 %12, 5
  %.sroa.05.0.copyload = load i64, ptr %9, align 4
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 8
  %.sroa.26.0.copyload = load i32, ptr %.sroa.26.0..sroa_idx, align 4
  %14 = tail call { i64, i32 } %1(i64 %.sroa.05.0.copyload, i32 %.sroa.26.0.copyload, i32 noundef %13) #2
  %.fca.0.extract = extractvalue { i64, i32 } %14, 0
  %.fca.1.extract = extractvalue { i64, i32 } %14, 1
  %.sroa.01.0.copyload = load i64, ptr %9, align 4
  %.sroa.22.0.copyload = load i32, ptr %.sroa.26.0..sroa_idx, align 4
  %15 = tail call i32 @TPE_dist(i64 %.sroa.01.0.copyload, i32 %.sroa.22.0.copyload, i64 %.fca.0.extract, i32 %.fca.1.extract)
  %.not = icmp sle i32 %15, %13
  br i1 %.not, label %._crit_edge.loopexit, label %5

._crit_edge.loopexit:                             ; preds = %5, %.lr.ph
  %16 = zext i1 %.not to i8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.not25.lcssa = phi i8 [ 0, %2 ], [ %16, %._crit_edge.loopexit ]
  ret i8 %.not25.lcssa
}

attributes #0 = { 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 #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 = { 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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !8, i64 18}
!15 = !{!"", !16, i64 0, !8, i64 12, !8, i64 18}
!16 = !{!"", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"int", !8, i64 0}


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