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

@IntersectionOfLines2D.det = external hidden global double, align 8
@IntersectionOfLines2D.temp_coeff1 = external hidden global double, align 8
@IntersectionOfLines2D.temp_coeff2 = 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: nounwind uwtable
define dso_local double @IntersectionOfLines2D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca double, align 8
  %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 %8, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %12, i64 0
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds double, ptr %15, i64 0
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = fsub double %14, %17
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 1
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %22, i64 1
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fsub double %21, %24
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %26, i64 1
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 1
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fsub double %28, %31
  %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 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %36, i64 0
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fsub double %35, %38
  %40 = fmul double %32, %39
  %41 = fneg double %40
  %42 = call double @llvm.fmuladd.f64(double %18, double %25, double %41)
  store double %42, ptr @IntersectionOfLines2D.det, align 8, !tbaa !9
  %43 = load double, ptr @IntersectionOfLines2D.det, align 8, !tbaa !9
  %44 = call double @llvm.fabs.f64(double %43)
  %45 = fcmp olt double %44, 1.000000e-10
  br i1 %45, label %46, label %47

46:                                               ; preds = %5
  store double -1.000000e+00, ptr %6, align 8
  br label %124

47:                                               ; preds = %5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds double, ptr %48, i64 0
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 1
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds double, ptr %54, i64 1
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds double, ptr %57, i64 0
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = fmul double %56, %59
  %61 = fneg double %60
  %62 = call double @llvm.fmuladd.f64(double %50, double %53, double %61)
  store double %62, ptr @IntersectionOfLines2D.temp_coeff1, align 8, !tbaa !9
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 0
  %65 = load double, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds double, ptr %66, i64 1
  %68 = load double, ptr %67, align 8, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds double, ptr %69, i64 1
  %71 = load double, ptr %70, align 8, !tbaa !9
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds double, ptr %72, i64 0
  %74 = load double, ptr %73, align 8, !tbaa !9
  %75 = fmul double %71, %74
  %76 = fneg double %75
  %77 = call double @llvm.fmuladd.f64(double %65, double %68, double %76)
  store double %77, ptr @IntersectionOfLines2D.temp_coeff2, align 8, !tbaa !9
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds double, ptr %78, i64 0
  %80 = load double, ptr %79, align 8, !tbaa !9
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = getelementptr inbounds double, ptr %81, i64 0
  %83 = load double, ptr %82, align 8, !tbaa !9
  %84 = fsub double %80, %83
  %85 = load double, ptr @IntersectionOfLines2D.temp_coeff1, align 8, !tbaa !9
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds double, ptr %86, i64 0
  %88 = load double, ptr %87, align 8, !tbaa !9
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds double, ptr %89, i64 0
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = fsub double %88, %91
  %93 = load double, ptr @IntersectionOfLines2D.temp_coeff2, align 8, !tbaa !9
  %94 = fmul double %92, %93
  %95 = fneg double %94
  %96 = call double @llvm.fmuladd.f64(double %84, double %85, double %95)
  %97 = load double, ptr @IntersectionOfLines2D.det, align 8, !tbaa !9
  %98 = fdiv double %96, %97
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds double, ptr %99, i64 0
  store double %98, ptr %100, align 8, !tbaa !9
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = getelementptr inbounds double, ptr %101, i64 1
  %103 = load double, ptr %102, align 8, !tbaa !9
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = getelementptr inbounds double, ptr %104, i64 1
  %106 = load double, ptr %105, align 8, !tbaa !9
  %107 = fsub double %103, %106
  %108 = load double, ptr @IntersectionOfLines2D.temp_coeff1, align 8, !tbaa !9
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds double, ptr %109, i64 1
  %111 = load double, ptr %110, align 8, !tbaa !9
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = getelementptr inbounds double, ptr %112, i64 1
  %114 = load double, ptr %113, align 8, !tbaa !9
  %115 = fsub double %111, %114
  %116 = load double, ptr @IntersectionOfLines2D.temp_coeff2, align 8, !tbaa !9
  %117 = fmul double %115, %116
  %118 = fneg double %117
  %119 = call double @llvm.fmuladd.f64(double %107, double %108, double %118)
  %120 = load double, ptr @IntersectionOfLines2D.det, align 8, !tbaa !9
  %121 = fdiv double %119, %120
  %122 = load ptr, ptr %7, align 8, !tbaa !5
  %123 = getelementptr inbounds double, ptr %122, i64 0
  store double %121, ptr %123, align 8, !tbaa !9
  store double 0.000000e+00, ptr %6, align 8
  br label %124

124:                                              ; preds = %47, %46
  %125 = load double, ptr %6, align 8
  ret double %125
}

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"

@IntersectionOfLines2D.det = external hidden local_unnamed_addr global double, align 8
@IntersectionOfLines2D.temp_coeff1 = external hidden local_unnamed_addr global double, align 8
@IntersectionOfLines2D.temp_coeff2 = 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef double @IntersectionOfLines2D(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #1 {
  %6 = load double, ptr %1, align 8, !tbaa !5
  %7 = load double, ptr %2, align 8, !tbaa !5
  %8 = fsub double %6, %7
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %4, i64 8
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fsub double %10, %12
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 8
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fsub double %15, %17
  %19 = load double, ptr %3, align 8, !tbaa !5
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = fsub double %19, %20
  %22 = fneg double %18
  %23 = fmul double %21, %22
  %24 = tail call double @llvm.fmuladd.f64(double %8, double %13, double %23)
  store double %24, ptr @IntersectionOfLines2D.det, align 8, !tbaa !5
  %25 = tail call double @llvm.fabs.f64(double %24)
  %26 = fcmp olt double %25, 1.000000e-10
  br i1 %26, label %61, label %27

27:                                               ; preds = %5
  %28 = load double, ptr %1, align 8, !tbaa !5
  %29 = load double, ptr %2, align 8, !tbaa !5
  %30 = fneg double %15
  %31 = fmul double %29, %30
  %32 = tail call double @llvm.fmuladd.f64(double %28, double %17, double %31)
  store double %32, ptr @IntersectionOfLines2D.temp_coeff1, align 8, !tbaa !5
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = fneg double %10
  %36 = fmul double %34, %35
  %37 = tail call double @llvm.fmuladd.f64(double %33, double %12, double %36)
  store double %37, ptr @IntersectionOfLines2D.temp_coeff2, align 8, !tbaa !5
  %38 = load double, ptr %3, align 8, !tbaa !5
  %39 = load double, ptr %4, align 8, !tbaa !5
  %40 = fsub double %38, %39
  %41 = load double, ptr %1, align 8, !tbaa !5
  %42 = load double, ptr %2, align 8, !tbaa !5
  %43 = fsub double %41, %42
  %44 = fneg double %43
  %45 = fmul double %37, %44
  %46 = tail call double @llvm.fmuladd.f64(double %40, double %32, double %45)
  %47 = fdiv double %46, %24
  store double %47, ptr %0, align 8, !tbaa !5
  %48 = load double, ptr %9, align 8, !tbaa !5
  %49 = load double, ptr %11, align 8, !tbaa !5
  %50 = fsub double %48, %49
  %51 = load double, ptr @IntersectionOfLines2D.temp_coeff1, align 8, !tbaa !5
  %52 = load double, ptr %14, align 8, !tbaa !5
  %53 = load double, ptr %16, align 8, !tbaa !5
  %54 = fsub double %52, %53
  %55 = load double, ptr @IntersectionOfLines2D.temp_coeff2, align 8, !tbaa !5
  %56 = fneg double %54
  %57 = fmul double %55, %56
  %58 = tail call double @llvm.fmuladd.f64(double %50, double %51, double %57)
  %59 = load double, ptr @IntersectionOfLines2D.det, align 8, !tbaa !5
  %60 = fdiv double %58, %59
  store double %60, ptr %0, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %5, %27
  %.0 = phi double [ 0.000000e+00, %27 ], [ -1.000000e+00, %5 ]
  ret double %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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