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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @IntersectionOfLineSegmentAndLine2D(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 %7, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = call double @IntersectionOfLines2D(ptr noundef %12, ptr noundef %13, ptr noundef %14, ptr noundef %15, ptr noundef %16)
  %18 = fcmp oeq double -1.000000e+00, %17
  br i1 %18, label %19, label %20

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

20:                                               ; preds = %5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds double, ptr %21, i64 0
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i64 0
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fsub double %23, %26
  %28 = call double @llvm.fabs.f64(double %27)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i64 0
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 0
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fsub double %31, %34
  %36 = call double @llvm.fabs.f64(double %35)
  %37 = fcmp ogt double %28, %36
  br i1 %37, label %38, label %57

38:                                               ; preds = %20
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %39, i64 1
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 1
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fsub double %41, %44
  %46 = call double @llvm.fabs.f64(double %45)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i64 1
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %50, i64 1
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = fsub double %49, %52
  %54 = call double @llvm.fabs.f64(double %53)
  %55 = fcmp ogt double %46, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %38
  store double 0.000000e+00, ptr %6, align 8
  br label %58

57:                                               ; preds = %38, %20
  store double -1.000000e+00, ptr %6, align 8
  br label %58

58:                                               ; preds = %57, %56, %19
  %59 = load double, ptr %6, align 8
  ret double %59
}

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"

; Function Attrs: nounwind uwtable
declare dso_local double @IntersectionOfLines2D(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef double @IntersectionOfLineSegmentAndLine2D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call double @IntersectionOfLines2D(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %7 = fcmp oeq double %6, -1.000000e+00
  br i1 %7, label %38, label %8

8:                                                ; preds = %5
  %9 = load double, ptr %3, align 8, !tbaa !5
  %10 = load double, ptr %4, align 8, !tbaa !5
  %11 = load double, ptr %0, align 8, !tbaa !5
  %12 = insertelement <2 x double> poison, double %9, i64 0
  %13 = insertelement <2 x double> %12, double %11, i64 1
  %14 = insertelement <2 x double> poison, double %10, i64 0
  %15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
  %16 = fsub <2 x double> %13, %15
  %17 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %16)
  %18 = extractelement <2 x double> %17, i64 0
  %19 = extractelement <2 x double> %17, i64 1
  %20 = fcmp ogt double %18, %19
  br i1 %20, label %21, label %37

21:                                               ; preds = %8
  %22 = getelementptr inbounds i8, ptr %3, i64 8
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = insertelement <2 x double> poison, double %23, i64 0
  %29 = insertelement <2 x double> %28, double %27, i64 1
  %30 = insertelement <2 x double> poison, double %25, i64 0
  %31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
  %32 = fsub <2 x double> %29, %31
  %33 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %32)
  %34 = extractelement <2 x double> %33, i64 0
  %35 = extractelement <2 x double> %33, i64 1
  %36 = fcmp ogt double %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %21, %8
  br label %38

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<2 x double>) #1

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

!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,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass