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

; 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: 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) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_nonZero(i32 noundef) #2

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

75:                                               ; preds = %9
  %76 = load i32, ptr %19, align 4, !tbaa !10
  %77 = mul nsw i32 %76, 512
  %78 = load i32, ptr %18, align 4, !tbaa !10
  %79 = sdiv i32 %77, %78
  br label %88

80:                                               ; preds = %9
  %81 = load i32, ptr %19, align 4, !tbaa !10
  %82 = sdiv i32 %81, 64
  %83 = mul nsw i32 %82, 512
  %84 = load i32, ptr %18, align 4, !tbaa !10
  %85 = sdiv i32 %84, 64
  %86 = call i32 @TPE_nonZero(i32 noundef %85)
  %87 = sdiv i32 %83, %86
  br label %88

88:                                               ; preds = %80, %75
  %89 = phi i32 [ %79, %75 ], [ %87, %80 ]
  store i32 %89, ptr %19, align 4, !tbaa !10
  %90 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %91 = load i64, ptr %90, align 4
  %92 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %93 = load i64, ptr %92, align 4
  call void @TPE_vec3MultiplyPlain(i64 %91, i64 %93, i32 noundef -1, ptr noundef %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %94 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %95 = load i64, ptr %94, align 4
  %96 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %97 = load i64, ptr %96, align 4
  %98 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %99 = load i64, ptr %98, align 4
  %100 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %101 = load i64, ptr %100, align 4
  %102 = call i32 @TPE_vec3DotProductPlain(i64 %95, i64 %97, i64 %99, i64 %101)
  %103 = load i32, ptr %16, align 4, !tbaa !10
  %104 = sub nsw i32 %102, %103
  store i32 %104, ptr %20, align 4, !tbaa !10
  %105 = load i32, ptr %20, align 4, !tbaa !10
  %106 = call i32 @TPE_abs(i32 noundef %105)
  %107 = icmp slt i32 %106, 500000
  br i1 %107, label %108, label %113

108:                                              ; preds = %88
  %109 = load i32, ptr %20, align 4, !tbaa !10
  %110 = mul nsw i32 %109, 512
  %111 = load i32, ptr %18, align 4, !tbaa !10
  %112 = sdiv i32 %110, %111
  br label %121

113:                                              ; preds = %88
  %114 = load i32, ptr %20, align 4, !tbaa !10
  %115 = sdiv i32 %114, 64
  %116 = mul nsw i32 %115, 512
  %117 = load i32, ptr %18, align 4, !tbaa !10
  %118 = sdiv i32 %117, 64
  %119 = call i32 @TPE_nonZero(i32 noundef %118)
  %120 = sdiv i32 %116, %119
  br label %121

121:                                              ; preds = %113, %108
  %122 = phi i32 [ %112, %108 ], [ %120, %113 ]
  store i32 %122, ptr %20, align 4, !tbaa !10
  %123 = load i32, ptr %20, align 4, !tbaa !10
  %124 = load i32, ptr %19, align 4, !tbaa !10
  %125 = icmp slt i32 %123, %124
  br i1 %125, label %126, label %130

126:                                              ; preds = %121
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %127 = load i32, ptr %19, align 4, !tbaa !10
  store i32 %127, ptr %21, align 4, !tbaa !10
  %128 = load i32, ptr %20, align 4, !tbaa !10
  store i32 %128, ptr %19, align 4, !tbaa !10
  %129 = load i32, ptr %21, align 4, !tbaa !10
  store i32 %129, ptr %20, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %130

130:                                              ; preds = %126, %121
  %131 = load i32, ptr %19, align 4, !tbaa !10
  %132 = load ptr, ptr %13, align 8, !tbaa !5
  %133 = load i32, ptr %132, align 4, !tbaa !10
  %134 = icmp sgt i32 %131, %133
  br i1 %134, label %135, label %138

135:                                              ; preds = %130
  %136 = load i32, ptr %19, align 4, !tbaa !10
  %137 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %136, ptr %137, align 4, !tbaa !10
  br label %138

138:                                              ; preds = %135, %130
  %139 = load i32, ptr %20, align 4, !tbaa !10
  %140 = load ptr, ptr %14, align 8, !tbaa !5
  %141 = load i32, ptr %140, align 4, !tbaa !10
  %142 = icmp slt i32 %139, %141
  br i1 %142, label %143, label %146

143:                                              ; preds = %138
  %144 = load i32, ptr %20, align 4, !tbaa !10
  %145 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %144, ptr %145, align 4, !tbaa !10
  br label %146

146:                                              ; preds = %143, %138
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TPE_vec3DotProductPlain(i64, i64, i64, i64) #3

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 12, i64 4, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}


; 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
define dso_local void @_TPE_cutLineSegmentByPlanes(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, ptr nocapture noundef readonly byval(%struct.TPE_Vec4) align 8 %6, ptr nocapture noundef %7, ptr nocapture noundef %8) local_unnamed_addr #2 {
  %10 = alloca %struct.TPE_Vec4, align 8
  %11 = tail call { i64, i64 } @TPE_vec3Minus(i64 %4, i64 %5, i64 %0, i64 %1)
  %12 = extractvalue { i64, i64 } %11, 0
  %13 = extractvalue { i64, i64 } %11, 1
  %14 = tail call i32 @TPE_vec3DotProductPlain(i64 %2, i64 %3, i64 %12, i64 %13)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %10) #4
  %15 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 %2, ptr %10, align 8
  store i64 %3, ptr %15, align 8
  %16 = load i64, ptr %6, align 8
  %17 = getelementptr inbounds i8, ptr %6, i64 8
  %18 = load i64, ptr %17, align 8
  %19 = tail call i32 @TPE_vec3DotProductPlain(i64 %2, i64 %3, i64 %16, i64 %18)
  %20 = tail call i32 @TPE_nonZero(i32 noundef %19)
  %21 = tail call i32 @TPE_vec3DotProductPlain(i64 %2, i64 %3, i64 %2, i64 %3)
  %22 = sub nsw i32 %21, %14
  %23 = tail call i32 @TPE_abs(i32 noundef %22)
  %24 = icmp slt i32 %23, 500000
  br i1 %24, label %25, label %28

25:                                               ; preds = %9
  %26 = shl nsw i32 %22, 9
  %27 = sdiv i32 %26, %20
  br label %34

28:                                               ; preds = %9
  %29 = sdiv i32 %22, 64
  %30 = shl nsw i32 %29, 9
  %31 = sdiv i32 %20, 64
  %32 = tail call i32 @TPE_nonZero(i32 noundef %31)
  %33 = sdiv i32 %30, %32
  br label %34

34:                                               ; preds = %28, %25
  %35 = phi i32 [ %27, %25 ], [ %33, %28 ]
  call void @TPE_vec3MultiplyPlain(i64 %2, i64 %3, i32 noundef -1, ptr noundef nonnull %10)
  %36 = load i64, ptr %10, align 8
  %37 = load i64, ptr %15, align 8
  %38 = call i32 @TPE_vec3DotProductPlain(i64 %2, i64 %3, i64 %36, i64 %37)
  %39 = sub nsw i32 %38, %14
  %40 = call i32 @TPE_abs(i32 noundef %39)
  %41 = icmp slt i32 %40, 500000
  br i1 %41, label %42, label %45

42:                                               ; preds = %34
  %43 = shl nsw i32 %39, 9
  %44 = sdiv i32 %43, %20
  br label %51

45:                                               ; preds = %34
  %46 = sdiv i32 %39, 64
  %47 = shl nsw i32 %46, 9
  %48 = sdiv i32 %20, 64
  %49 = call i32 @TPE_nonZero(i32 noundef %48)
  %50 = sdiv i32 %47, %49
  br label %51

51:                                               ; preds = %45, %42
  %52 = phi i32 [ %44, %42 ], [ %50, %45 ]
  %spec.select = call i32 @llvm.smax.i32(i32 %52, i32 %35)
  %spec.select42 = call i32 @llvm.smin.i32(i32 %52, i32 %35)
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = icmp sgt i32 %spec.select42, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  store i32 %spec.select42, ptr %7, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %55, %51
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = icmp slt i32 %spec.select, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store i32 %spec.select, ptr %8, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %10) #4
  ret void
}

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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