; LLVM IR from Dev-XYS/Algorithms :: Segment-Intersection.ll (Z5cross7segmentS_)

; 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.segment = type { %struct.point, %struct.point }
%struct.point = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z5cross7segmentS_(ptr noundef byval(%struct.segment) align 8 %0, ptr noundef byval(%struct.segment) align 8 %1) #0 {
  %3 = getelementptr inbounds %struct.segment, ptr %0, i32 0, i32 0
  %4 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 0
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.segment, ptr %0, i32 0, i32 1
  %7 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = fsub double %5, %8
  %10 = getelementptr inbounds %struct.segment, ptr %1, i32 0, i32 0
  %11 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 1
  %12 = load double, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.segment, ptr %1, i32 0, i32 1
  %14 = getelementptr inbounds %struct.point, ptr %13, i32 0, i32 1
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = fsub double %12, %15
  %17 = getelementptr inbounds %struct.segment, ptr %0, i32 0, i32 0
  %18 = getelementptr inbounds %struct.point, ptr %17, i32 0, i32 1
  %19 = load double, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds %struct.segment, ptr %0, i32 0, i32 1
  %21 = getelementptr inbounds %struct.point, ptr %20, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !13
  %23 = fsub double %19, %22
  %24 = getelementptr inbounds %struct.segment, ptr %1, i32 0, i32 0
  %25 = getelementptr inbounds %struct.point, ptr %24, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.segment, ptr %1, i32 0, i32 1
  %28 = getelementptr inbounds %struct.point, ptr %27, i32 0, i32 0
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = fsub double %26, %29
  %31 = fmul double %23, %30
  %32 = fneg double %31
  %33 = call double @llvm.fmuladd.f64(double %9, double %16, double %32)
  ret double %33
}

; 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, !8, i64 0}
!6 = !{!"_ZTS7segment", !7, i64 0, !7, i64 16}
!7 = !{!"_ZTS5point", !8, i64 0, !8, i64 8}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!6, !8, i64 16}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !8, i64 24}


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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef double @_Z5cross7segmentS_(ptr nocapture noundef readonly byval(%struct.segment) align 8 %0, ptr nocapture noundef readonly byval(%struct.segment) align 8 %1) local_unnamed_addr #0 {
  %3 = load double, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load double, ptr %4, align 8, !tbaa !11
  %6 = fsub double %3, %5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = getelementptr inbounds i8, ptr %1, i64 24
  %11 = load double, ptr %10, align 8, !tbaa !13
  %12 = fsub double %8, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = fsub double %14, %16
  %18 = load double, ptr %1, align 8, !tbaa !5
  %19 = load double, ptr %9, align 8, !tbaa !11
  %20 = fsub double %18, %19
  %21 = fneg double %17
  %22 = fmul double %20, %21
  %23 = tail call double @llvm.fmuladd.f64(double %6, double %12, double %22)
  ret double %23
}

; 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: read) 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)"}
!5 = !{!6, !8, i64 0}
!6 = !{!"_ZTS7segment", !7, i64 0, !7, i64 16}
!7 = !{!"_ZTS5point", !8, i64 0, !8, i64 8}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!6, !8, i64 16}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !8, i64 24}


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