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

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z20UpdateLineParametersP11LineSegment(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.LineSegment, ptr %5, i32 0, i32 5
  %7 = load double, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.LineSegment, ptr %8, i32 0, i32 3
  %10 = load double, ptr %9, align 8, !tbaa !13
  %11 = fsub double %7, %10
  store double %11, ptr %3, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LineSegment, ptr %12, i32 0, i32 6
  %14 = load double, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LineSegment, ptr %15, i32 0, i32 4
  %17 = load double, ptr %16, align 8, !tbaa !16
  %18 = fsub double %14, %17
  store double %18, ptr %4, align 8, !tbaa !14
  %19 = load double, ptr %3, align 8, !tbaa !14
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = load double, ptr %4, align 8, !tbaa !14
  %22 = call double @llvm.fabs.f64(double %21)
  %23 = fcmp oge double %20, %22
  br i1 %23, label %24, label %63

24:                                               ; preds = %1
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LineSegment, ptr %25, i32 0, i32 2
  store i32 0, ptr %26, align 8, !tbaa !17
  %27 = load double, ptr %4, align 8, !tbaa !14
  %28 = call double @llvm.fabs.f64(double %27)
  %29 = fcmp olt double %28, 1.000000e-03
  br i1 %29, label %30, label %43

30:                                               ; preds = %24
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LineSegment, ptr %31, i32 0, i32 1
  store double 0.000000e+00, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.LineSegment, ptr %33, i32 0, i32 4
  %35 = load double, ptr %34, align 8, !tbaa !16
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LineSegment, ptr %36, i32 0, i32 6
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = fadd double %35, %38
  %40 = fdiv double %39, 2.000000e+00
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LineSegment, ptr %41, i32 0, i32 0
  store double %40, ptr %42, align 8, !tbaa !19
  br label %62

43:                                               ; preds = %24
  %44 = load double, ptr %4, align 8, !tbaa !14
  %45 = load double, ptr %3, align 8, !tbaa !14
  %46 = fdiv double %44, %45
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.LineSegment, ptr %47, i32 0, i32 1
  store double %46, ptr %48, align 8, !tbaa !18
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LineSegment, ptr %49, i32 0, i32 4
  %51 = load double, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.LineSegment, ptr %52, i32 0, i32 1
  %54 = load double, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.LineSegment, ptr %55, i32 0, i32 3
  %57 = load double, ptr %56, align 8, !tbaa !13
  %58 = fneg double %54
  %59 = call double @llvm.fmuladd.f64(double %58, double %57, double %51)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.LineSegment, ptr %60, i32 0, i32 0
  store double %59, ptr %61, align 8, !tbaa !19
  br label %62

62:                                               ; preds = %43, %30
  br label %102

63:                                               ; preds = %1
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.LineSegment, ptr %64, i32 0, i32 2
  store i32 1, ptr %65, align 8, !tbaa !17
  %66 = load double, ptr %3, align 8, !tbaa !14
  %67 = call double @llvm.fabs.f64(double %66)
  %68 = fcmp olt double %67, 1.000000e-03
  br i1 %68, label %69, label %82

69:                                               ; preds = %63
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.LineSegment, ptr %70, i32 0, i32 1
  store double 0.000000e+00, ptr %71, align 8, !tbaa !18
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LineSegment, ptr %72, i32 0, i32 3
  %74 = load double, ptr %73, align 8, !tbaa !13
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.LineSegment, ptr %75, i32 0, i32 5
  %77 = load double, ptr %76, align 8, !tbaa !9
  %78 = fadd double %74, %77
  %79 = fdiv double %78, 2.000000e+00
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.LineSegment, ptr %80, i32 0, i32 0
  store double %79, ptr %81, align 8, !tbaa !19
  br label %101

82:                                               ; preds = %63
  %83 = load double, ptr %3, align 8, !tbaa !14
  %84 = load double, ptr %4, align 8, !tbaa !14
  %85 = fdiv double %83, %84
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.LineSegment, ptr %86, i32 0, i32 1
  store double %85, ptr %87, align 8, !tbaa !18
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LineSegment, ptr %88, i32 0, i32 3
  %90 = load double, ptr %89, align 8, !tbaa !13
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.LineSegment, ptr %91, i32 0, i32 1
  %93 = load double, ptr %92, align 8, !tbaa !18
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.LineSegment, ptr %94, i32 0, i32 4
  %96 = load double, ptr %95, align 8, !tbaa !16
  %97 = fneg double %93
  %98 = call double @llvm.fmuladd.f64(double %97, double %96, double %90)
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.LineSegment, ptr %99, i32 0, i32 0
  store double %98, ptr %100, align 8, !tbaa !19
  br label %101

101:                                              ; preds = %82, %69
  br label %102

102:                                              ; preds = %101, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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, !11, i64 40}
!10 = !{!"_ZTS11LineSegment", !11, i64 0, !11, i64 8, !12, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !12, i64 60, !12, i64 64}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 48}
!16 = !{!10, !11, i64 32}
!17 = !{!10, !12, i64 16}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !11, 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"

; 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 @_Z20UpdateLineParametersP11LineSegment(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load <2 x double>, ptr %2, align 8, !tbaa !5
  %5 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %6 = fsub <2 x double> %4, %5
  %7 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %6)
  %8 = extractelement <2 x double> %7, i64 0
  %9 = extractelement <2 x double> %7, i64 1
  %10 = fcmp ult double %8, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br i1 %10, label %28, label %12

12:                                               ; preds = %1
  store i32 0, ptr %11, align 8, !tbaa !9
  %13 = fcmp olt double %9, 1.000000e-03
  br i1 %13, label %14, label %19

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  store double 0.000000e+00, ptr %15, align 8, !tbaa !12
  %16 = fadd <2 x double> %4, %5
  %17 = extractelement <2 x double> %16, i64 1
  %18 = fmul double %17, 5.000000e-01
  br label %44

19:                                               ; preds = %12
  %20 = extractelement <2 x double> %6, i64 0
  %21 = extractelement <2 x double> %6, i64 1
  %22 = fdiv double %21, %20
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store double %22, ptr %23, align 8, !tbaa !12
  %24 = fneg double %22
  %25 = extractelement <2 x double> %5, i64 0
  %26 = extractelement <2 x double> %5, i64 1
  %27 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %26)
  br label %44

28:                                               ; preds = %1
  store i32 1, ptr %11, align 8, !tbaa !9
  %29 = fcmp olt double %8, 1.000000e-03
  br i1 %29, label %30, label %35

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  store double 0.000000e+00, ptr %31, align 8, !tbaa !12
  %32 = fadd <2 x double> %4, %5
  %33 = extractelement <2 x double> %32, i64 0
  %34 = fmul double %33, 5.000000e-01
  br label %44

35:                                               ; preds = %28
  %36 = extractelement <2 x double> %6, i64 0
  %37 = extractelement <2 x double> %6, i64 1
  %38 = fdiv double %36, %37
  %39 = getelementptr inbounds i8, ptr %0, i64 8
  store double %38, ptr %39, align 8, !tbaa !12
  %40 = fneg double %38
  %41 = extractelement <2 x double> %5, i64 0
  %42 = extractelement <2 x double> %5, i64 1
  %43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %41)
  br label %44

44:                                               ; preds = %30, %35, %14, %19
  %.sink = phi double [ %34, %30 ], [ %43, %35 ], [ %18, %14 ], [ %27, %19 ]
  store double %.sink, ptr %0, align 8, !tbaa !13
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fabs.v2f64(<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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"_ZTS11LineSegment", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass