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

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

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @TPE_envSphere(i64 %0, i32 %1, i64 %2, i32 %3, i32 noundef %4) #2 {
  %6 = alloca %struct.TPE_Vec3, align 4
  %7 = alloca %struct.TPE_Vec3, align 4
  %8 = alloca { i64, i32 }, align 4
  %9 = alloca %struct.TPE_Vec3, align 4
  %10 = alloca { i64, i32 }, align 4
  %11 = alloca i32, align 4
  %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 i32, align 4
  %17 = alloca { i64, i32 }, align 4
  %18 = alloca i32, align 4
  %19 = alloca { i64, i32 }, align 4
  %20 = alloca { i64, i32 }, align 4
  %21 = alloca { i64, i32 }, align 8
  %22 = alloca { i64, i32 }, align 8
  %23 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %0, ptr %23, align 4
  %24 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %1, ptr %24, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %8, i64 12, i1 false)
  %25 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  store i64 %2, ptr %25, align 4
  %26 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  store i32 %3, ptr %26, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %10, i64 12, i1 false)
  store i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %7, i64 12, i1 false)
  %27 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %28 = load i64, ptr %27, align 4
  %29 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %30 = load i32, ptr %29, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %9, i64 12, i1 false)
  %31 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %32 = load i64, ptr %31, align 4
  %33 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %34 = load i32, ptr %33, align 4
  %35 = call { i64, i32 } @TPE_vec3Minus(i64 %28, i32 %30, i64 %32, i32 %34)
  store { i64, i32 } %35, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 8 %15, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %12, i64 12, i1 false)
  %36 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 0
  %37 = load i64, ptr %36, align 4
  %38 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 1
  %39 = load i32, ptr %38, align 4
  %40 = call i32 @TPE_vec3Len(i64 %37, i32 %39)
  store i32 %40, ptr %16, align 4, !tbaa !5
  %41 = load i32, ptr %16, align 4, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !5
  %43 = icmp sle i32 %41, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !9
  store i32 1, ptr %18, align 4
  br label %76

45:                                               ; preds = %5
  %46 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !10
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = mul nsw i32 %47, %48
  %50 = load i32, ptr %16, align 4, !tbaa !5
  %51 = sdiv i32 %49, %50
  %52 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 0
  store i32 %51, ptr %52, align 4, !tbaa !10
  %53 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = mul nsw i32 %54, %55
  %57 = load i32, ptr %16, align 4, !tbaa !5
  %58 = sdiv i32 %56, %57
  %59 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 1
  store i32 %58, ptr %59, align 4, !tbaa !12
  %60 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 2
  %61 = load i32, ptr %60, align 4, !tbaa !13
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = mul nsw i32 %61, %62
  %64 = load i32, ptr %16, align 4, !tbaa !5
  %65 = sdiv i32 %63, %64
  %66 = getelementptr inbounds %struct.TPE_Vec3, ptr %12, i32 0, i32 2
  store i32 %65, ptr %66, align 4, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %9, i64 12, i1 false)
  %67 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 0
  %68 = load i64, ptr %67, align 4
  %69 = getelementptr inbounds { i64, i32 }, ptr %19, i32 0, i32 1
  %70 = load i32, ptr %69, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %12, i64 12, i1 false)
  %71 = getelementptr inbounds { i64, i32 }, ptr %20, i32 0, i32 0
  %72 = load i64, ptr %71, align 4
  %73 = getelementptr inbounds { i64, i32 }, ptr %20, i32 0, i32 1
  %74 = load i32, ptr %73, align 4
  %75 = call { i64, i32 } @TPE_vec3Plus(i64 %68, i32 %70, i64 %72, i32 %74)
  store { i64, i32 } %75, ptr %21, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 8 %21, i64 12, i1 false)
  store i32 1, ptr %18, align 4
  br label %76

76:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 4 %6, i64 12, i1 false)
  %77 = load { i64, i32 }, ptr %22, align 8
  ret { i64, i32 } %77
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!12 = !{!11, !6, i64 4}
!13 = !{!11, !6, 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 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 { i64, i32 } @TPE_vec3Plus(i64, i32, i64, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @TPE_envSphere(i64 %0, i32 %1, i64 %2, i32 %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call { i64, i32 } @TPE_vec3Minus(i64 %0, i32 %1, i64 %2, i32 %3)
  %.fca.0.extract12 = extractvalue { i64, i32 } %6, 0
  %.fca.1.extract13 = extractvalue { i64, i32 } %6, 1
  %7 = tail call i32 @TPE_vec3Len(i64 %.fca.0.extract12, i32 %.fca.1.extract13)
  %.not = icmp sgt i32 %7, %4
  br i1 %.not, label %8, label %16

8:                                                ; preds = %5
  %.sroa.020.0.extract.trunc = trunc i64 %.fca.0.extract12 to i32
  %9 = mul nsw i32 %.sroa.020.0.extract.trunc, %4
  %10 = sdiv i32 %9, %7
  %.sroa.020.0.insert.ext = zext i32 %10 to i64
  %.sroa.020.4.extract.shift = lshr i64 %.fca.0.extract12, 32
  %.sroa.020.4.extract.trunc = trunc nuw i64 %.sroa.020.4.extract.shift to i32
  %11 = mul nsw i32 %.sroa.020.4.extract.trunc, %4
  %12 = sdiv i32 %11, %7
  %.sroa.020.4.insert.ext = zext i32 %12 to i64
  %.sroa.020.4.insert.shift = shl nuw i64 %.sroa.020.4.insert.ext, 32
  %.sroa.020.4.insert.insert = or disjoint i64 %.sroa.020.4.insert.shift, %.sroa.020.0.insert.ext
  %13 = mul nsw i32 %.fca.1.extract13, %4
  %14 = sdiv i32 %13, %7
  %15 = tail call { i64, i32 } @TPE_vec3Plus(i64 %2, i32 %3, i64 %.sroa.020.4.insert.insert, i32 %14)
  %.fca.0.extract = extractvalue { i64, i32 } %15, 0
  %.fca.1.extract = extractvalue { i64, i32 } %15, 1
  br label %16

16:                                               ; preds = %5, %8
  %.sroa.038.0 = phi i64 [ %.fca.0.extract, %8 ], [ %0, %5 ]
  %.sroa.339.0 = phi i32 [ %.fca.1.extract, %8 ], [ %1, %5 ]
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.038.0, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.339.0, 1
  ret { i64, i32 } %.fca.1.insert
}

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)"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass