; LLVM IR from ippeb/ACM-ICPC :: computational_geometry/line_line_intersection (line_line_intersection)

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

%struct.point = type { double, double }
%struct.line = type { double, double, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z14points_to_line5pointS_P4line(double %0, double %1, double %2, double %3, ptr noundef %4) #0 {
  %6 = alloca %struct.point, align 8
  %7 = alloca %struct.point, align 8
  %8 = alloca ptr, align 8
  %9 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  store double %0, ptr %9, align 8
  %10 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  store double %1, ptr %10, align 8
  %11 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  store double %2, ptr %11, align 8
  %12 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  store double %3, ptr %12, align 8
  store ptr %4, ptr %8, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.point, ptr %7, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fcmp oeq double %14, %16
  br i1 %17, label %18, label %28

18:                                               ; preds = %5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.line, ptr %19, i32 0, i32 0
  store double 1.000000e+00, ptr %20, align 8, !tbaa !12
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.line, ptr %21, i32 0, i32 1
  store double 0.000000e+00, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fneg double %24
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.line, ptr %26, i32 0, i32 2
  store double %25, ptr %27, align 8, !tbaa !15
  br label %61

28:                                               ; preds = %5
  %29 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 1
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.point, ptr %7, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = fsub double %30, %32
  %34 = fneg double %33
  %35 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.point, ptr %7, i32 0, i32 0
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fsub double %36, %38
  %40 = fdiv double %34, %39
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.line, ptr %41, i32 0, i32 0
  store double %40, ptr %42, align 8, !tbaa !12
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.line, ptr %43, i32 0, i32 1
  store double 1.000000e+00, ptr %44, align 8, !tbaa !14
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.line, ptr %45, i32 0, i32 0
  %47 = load double, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.line, ptr %50, i32 0, i32 1
  %52 = load double, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 1
  %54 = load double, ptr %53, align 8, !tbaa !16
  %55 = fmul double %52, %54
  %56 = fneg double %47
  %57 = fneg double %55
  %58 = call double @llvm.fmuladd.f64(double %56, double %49, double %57)
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.line, ptr %59, i32 0, i32 2
  store double %58, ptr %60, align 8, !tbaa !15
  br label %61

61:                                               ; preds = %28, %18
  ret void
}

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

attributes #0 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS5point", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTS4line", !11, i64 0, !11, i64 8, !11, i64 16}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !11, i64 16}
!16 = !{!10, !11, i64 8}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_Z14points_to_line5pointS_P4line(double %0, double %1, double %2, double %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = fcmp oeq double %0, %2
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  %8 = fneg double %0
  br label %17

9:                                                ; preds = %5
  %10 = fsub double %1, %3
  %11 = fneg double %10
  %12 = fsub double %0, %2
  %13 = fdiv double %11, %12
  %14 = fneg double %13
  %15 = fneg double %1
  %16 = tail call double @llvm.fmuladd.f64(double %14, double %0, double %15)
  br label %17

17:                                               ; preds = %9, %7
  %.sink16 = phi double [ 1.000000e+00, %7 ], [ %13, %9 ]
  %.sink15 = phi double [ 0.000000e+00, %7 ], [ 1.000000e+00, %9 ]
  %.sink = phi double [ %8, %7 ], [ %16, %9 ]
  store double %.sink16, ptr %4, align 8
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  store double %.sink15, ptr %18, align 8
  %19 = getelementptr inbounds i8, ptr %4, i64 16
  store double %.sink, ptr %19, align 8
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 = { mustprogress 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)"}


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