; LLVM IR from jgaeddert/liquid-dsp :: src/math/src/poly.findroots (liquid_poly_findroots_bairstow_persistent)

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

@.str.6 = external hidden unnamed_addr constant [86 x i8], align 1

; 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: nounwind uwtable
define dso_local i32 @liquid_poly_findroots_bairstow_persistent(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 10, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %58, %5
  %16 = load i32, ptr %12, align 4, !tbaa !9
  %17 = load i32, ptr %13, align 4, !tbaa !9
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %19, label %61

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %20, i32 noundef %21, ptr noundef %22, ptr noundef %23, ptr noundef %24)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %67

28:                                               ; preds = %19
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = sub i32 %30, 1
  %32 = icmp ult i32 %29, %31
  br i1 %32, label %33, label %56

33:                                               ; preds = %28
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = uitofp i32 %34 to float
  %36 = fmul float %35, 0x3FF19999A0000000
  %37 = call float @cosf(float noundef %36) #4
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = uitofp i32 %38 to float
  %40 = fmul float %39, 0x3FC99999A0000000
  %41 = call float @expf(float noundef %40) #4, !tbaa !9
  %42 = fmul float %37, %41
  %43 = fpext float %42 to double
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  store double %43, ptr %44, align 8, !tbaa !11
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = uitofp i32 %45 to float
  %47 = fmul float %46, 0x3FF19999A0000000
  %48 = call float @sinf(float noundef %47) #4
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = uitofp i32 %49 to float
  %51 = fmul float %50, 0x3FC99999A0000000
  %52 = call float @expf(float noundef %51) #4, !tbaa !9
  %53 = fmul float %48, %52
  %54 = fpext float %53 to double
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  store double %54, ptr %55, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %33, %28
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %12, align 4, !tbaa !9
  br label %15, !llvm.loop !13

61:                                               ; preds = %15
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, double noundef %63, double noundef 0.000000e+00)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %67

67:                                               ; preds = %61, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %68 = load i32, ptr %6, align 4
  ret i32 %68
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare float @cosf(float noundef) #3

; Function Attrs: nounwind
declare float @expf(float noundef) #3

; Function Attrs: nounwind
declare float @sinf(float noundef) #3

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

@.str.6 = external hidden unnamed_addr constant [86 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @liquid_poly_findroots_bairstow_persistent(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %5
  store double 1.000000e+00, ptr %3, align 8, !tbaa !5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  %9 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %8
  store double 0x3FE1BA8F80000000, ptr %3, align 8, !tbaa !5
  store double 0x3FF16A9740000000, ptr %4, align 8, !tbaa !5
  %12 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %11
  store double 0xBFEC1816E0000000, ptr %3, align 8, !tbaa !5
  store double 0x3FF34C5420000000, ptr %4, align 8, !tbaa !5
  %15 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %14
  store double 0xBFFCC9F480000000, ptr %3, align 8, !tbaa !5
  store double 0xBFD2654820000000, ptr %4, align 8, !tbaa !5
  %18 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %.loopexit, label %20

20:                                               ; preds = %17
  store double 0xBFE5E32D80000000, ptr %3, align 8, !tbaa !5
  store double 0xC000F15080000000, ptr %4, align 8, !tbaa !5
  %21 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %20
  store double 0x3FFED26340000000, ptr %3, align 8, !tbaa !5
  store double 0xBFFEAF8B20000000, ptr %4, align 8, !tbaa !5
  %24 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.loopexit, label %26

26:                                               ; preds = %23
  store double 0x40093D3340000000, ptr %3, align 8, !tbaa !5
  store double 0x3FF08CB7E0000000, ptr %4, align 8, !tbaa !5
  %27 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %.loopexit, label %29

29:                                               ; preds = %26
  store double 0x3FE3E719E0000000, ptr %3, align 8, !tbaa !5
  store double 0x40100764C0000000, ptr %4, align 8, !tbaa !5
  %30 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %.loopexit, label %32

32:                                               ; preds = %29
  store double 0xC01011C9A0000000, ptr %3, align 8, !tbaa !5
  store double 0x40072D4980000000, ptr %4, align 8, !tbaa !5
  %33 = tail call i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %.loopexit, label %._crit_edge28

._crit_edge28:                                    ; preds = %32
  %.pre = load double, ptr %3, align 8, !tbaa !5
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, double noundef %.pre, double noundef 0.000000e+00)
  br label %.loopexit

.loopexit:                                        ; preds = %5, %8, %11, %14, %17, %20, %23, %26, %29, %32, %._crit_edge28
  %.0 = phi i32 [ 1, %._crit_edge28 ], [ 0, %32 ], [ 0, %29 ], [ 0, %26 ], [ 0, %23 ], [ 0, %20 ], [ 0, %17 ], [ 0, %14 ], [ 0, %11 ], [ 0, %8 ], [ 0, %5 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @liquid_poly_findroots_bairstow_recursion(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { nofree 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" }

!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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass