; LLVM IR from AlgoGenesis/C :: Greedy Algorithms/Ramer-Douglas-Peucker AlgorithmRamer-Douglas-Peucker Algorithm (perpendicularDistance)

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

; Function Attrs: nounwind uwtable
define dso_local double @perpendicularDistance(double %0, double %1, double %2, double %3, double %4, double %5) #0 {
  %7 = alloca %struct.Point, align 8
  %8 = alloca %struct.Point, align 8
  %9 = alloca %struct.Point, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  store double %0, ptr %12, align 8
  %13 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  store double %1, ptr %13, align 8
  %14 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  store double %2, ptr %14, align 8
  %15 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  store double %3, ptr %15, align 8
  %16 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 0
  store double %4, ptr %16, align 8
  %17 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 1
  store double %5, ptr %17, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %18 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 1
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 1
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %19, %21
  %23 = getelementptr inbounds %struct.Point, ptr %7, i32 0, i32 0
  %24 = load double, ptr %23, align 8, !tbaa !10
  %25 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !10
  %27 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !10
  %29 = fsub double %26, %28
  %30 = getelementptr inbounds %struct.Point, ptr %7, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fmul double %29, %31
  %33 = fneg double %32
  %34 = call double @llvm.fmuladd.f64(double %22, double %24, double %33)
  %35 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 0
  %36 = load double, ptr %35, align 8, !tbaa !10
  %37 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = call double @llvm.fmuladd.f64(double %36, double %38, double %34)
  %40 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 1
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 0
  %43 = load double, ptr %42, align 8, !tbaa !10
  %44 = fneg double %41
  %45 = call double @llvm.fmuladd.f64(double %44, double %43, double %39)
  %46 = call double @llvm.fabs.f64(double %45)
  store double %46, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %47 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 1
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 1
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = fsub double %48, %50
  %52 = call double @pow(double noundef %51, double noundef 2.000000e+00) #4
  %53 = getelementptr inbounds %struct.Point, ptr %9, i32 0, i32 0
  %54 = load double, ptr %53, align 8, !tbaa !10
  %55 = getelementptr inbounds %struct.Point, ptr %8, i32 0, i32 0
  %56 = load double, ptr %55, align 8, !tbaa !10
  %57 = fsub double %54, %56
  %58 = call double @pow(double noundef %57, double noundef 2.000000e+00) #4
  %59 = fadd double %52, %58
  %60 = call double @sqrt(double noundef %59) #4
  store double %60, ptr %11, align 8, !tbaa !11
  %61 = load double, ptr %10, align 8, !tbaa !11
  %62 = load double, ptr %11, align 8, !tbaa !11
  %63 = fdiv double %61, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  ret double %63
}

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

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

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local double @perpendicularDistance(double %0, double %1, double %2, double %3, double %4, double %5) local_unnamed_addr #0 {
  %7 = fsub double %5, %3
  %8 = fsub double %4, %2
  %9 = fneg double %8
  %10 = fmul double %9, %1
  %11 = tail call double @llvm.fmuladd.f64(double %7, double %0, double %10)
  %12 = tail call double @llvm.fmuladd.f64(double %4, double %3, double %11)
  %13 = fneg double %5
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %2, double %12)
  %15 = tail call double @llvm.fabs.f64(double %14)
  %square = fmul double %7, %7
  %square13 = fmul double %8, %8
  %16 = fadd double %square13, %square
  %sqrt = tail call double @llvm.sqrt.f64(double %16)
  %17 = fdiv double %15, %sqrt
  ret double %17
}

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

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

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

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


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