; LLVM IR from stillwater-sc/universal :: applications/accuracy/roots/rpoly_ak1.ll (Z10QuadSD_ak1iddPdS_S_S_)

; 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 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 @_Z10QuadSD_ak1iddPdS_S_S_(i32 noundef %0, double noundef %1, double noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store double %1, ptr %9, align 8, !tbaa !9
  store double %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !11
  store ptr %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %16 = load ptr, ptr %11, align 8, !tbaa !11
  %17 = getelementptr inbounds double, ptr %16, i64 0
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %14, align 8, !tbaa !11
  store double %18, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %12, align 8, !tbaa !11
  %21 = getelementptr inbounds double, ptr %20, i64 0
  store double %18, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %14, align 8, !tbaa !11
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = load double, ptr %9, align 8, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !11
  %26 = getelementptr inbounds double, ptr %25, i64 1
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fneg double %23
  %29 = call double @llvm.fmuladd.f64(double %28, double %24, double %27)
  %30 = load ptr, ptr %13, align 8, !tbaa !11
  store double %29, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %12, align 8, !tbaa !11
  %32 = getelementptr inbounds double, ptr %31, i64 1
  store double %29, ptr %32, align 8, !tbaa !9
  store i32 2, ptr %15, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %66, %7
  %34 = load i32, ptr %15, align 4, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %69

37:                                               ; preds = %33
  %38 = load ptr, ptr %13, align 8, !tbaa !11
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load double, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %14, align 8, !tbaa !11
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = load double, ptr %10, align 8, !tbaa !9
  %44 = fmul double %42, %43
  %45 = call double @llvm.fmuladd.f64(double %39, double %40, double %44)
  %46 = fneg double %45
  %47 = load ptr, ptr %11, align 8, !tbaa !11
  %48 = load i32, ptr %15, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fadd double %46, %51
  %53 = load ptr, ptr %12, align 8, !tbaa !11
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  store double %52, ptr %56, align 8, !tbaa !9
  %57 = load ptr, ptr %13, align 8, !tbaa !11
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %14, align 8, !tbaa !11
  store double %58, ptr %59, align 8, !tbaa !9
  %60 = load ptr, ptr %12, align 8, !tbaa !11
  %61 = load i32, ptr %15, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !9
  %65 = load ptr, ptr %13, align 8, !tbaa !11
  store double %64, ptr %65, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %37
  %67 = load i32, ptr %15, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %15, align 4, !tbaa !5
  br label %33, !llvm.loop !13

69:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #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 = !{!"int", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z10QuadSD_ak1iddPdS_S_S_(i32 noundef %0, double noundef %1, double noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef %4, ptr nocapture noundef %5, ptr nocapture noundef %6) local_unnamed_addr #1 {
  %8 = load double, ptr %3, align 8, !tbaa !5
  store double %8, ptr %6, align 8, !tbaa !5
  store double %8, ptr %4, align 8, !tbaa !5
  %9 = load double, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fneg double %9
  %13 = tail call double @llvm.fmuladd.f64(double %12, double %1, double %11)
  store double %13, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  store double %13, ptr %14, align 8, !tbaa !5
  %15 = icmp sgt i32 %0, 2
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %wide.trip.count = zext nneg i32 %0 to i64
  %.pre = load double, ptr %5, align 8, !tbaa !5
  %xtraiter = and i64 %wide.trip.count, 1
  %16 = icmp eq i32 %0, 3
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %17 = and i64 %wide.trip.count, 2147483646
  %18 = add nsw i64 %17, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %19 = phi double [ %.pre, %.lr.ph.preheader.new ], [ %37, %.lr.ph ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %20 = load double, ptr %6, align 8, !tbaa !5
  %21 = fmul double %20, %2
  %22 = tail call double @llvm.fmuladd.f64(double %19, double %1, double %21)
  %23 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fsub double %24, %22
  %26 = getelementptr inbounds double, ptr %4, i64 %indvars.iv
  store double %25, ptr %26, align 8, !tbaa !5
  %27 = load double, ptr %5, align 8, !tbaa !5
  store double %27, ptr %6, align 8, !tbaa !5
  %28 = load double, ptr %26, align 8, !tbaa !5
  store double %28, ptr %5, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = load double, ptr %6, align 8, !tbaa !5
  %30 = fmul double %29, %2
  %31 = tail call double @llvm.fmuladd.f64(double %28, double %1, double %30)
  %32 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fsub double %33, %31
  %35 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next
  store double %34, ptr %35, align 8, !tbaa !5
  %36 = load double, ptr %5, align 8, !tbaa !5
  store double %36, ptr %6, align 8, !tbaa !5
  %37 = load double, ptr %35, align 8, !tbaa !5
  store double %37, ptr %5, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %18
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi double [ %.pre, %.lr.ph.preheader ], [ %37, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %38 = load double, ptr %6, align 8, !tbaa !5
  %39 = fmul double %38, %2
  %40 = tail call double @llvm.fmuladd.f64(double %.unr, double %1, double %39)
  %41 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.unr
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fsub double %42, %40
  %44 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.unr
  store double %43, ptr %44, align 8, !tbaa !5
  %45 = load double, ptr %5, align 8, !tbaa !5
  store double %45, ptr %6, align 8, !tbaa !5
  %46 = load double, ptr %44, align 8, !tbaa !5
  store double %46, ptr %5, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %7
  ret void
}

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

!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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass