; LLVM IR from jordan4ibanez/tinyphysicsengine :: old (test)

; 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_Vec4 = type { i32, i32, i32, i32 }

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

; Function Attrs: 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_nonZero(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_vec3Minus(i64, i64, i64, i64) #2

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @TPE_lineSegmentClosestPoint(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) #2 {
  %7 = alloca %struct.TPE_Vec4, align 4
  %8 = alloca %struct.TPE_Vec4, align 4
  %9 = alloca %struct.TPE_Vec4, align 4
  %10 = alloca %struct.TPE_Vec4, align 4
  %11 = alloca %struct.TPE_Vec4, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.TPE_Vec4, align 4
  %14 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %0, ptr %14, align 4
  %15 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %1, ptr %15, align 4
  %16 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  store i64 %2, ptr %16, align 4
  %17 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  store i64 %3, ptr %17, align 4
  %18 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  store i64 %4, ptr %18, align 4
  %19 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  store i64 %5, ptr %19, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #3
  %20 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %21 = load i64, ptr %20, align 4
  %22 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %23 = load i64, ptr %22, align 4
  %24 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %25 = load i64, ptr %24, align 4
  %26 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %27 = load i64, ptr %26, align 4
  %28 = call { i64, i64 } @TPE_vec3Minus(i64 %21, i64 %23, i64 %25, i64 %27)
  %29 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %30 = extractvalue { i64, i64 } %28, 0
  store i64 %30, ptr %29, align 4
  %31 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %32 = extractvalue { i64, i64 } %28, 1
  store i64 %32, ptr %31, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %33 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %34 = load i64, ptr %33, align 4
  %35 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %36 = load i64, ptr %35, align 4
  %37 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %38 = load i64, ptr %37, align 4
  %39 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %40 = load i64, ptr %39, align 4
  %41 = call { i64, i64 } @TPE_vec3Minus(i64 %34, i64 %36, i64 %38, i64 %40)
  %42 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %43 = extractvalue { i64, i64 } %41, 0
  store i64 %43, ptr %42, align 4
  %44 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %45 = extractvalue { i64, i64 } %41, 1
  store i64 %45, ptr %44, align 4
  %46 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %47 = load i64, ptr %46, align 4
  %48 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %49 = load i64, ptr %48, align 4
  %50 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %53 = load i64, ptr %52, align 4
  %54 = call i32 @TPE_vec3DotProduct(i64 %47, i64 %49, i64 %51, i64 %53)
  %55 = mul nsw i32 %54, 512
  %56 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %57 = load i64, ptr %56, align 4
  %58 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %59 = load i64, ptr %58, align 4
  %60 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %61 = load i64, ptr %60, align 4
  %62 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %63 = load i64, ptr %62, align 4
  %64 = call i32 @TPE_vec3DotProduct(i64 %57, i64 %59, i64 %61, i64 %63)
  %65 = call i32 @TPE_nonZero(i32 noundef %64)
  %66 = sdiv i32 %55, %65
  store i32 %66, ptr %12, align 4, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = icmp slt i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %6
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %75

70:                                               ; preds = %6
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 512
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  store i32 512, ptr %12, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %73, %70
  br label %75

75:                                               ; preds = %74, %69
  %76 = load i32, ptr %12, align 4, !tbaa !5
  %77 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %78 = load i64, ptr %77, align 4
  %79 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %80 = load i64, ptr %79, align 4
  call void @TPE_vec3Multiply(i64 %78, i64 %80, i32 noundef %76, ptr noundef %11)
  %81 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %82 = load i64, ptr %81, align 4
  %83 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %84 = load i64, ptr %83, align 4
  %85 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %86 = load i64, ptr %85, align 4
  %87 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %88 = load i64, ptr %87, align 4
  %89 = call { i64, i64 } @TPE_vec3Plus(i64 %82, i64 %84, i64 %86, i64 %88)
  %90 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %91 = extractvalue { i64, i64 } %89, 0
  store i64 %91, ptr %90, align 4
  %92 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %93 = extractvalue { i64, i64 } %89, 1
  store i64 %93, ptr %92, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #3
  %94 = load { i64, i64 }, ptr %7, align 4
  ret { i64, i64 } %94
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_vec3DotProduct(i64, i64, i64, i64) #2

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_vec3Multiply(i64, i64, i32 noundef, ptr noundef) #2

attributes #0 = { 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"}


; 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_Vec4 = type { i32, i32, i32, i32 }

; 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_nonZero(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_vec3Minus(i64, i64, i64, i64) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local { i64, i64 } @TPE_lineSegmentClosestPoint(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) local_unnamed_addr #2 {
  %7 = alloca %struct.TPE_Vec4, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %8 = tail call { i64, i64 } @TPE_vec3Minus(i64 %2, i64 %3, i64 %0, i64 %1)
  %9 = extractvalue { i64, i64 } %8, 0
  store i64 %9, ptr %7, align 8
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  %11 = extractvalue { i64, i64 } %8, 1
  store i64 %11, ptr %10, align 8
  %12 = tail call { i64, i64 } @TPE_vec3Minus(i64 %4, i64 %5, i64 %0, i64 %1)
  %13 = extractvalue { i64, i64 } %12, 0
  %14 = extractvalue { i64, i64 } %12, 1
  %15 = tail call i32 @TPE_vec3DotProduct(i64 %9, i64 %11, i64 %13, i64 %14)
  %16 = shl nsw i32 %15, 9
  %17 = tail call i32 @TPE_vec3DotProduct(i64 %9, i64 %11, i64 %9, i64 %11)
  %18 = tail call i32 @TPE_nonZero(i32 noundef %17)
  %19 = sdiv i32 %16, %18
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %19, i32 512)
  %.0 = tail call i32 @llvm.smax.i32(i32 %spec.store.select, i32 0)
  call void @TPE_vec3Multiply(i64 %9, i64 %11, i32 noundef %.0, ptr noundef nonnull %7)
  %20 = load i64, ptr %7, align 8
  %21 = load i64, ptr %10, align 8
  %22 = call { i64, i64 } @TPE_vec3Plus(i64 %0, i64 %1, i64 %20, i64 %21)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret { i64, i64 } %22
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_vec3DotProduct(i64, i64, i64, i64) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass