; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Isect.ll (Z12R2IntersectsRK6R2LineS1_P7R2Point)

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

%class.R2Point = type { [2 x double] }

@RN_EPSILON = external global double, align 8

declare noundef i32 @_Z10R2ContainsRK6R2LineRK7R2Point(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(16)) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12R2IntersectsRK6R2LineS1_P7R2Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca %class.R2Point, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40) %17)
  store double %18, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40) %19)
  store double %20, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40) %21)
  store double %22, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40) %23)
  store double %24, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40) %25)
  store double %26, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40) %27)
  store double %28, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %29 = load double, ptr %11, align 8, !tbaa !9
  %30 = load double, ptr %9, align 8, !tbaa !9
  %31 = load double, ptr %8, align 8, !tbaa !9
  %32 = load double, ptr %12, align 8, !tbaa !9
  %33 = fmul double %31, %32
  %34 = fneg double %33
  %35 = call double @llvm.fmuladd.f64(double %29, double %30, double %34)
  store double %35, ptr %14, align 8, !tbaa !9
  %36 = load double, ptr %14, align 8, !tbaa !9
  %37 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %38 = call noundef i32 @_Z8RNIsZerodd(double noundef %36, double noundef %37)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #6
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZNK6R2Line5PointEv(ptr dead_on_unwind writable sret(%class.R2Point) align 8 %15, ptr noundef nonnull align 8 dereferenceable(40) %42)
  %43 = call noundef i32 @_Z10R2ContainsRK6R2LineRK7R2Point(ptr noundef nonnull align 8 dereferenceable(40) %41, ptr noundef nonnull align 8 dereferenceable(16) %15)
  %44 = icmp ne i32 %43, 0
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #6
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  store i32 2, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %74

46:                                               ; preds = %40
  store i32 0, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %74

47:                                               ; preds = %3
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %73

50:                                               ; preds = %47
  %51 = load double, ptr %12, align 8, !tbaa !9
  %52 = load double, ptr %10, align 8, !tbaa !9
  %53 = load double, ptr %9, align 8, !tbaa !9
  %54 = load double, ptr %13, align 8, !tbaa !9
  %55 = fmul double %53, %54
  %56 = fneg double %55
  %57 = call double @llvm.fmuladd.f64(double %51, double %52, double %56)
  %58 = load double, ptr %14, align 8, !tbaa !9
  %59 = fdiv double %57, %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16) %60, i32 noundef 0)
  store double %59, ptr %61, align 8, !tbaa !9
  %62 = load double, ptr %8, align 8, !tbaa !9
  %63 = load double, ptr %13, align 8, !tbaa !9
  %64 = load double, ptr %11, align 8, !tbaa !9
  %65 = load double, ptr %10, align 8, !tbaa !9
  %66 = fmul double %64, %65
  %67 = fneg double %66
  %68 = call double @llvm.fmuladd.f64(double %62, double %63, double %67)
  %69 = load double, ptr %14, align 8, !tbaa !9
  %70 = fdiv double %68, %69
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16) %71, i32 noundef 1)
  store double %70, ptr %72, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %50, %47
  store i32 1, ptr %4, align 4
  store i32 1, ptr %16, align 4
  br label %74

74:                                               ; preds = %73, %46, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40)) #4 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK6R2Line5PointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3 align 2

attributes #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 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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++ 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"

%class.R2Point = type { [2 x double] }

@RN_EPSILON = external local_unnamed_addr global double, align 8

declare noundef i32 @_Z10R2ContainsRK6R2LineRK7R2Point(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 3) i32 @_Z12R2IntersectsRK6R2LineS1_P7R2Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %class.R2Point, align 8
  %5 = tail call noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %6 = tail call noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %7 = tail call noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %8 = tail call noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %9 = tail call noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %10 = tail call noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %11 = fneg double %5
  %12 = fmul double %9, %11
  %13 = tail call double @llvm.fmuladd.f64(double %8, double %6, double %12)
  %14 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %15 = tail call noundef i32 @_Z8RNIsZerodd(double noundef %13, double noundef %14)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %18, label %16

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #6
  call void @_ZNK6R2Line5PointEv(ptr dead_on_unwind nonnull writable sret(%class.R2Point) align 8 %4, ptr noundef nonnull align 8 dereferenceable(40) %1)
  %17 = call noundef i32 @_Z10R2ContainsRK6R2LineRK7R2Point(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(16) %4)
  %.not28 = icmp eq i32 %17, 0
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #6
  %. = select i1 %.not28, i32 0, i32 2
  br label %30

18:                                               ; preds = %3
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %30, label %19

19:                                               ; preds = %18
  %20 = fneg double %6
  %21 = fmul double %10, %20
  %22 = tail call double @llvm.fmuladd.f64(double %9, double %7, double %21)
  %23 = fdiv double %22, %13
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef 0)
  store double %23, ptr %24, align 8, !tbaa !5
  %25 = fneg double %8
  %26 = fmul double %7, %25
  %27 = tail call double @llvm.fmuladd.f64(double %5, double %10, double %26)
  %28 = fdiv double %27, %13
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef 1)
  store double %28, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %18, %19, %16
  %.0 = phi i32 [ %., %16 ], [ 1, %19 ], [ 1, %18 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Line1AEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Line1BEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK6R2Line1CEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #4 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK6R2Line5PointEv(ptr dead_on_unwind noalias writable sret(%class.R2Point) align 8, ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN7R2PointixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #3 align 2

attributes #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 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #5 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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