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

@IntersectionOfLineSegmentAndHalfLine.SA = external hidden global [3 x double], align 16
@IntersectionOfLineSegmentAndHalfLine.t = external hidden global double, align 8
@IntersectionOfLineSegmentAndHalfLine.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 @IntersectionOfLineSegmentAndHalfLine(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 @IntersectionOfLineSegmentAndHalfLine.SA, ptr noundef %12, ptr noundef %13)
  %14 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.SA, align 16, !tbaa !9
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = getelementptr inbounds double, ptr %15, i64 1
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegmentAndHalfLine.SA, i64 0, i64 1), align 8, !tbaa !9
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 0
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fmul double %18, %21
  %23 = fneg double %22
  %24 = call double @llvm.fmuladd.f64(double %14, double %17, double %23)
  store double %24, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %25 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %26 = call double @llvm.fabs.f64(double %25)
  %27 = fcmp olt double %26, 1.000000e-10
  br i1 %27, label %28, label %29

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

29:                                               ; preds = %5
  %30 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegmentAndHalfLine.SA, i64 0, i64 1), align 8, !tbaa !9
  %31 = fneg double %30
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 0
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %35, i64 0
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = fsub double %34, %37
  %39 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.SA, align 16, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds double, ptr %40, i64 1
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 1
  %45 = load double, ptr %44, align 8, !tbaa !9
  %46 = fsub double %42, %45
  %47 = fmul double %39, %46
  %48 = call double @llvm.fmuladd.f64(double %31, double %38, double %47)
  %49 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %50 = fdiv double %48, %49
  store double %50, ptr @IntersectionOfLineSegmentAndHalfLine.s, align 8, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 0
  %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 %10, align 8, !tbaa !5
  %58 = getelementptr inbounds double, ptr %57, i64 1
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = fsub double %56, %59
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds double, ptr %61, i64 1
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds double, ptr %64, i64 0
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds double, ptr %67, i64 0
  %69 = load double, ptr %68, align 8, !tbaa !9
  %70 = fsub double %66, %69
  %71 = fmul double %63, %70
  %72 = fneg double %71
  %73 = call double @llvm.fmuladd.f64(double %53, double %60, double %72)
  %74 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %75 = fdiv double %73, %74
  store double %75, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %76 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.s, align 8, !tbaa !9
  %77 = fcmp oge double %76, 0.000000e+00
  br i1 %77, label %78, label %98

78:                                               ; preds = %29
  %79 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %80 = fcmp oge double %79, 0.000000e+00
  br i1 %80, label %81, label %98

81:                                               ; preds = %78
  %82 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %83 = fcmp ole double %82, 1.000000e+00
  br i1 %83, label %84, label %98

84:                                               ; preds = %81
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %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 double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %90 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.SA, align 16, !tbaa !9
  %91 = call double @llvm.fmuladd.f64(double %89, double %90, double %88)
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds double, ptr %92, i64 1
  %94 = load double, ptr %93, align 8, !tbaa !9
  %95 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !9
  %96 = load double, ptr getelementptr inbounds ([3 x double], ptr @IntersectionOfLineSegmentAndHalfLine.SA, i64 0, i64 1), align 8, !tbaa !9
  %97 = call double @llvm.fmuladd.f64(double %95, double %96, double %94)
  call void @FillVect(ptr noundef %85, double noundef %91, double noundef %97, double noundef 0.000000e+00)
  store i1 true, ptr %6, align 1
  br label %99

98:                                               ; preds = %81, %78, %29
  store i1 false, ptr %6, align 1
  br label %99

99:                                               ; preds = %98, %84, %28
  %100 = load i1, ptr %6, align 1
  ret i1 %100
}

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"

@IntersectionOfLineSegmentAndHalfLine.SA = external hidden global [3 x double], align 16
@IntersectionOfLineSegmentAndHalfLine.t = external hidden local_unnamed_addr global double, align 8
@IntersectionOfLineSegmentAndHalfLine.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 @IntersectionOfLineSegmentAndHalfLine(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #1 {
  tail call void @VectDifference(ptr noundef nonnull @IntersectionOfLineSegmentAndHalfLine.SA, ptr noundef %2, ptr noundef %1)
  %6 = load double, ptr @IntersectionOfLineSegmentAndHalfLine.SA, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = load double, ptr getelementptr inbounds (i8, ptr @IntersectionOfLineSegmentAndHalfLine.SA, i64 8), align 8, !tbaa !5
  %10 = load double, ptr %4, align 8, !tbaa !5
  %11 = fneg double %9
  %12 = fmul double %10, %11
  %13 = tail call double @llvm.fmuladd.f64(double %6, double %8, double %12)
  store double %13, ptr @IntersectionOfLineSegmentAndHalfLine.t, align 8, !tbaa !5
  %14 = tail call double @llvm.fabs.f64(double %13)
  %15 = fcmp olt double %14, 1.000000e-10
  br i1 %15, label %44, label %16

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

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

44:                                               ; preds = %16, %5, %40
  %.0 = phi i1 [ true, %40 ], [ false, %5 ], [ false, %16 ]
  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