; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

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

@IntersectionOfLineSegments.SA = external hidden global [3 x double], align 16
@IntersectionOfLineSegments.SB = external hidden global [3 x double], align 16
@IntersectionOfLineSegments.t = external hidden global double, align 8
@IntersectionOfLineSegments.s = external hidden global double, align 8

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @FillVect(ptr noundef, double noundef, double noundef, double noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @IntersectionOfLineSegments(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @IntersectionOfLineSegments.SA, ptr noundef %12, ptr noundef %13)
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  call void @VectDifference(ptr noundef @IntersectionOfLineSegments.SB, ptr noundef %14, ptr noundef %15)
  %16 = load double, ptr @IntersectionOfLineSegments.SA, align 16, !tbaa !9
  %17 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegments.SB, i64 0, i64 1), align 8, !tbaa !9
  %18 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegments.SA, i64 0, i64 1), align 8, !tbaa !9
  %19 = load double, ptr @IntersectionOfLineSegments.SB, align 16, !tbaa !9
  %20 = fmul double %18, %19
  %21 = fneg double %20
  %22 = call double @llvm.fmuladd.f64(double %16, double %17, double %21)
  store double %22, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %23 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %24 = call double @llvm.fabs.f64(double %23)
  %25 = fcmp olt double %24, 1.000000e-10
  br i1 %25, label %26, label %27

26:                                               ; preds = %5
  store i1 false, ptr %6, align 1
  br label %96

27:                                               ; preds = %5
  %28 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegments.SA, i64 0, i64 1), align 8, !tbaa !9
  %29 = fneg double %28
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 0
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds double, ptr %33, i64 0
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fsub double %32, %35
  %37 = load double, ptr @IntersectionOfLineSegments.SA, align 16, !tbaa !9
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %38, i64 1
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds double, ptr %41, i64 1
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = fsub double %40, %43
  %45 = fmul double %37, %44
  %46 = call double @llvm.fmuladd.f64(double %29, double %36, double %45)
  %47 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %48 = fdiv double %46, %47
  store double %48, ptr @IntersectionOfLineSegments.s, align 8, !tbaa !9
  %49 = load double, ptr @IntersectionOfLineSegments.SB, align 16, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %50, i64 1
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i64 1
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fsub double %52, %55
  %57 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegments.SB, i64 0, i64 1), align 8, !tbaa !9
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds double, ptr %58, i64 0
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds double, ptr %61, i64 0
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fsub double %60, %63
  %65 = fmul double %57, %64
  %66 = fneg double %65
  %67 = call double @llvm.fmuladd.f64(double %49, double %56, double %66)
  %68 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %69 = fdiv double %67, %68
  store double %69, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %70 = load double, ptr @IntersectionOfLineSegments.s, align 8, !tbaa !9
  %71 = fcmp oge double %70, 0.000000e+00
  br i1 %71, label %72, label %95

72:                                               ; preds = %27
  %73 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %74 = fcmp oge double %73, 0.000000e+00
  br i1 %74, label %75, label %95

75:                                               ; preds = %72
  %76 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %77 = fcmp ole double %76, 1.000000e+00
  br i1 %77, label %78, label %95

78:                                               ; preds = %75
  %79 = load double, ptr @IntersectionOfLineSegments.s, align 8, !tbaa !9
  %80 = fcmp ole double %79, 1.000000e+00
  br i1 %80, label %81, label %95

81:                                               ; preds = %78
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds double, ptr %83, i64 0
  %85 = load double, ptr %84, align 8, !tbaa !9
  %86 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %87 = load double, ptr @IntersectionOfLineSegments.SA, align 16, !tbaa !9
  %88 = call double @llvm.fmuladd.f64(double %86, double %87, double %85)
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds double, ptr %89, i64 1
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = load double, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !9
  %93 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegments.SA, i64 0, i64 1), align 8, !tbaa !9
  %94 = call double @llvm.fmuladd.f64(double %92, double %93, double %91)
  call void @FillVect(ptr noundef %82, double noundef %88, double noundef %94, double noundef 0.000000e+00)
  store i1 true, ptr %6, align 1
  br label %96

95:                                               ; preds = %78, %75, %72, %27
  store i1 false, ptr %6, align 1
  br label %96

96:                                               ; preds = %95, %81, %26
  %97 = load i1, ptr %6, align 1
  ret i1 %97
}

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

!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 = !{!"double", !7, i64 0}


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

@IntersectionOfLineSegments.SA = external hidden global [3 x double], align 16
@IntersectionOfLineSegments.SB = external hidden global [3 x double], align 16
@IntersectionOfLineSegments.t = external hidden local_unnamed_addr global double, align 8
@IntersectionOfLineSegments.s = external hidden local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nounwind uwtable
declare dso_local void @FillVect(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @IntersectionOfLineSegments(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  tail call void @VectDifference(ptr noundef nonnull @IntersectionOfLineSegments.SA, ptr noundef %2, ptr noundef %1)
  tail call void @VectDifference(ptr noundef nonnull @IntersectionOfLineSegments.SB, ptr noundef %4, ptr noundef %3)
  %6 = load double, ptr @IntersectionOfLineSegments.SA, align 16, !tbaa !5
  %7 = load double, ptr getelementptr inbounds (i8, ptr @IntersectionOfLineSegments.SB, i64 8), align 8, !tbaa !5
  %8 = load double, ptr getelementptr inbounds (i8, ptr @IntersectionOfLineSegments.SA, i64 8), align 8, !tbaa !5
  %9 = load double, ptr @IntersectionOfLineSegments.SB, align 16, !tbaa !5
  %10 = fneg double %8
  %11 = fmul double %9, %10
  %12 = tail call double @llvm.fmuladd.f64(double %6, double %7, double %11)
  store double %12, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !5
  %13 = tail call double @llvm.fabs.f64(double %12)
  %14 = fcmp olt double %13, 1.000000e-10
  br i1 %14, label %43, label %15

15:                                               ; preds = %5
  %16 = load double, ptr %1, align 8, !tbaa !5
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = fsub double %16, %17
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %3, i64 8
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fsub double %20, %22
  %24 = fmul double %6, %23
  %25 = tail call double @llvm.fmuladd.f64(double %10, double %18, double %24)
  %26 = fdiv double %25, %12
  store double %26, ptr @IntersectionOfLineSegments.s, align 8, !tbaa !5
  %27 = load double, ptr %1, align 8, !tbaa !5
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = fsub double %27, %28
  %30 = fneg double %7
  %31 = fmul double %29, %30
  %32 = tail call double @llvm.fmuladd.f64(double %9, double %23, double %31)
  %33 = fdiv double %32, %12
  store double %33, ptr @IntersectionOfLineSegments.t, align 8, !tbaa !5
  %34 = fcmp oge double %26, 0.000000e+00
  %35 = fcmp oge double %33, 0.000000e+00
  %36 = fcmp ole double %33, 1.000000e+00
  %37 = and i1 %35, %36
  %or.cond3 = select i1 %34, i1 %37, i1 false
  %38 = fcmp ole double %26, 1.000000e+00
  %or.cond5 = and i1 %38, %or.cond3
  br i1 %or.cond5, label %39, label %43

39:                                               ; preds = %15
  %40 = load double, ptr %1, align 8, !tbaa !5
  %41 = tail call double @llvm.fmuladd.f64(double %33, double %6, double %40)
  %42 = tail call double @llvm.fmuladd.f64(double %33, double %8, double %20)
  tail call void @FillVect(ptr noundef %0, double noundef %41, double noundef %42, double noundef 0.000000e+00)
  br label %43

43:                                               ; preds = %15, %5, %39
  %.0 = phi i1 [ true, %39 ], [ false, %5 ], [ false, %15 ]
  ret i1 %.0
}

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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