; LLVM IR from bbenligiray/stag :: src/ED/LineSegment.ll (Z21FindIntersectionPointP11LineSegmentS0_PdS1_)

; 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.LineSegment = type { double, double, i32, double, double, double, double, i32, i32, i32 }

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z21FindIntersectionPointP11LineSegmentS0_PdS1_(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.LineSegment, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %44

15:                                               ; preds = %4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LineSegment, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %44

20:                                               ; preds = %15
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.LineSegment, ptr %21, i32 0, i32 0
  %23 = load double, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.LineSegment, ptr %24, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !14
  %27 = fsub double %23, %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LineSegment, ptr %28, i32 0, i32 1
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LineSegment, ptr %31, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = fsub double %30, %33
  %35 = fdiv double %27, %34
  store double %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LineSegment, ptr %36, i32 0, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = load double, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LineSegment, ptr %40, i32 0, i32 0
  %42 = load double, ptr %41, align 8, !tbaa !14
  %43 = call double @llvm.fmuladd.f64(double %38, double %39, double %42)
  store double %43, ptr %10, align 8, !tbaa !9
  br label %146

44:                                               ; preds = %15, %4
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LineSegment, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %82

49:                                               ; preds = %44
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.LineSegment, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !11
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %82

54:                                               ; preds = %49
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.LineSegment, ptr %55, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !15
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.LineSegment, ptr %58, i32 0, i32 0
  %60 = load double, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LineSegment, ptr %61, i32 0, i32 0
  %63 = load double, ptr %62, align 8, !tbaa !14
  %64 = call double @llvm.fmuladd.f64(double %57, double %60, double %63)
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LineSegment, ptr %65, i32 0, i32 1
  %67 = load double, ptr %66, align 8, !tbaa !15
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.LineSegment, ptr %68, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !15
  %71 = fneg double %67
  %72 = call double @llvm.fmuladd.f64(double %71, double %70, double 1.000000e+00)
  %73 = fdiv double %64, %72
  store double %73, ptr %9, align 8, !tbaa !9
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LineSegment, ptr %74, i32 0, i32 1
  %76 = load double, ptr %75, align 8, !tbaa !15
  %77 = load double, ptr %9, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.LineSegment, ptr %78, i32 0, i32 0
  %80 = load double, ptr %79, align 8, !tbaa !14
  %81 = call double @llvm.fmuladd.f64(double %76, double %77, double %80)
  store double %81, ptr %10, align 8, !tbaa !9
  br label %145

82:                                               ; preds = %49, %44
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.LineSegment, ptr %83, i32 0, i32 2
  %85 = load i32, ptr %84, align 8, !tbaa !11
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %120

87:                                               ; preds = %82
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LineSegment, ptr %88, i32 0, i32 2
  %90 = load i32, ptr %89, align 8, !tbaa !11
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %92, label %120

92:                                               ; preds = %87
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.LineSegment, ptr %93, i32 0, i32 1
  %95 = load double, ptr %94, align 8, !tbaa !15
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.LineSegment, ptr %96, i32 0, i32 0
  %98 = load double, ptr %97, align 8, !tbaa !14
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.LineSegment, ptr %99, i32 0, i32 0
  %101 = load double, ptr %100, align 8, !tbaa !14
  %102 = call double @llvm.fmuladd.f64(double %95, double %98, double %101)
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.LineSegment, ptr %103, i32 0, i32 1
  %105 = load double, ptr %104, align 8, !tbaa !15
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.LineSegment, ptr %106, i32 0, i32 1
  %108 = load double, ptr %107, align 8, !tbaa !15
  %109 = fneg double %105
  %110 = call double @llvm.fmuladd.f64(double %109, double %108, double 1.000000e+00)
  %111 = fdiv double %102, %110
  store double %111, ptr %10, align 8, !tbaa !9
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.LineSegment, ptr %112, i32 0, i32 1
  %114 = load double, ptr %113, align 8, !tbaa !15
  %115 = load double, ptr %10, align 8, !tbaa !9
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.LineSegment, ptr %116, i32 0, i32 0
  %118 = load double, ptr %117, align 8, !tbaa !14
  %119 = call double @llvm.fmuladd.f64(double %114, double %115, double %118)
  store double %119, ptr %9, align 8, !tbaa !9
  br label %144

120:                                              ; preds = %87, %82
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.LineSegment, ptr %121, i32 0, i32 0
  %123 = load double, ptr %122, align 8, !tbaa !14
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.LineSegment, ptr %124, i32 0, i32 0
  %126 = load double, ptr %125, align 8, !tbaa !14
  %127 = fsub double %123, %126
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.LineSegment, ptr %128, i32 0, i32 1
  %130 = load double, ptr %129, align 8, !tbaa !15
  %131 = load ptr, ptr %5, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.LineSegment, ptr %131, i32 0, i32 1
  %133 = load double, ptr %132, align 8, !tbaa !15
  %134 = fsub double %130, %133
  %135 = fdiv double %127, %134
  store double %135, ptr %10, align 8, !tbaa !9
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.LineSegment, ptr %136, i32 0, i32 1
  %138 = load double, ptr %137, align 8, !tbaa !15
  %139 = load double, ptr %10, align 8, !tbaa !9
  %140 = load ptr, ptr %5, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.LineSegment, ptr %140, i32 0, i32 0
  %142 = load double, ptr %141, align 8, !tbaa !14
  %143 = call double @llvm.fmuladd.f64(double %138, double %139, double %142)
  store double %143, ptr %9, align 8, !tbaa !9
  br label %144

144:                                              ; preds = %120, %92
  br label %145

145:                                              ; preds = %144, %54
  br label %146

146:                                              ; preds = %145, %20
  %147 = load double, ptr %9, align 8, !tbaa !9
  %148 = load ptr, ptr %7, align 8, !tbaa !5
  store double %147, ptr %148, align 8, !tbaa !9
  %149 = load double, ptr %10, align 8, !tbaa !9
  %150 = load ptr, ptr %8, align 8, !tbaa !5
  store double %149, ptr %150, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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}
!11 = !{!12, !13, i64 16}
!12 = !{!"_ZTS11LineSegment", !10, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !13, i64 56, !13, i64 60, !13, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_Z21FindIntersectionPointP11LineSegmentS0_PdS1_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  switch i32 %6, label %.thread41 [
    i32 0, label %7
    i32 1, label %37
  ]

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !5
  switch i32 %9, label %.thread41 [
    i32 0, label %10
    i32 1, label %21
  ]

10:                                               ; preds = %7
  %11 = load double, ptr %1, align 8, !tbaa !11
  %12 = load double, ptr %0, align 8, !tbaa !11
  %13 = fsub double %11, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = load double, ptr %16, align 8, !tbaa !12
  %18 = fsub double %15, %17
  %19 = fdiv double %13, %18
  %20 = tail call double @llvm.fmuladd.f64(double %15, double %19, double %12)
  br label %63

21:                                               ; preds = %7
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = load double, ptr %1, align 8, !tbaa !11
  %25 = fneg double %23
  %26 = load <2 x double>, ptr %0, align 8, !tbaa !13
  %27 = insertelement <2 x double> poison, double %23, i64 0
  %28 = insertelement <2 x double> %27, double %25, i64 1
  %29 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %24, i64 0
  %30 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %26, <2 x double> %29)
  %31 = extractelement <2 x double> %30, i64 0
  %32 = extractelement <2 x double> %30, i64 1
  %33 = fdiv double %31, %32
  %34 = extractelement <2 x double> %26, i64 0
  %35 = extractelement <2 x double> %26, i64 1
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %33, double %34)
  br label %63

37:                                               ; preds = %4
  %38 = getelementptr inbounds i8, ptr %1, i64 16
  %39 = load i32, ptr %38, align 8, !tbaa !5
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %.thread41

41:                                               ; preds = %37
  %42 = getelementptr inbounds i8, ptr %1, i64 8
  %43 = load double, ptr %42, align 8, !tbaa !12
  %44 = load double, ptr %0, align 8, !tbaa !11
  %45 = load double, ptr %1, align 8, !tbaa !11
  %46 = tail call double @llvm.fmuladd.f64(double %43, double %44, double %45)
  %47 = getelementptr inbounds i8, ptr %0, i64 8
  %48 = load double, ptr %47, align 8, !tbaa !12
  %49 = fneg double %48
  %50 = tail call double @llvm.fmuladd.f64(double %49, double %43, double 1.000000e+00)
  %51 = fdiv double %46, %50
  %52 = tail call double @llvm.fmuladd.f64(double %48, double %51, double %44)
  br label %63

.thread41:                                        ; preds = %7, %4, %37
  %53 = load double, ptr %0, align 8, !tbaa !11
  %54 = load double, ptr %1, align 8, !tbaa !11
  %55 = fsub double %53, %54
  %56 = getelementptr inbounds i8, ptr %1, i64 8
  %57 = load double, ptr %56, align 8, !tbaa !12
  %58 = getelementptr inbounds i8, ptr %0, i64 8
  %59 = load double, ptr %58, align 8, !tbaa !12
  %60 = fsub double %57, %59
  %61 = fdiv double %55, %60
  %62 = tail call double @llvm.fmuladd.f64(double %59, double %61, double %53)
  br label %63

63:                                               ; preds = %21, %.thread41, %41, %10
  %.040 = phi double [ %19, %10 ], [ %33, %21 ], [ %52, %41 ], [ %62, %.thread41 ]
  %.0 = phi double [ %20, %10 ], [ %36, %21 ], [ %51, %41 ], [ %61, %.thread41 ]
  store double %.040, ptr %2, align 8, !tbaa !13
  store double %.0, ptr %3, align 8, !tbaa !13
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 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, !10, i64 16}
!6 = !{!"_ZTS11LineSegment", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass