; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数学算法/三分求极值.ll (Z14maximum_doubledd)

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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z14maximum_doubledd(double noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %32, %2
  %8 = load double, ptr %4, align 8, !tbaa !5
  %9 = load double, ptr %3, align 8, !tbaa !5
  %10 = fsub double %8, %9
  %11 = fcmp ogt double %10, 0x3EB0C6F7A0B5ED8D
  br i1 %11, label %12, label %33

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = load double, ptr %4, align 8, !tbaa !5
  %15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %13, double %14)
  %16 = fdiv double %15, 3.000000e+00
  store double %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = load double, ptr %3, align 8, !tbaa !5
  %19 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double %18)
  %20 = fdiv double %19, 3.000000e+00
  store double %20, ptr %6, align 8, !tbaa !5
  %21 = load double, ptr %5, align 8, !tbaa !5
  %22 = fsub double %21, 8.000000e+00
  %23 = call double @llvm.fabs.f64(double %22)
  %24 = load double, ptr %6, align 8, !tbaa !5
  %25 = fsub double %24, 8.000000e+00
  %26 = call double @llvm.fabs.f64(double %25)
  %27 = fcmp ogt double %23, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %12
  %29 = load double, ptr %6, align 8, !tbaa !5
  store double %29, ptr %4, align 8, !tbaa !5
  br label %32

30:                                               ; preds = %12
  %31 = load double, ptr %5, align 8, !tbaa !5
  store double %31, ptr %3, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %30, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %7, !llvm.loop !9

33:                                               ; preds = %7
  %34 = load double, ptr %3, align 8, !tbaa !5
  ret double %34
}

; 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

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


; 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 noundef double @_Z14maximum_doubledd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fsub double %1, %0
  %4 = fcmp ogt double %3, 0x3EB0C6F7A0B5ED8D
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %5 = insertelement <2 x double> poison, double %1, i64 0
  %6 = insertelement <2 x double> %5, double %0, i64 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %7 = phi <2 x double> [ %20, %.lr.ph ], [ %6, %.lr.ph.preheader ]
  %8 = shufflevector <2 x double> %7, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %9 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %7, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> %8)
  %10 = fdiv <2 x double> %9, <double 3.000000e+00, double 3.000000e+00>
  %11 = fadd <2 x double> %10, <double -8.000000e+00, double -8.000000e+00>
  %12 = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %11)
  %13 = extractelement <2 x double> %12, i64 0
  %14 = extractelement <2 x double> %12, i64 1
  %15 = fcmp ogt double %14, %13
  %16 = insertelement <2 x i1> poison, i1 %15, i64 0
  %17 = shufflevector <2 x i1> %16, <2 x i1> poison, <2 x i32> zeroinitializer
  %18 = shufflevector <2 x double> %10, <2 x double> %7, <2 x i32> <i32 0, i32 3>
  %19 = shufflevector <2 x double> %7, <2 x double> %10, <2 x i32> <i32 0, i32 3>
  %20 = select <2 x i1> %17, <2 x double> %18, <2 x double> %19
  %21 = extractelement <2 x double> %20, i64 0
  %22 = extractelement <2 x double> %20, i64 1
  %23 = fsub double %21, %22
  %24 = fcmp ogt double %23, 0x3EB0C6F7A0B5ED8D
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.0.lcssa = phi double [ %0, %2 ], [ %22, %.lr.ph ]
  ret double %.0.lcssa
}

; 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>) #1

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

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass