; LLVM IR from jgaeddert/liquid-dsp :: src/math/bench (polyfit_benchmark)

; 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: nounwind uwtable
define dso_local void @polyf_fit_bench(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %16 = load i32, ptr %10, align 4, !tbaa !9
  %17 = uitofp i32 %16 to double
  %18 = fmul double 3.381000e-02, %17
  %19 = call double @llvm.fmuladd.f64(double %18, double 4.000000e+01, double 2.953000e-01)
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = uitofp i64 %21 to double
  %23 = fdiv double %22, %19
  %24 = fptoui double %23 to i64
  store i64 %24, ptr %20, align 8, !tbaa !11
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = icmp ult i64 %26, 1
  br i1 %27, label %28, label %30

28:                                               ; preds = %5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 1, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %28, %5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = call ptr @llvm.stacksave.p0()
  store ptr %34, ptr %11, align 8
  %35 = alloca float, i64 %33, align 16
  store i64 %33, ptr %12, align 8
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = alloca float, i64 %37, align 16
  store i64 %37, ptr %13, align 8
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = alloca float, i64 %40, align 16
  store i64 %40, ptr %14, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %55, %30
  %43 = load i32, ptr %15, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %58

46:                                               ; preds = %42
  %47 = call float (...) @randnf()
  %48 = load i32, ptr %15, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %38, i64 %49
  store float %47, ptr %50, align 4, !tbaa !13
  %51 = call float (...) @randnf()
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %41, i64 %53
  store float %51, ptr %54, align 4, !tbaa !13
  br label %55

55:                                               ; preds = %46
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %15, align 4, !tbaa !9
  br label %42, !llvm.loop !15

58:                                               ; preds = %42
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call i32 @getrusage(i32 noundef 0, ptr noundef %59) #6
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %84, %58
  %62 = load i32, ptr %15, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = icmp ult i64 %63, %65
  br i1 %66, label %67, label %87

67:                                               ; preds = %61
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = add i32 %69, 1
  %71 = call i32 @polyf_fit(ptr noundef %38, ptr noundef %41, i32 noundef %68, ptr noundef %35, i32 noundef %70)
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = add i32 %73, 1
  %75 = call i32 @polyf_fit(ptr noundef %38, ptr noundef %41, i32 noundef %72, ptr noundef %35, i32 noundef %74)
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = add i32 %77, 1
  %79 = call i32 @polyf_fit(ptr noundef %38, ptr noundef %41, i32 noundef %76, ptr noundef %35, i32 noundef %78)
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = add i32 %81, 1
  %83 = call i32 @polyf_fit(ptr noundef %38, ptr noundef %41, i32 noundef %80, ptr noundef %35, i32 noundef %82)
  br label %84

84:                                               ; preds = %67
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %15, align 4, !tbaa !9
  br label %61, !llvm.loop !17

87:                                               ; preds = %61
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = call i32 @getrusage(i32 noundef 0, ptr noundef %88) #6
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load i64, ptr %90, align 8, !tbaa !11
  %92 = mul i64 %91, 4
  store i64 %92, ptr %90, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  %93 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %93)
  ret void
}

; 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
declare ptr @llvm.stacksave.p0() #2

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

declare float @randnf(...) #4

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) #5

declare i32 @polyf_fit(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 #6 = { 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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: nounwind uwtable
define dso_local void @polyf_fit_bench(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = uitofp i32 %4 to double
  %7 = fmul double %6, 3.381000e-02
  %8 = tail call double @llvm.fmuladd.f64(double %7, double 4.000000e+01, double 2.953000e-01)
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = uitofp i64 %9 to double
  %11 = fdiv double %10, %8
  %12 = fptoui double %11 to i64
  %spec.select = tail call i64 @llvm.umax.i64(i64 %12, i64 1)
  store i64 %spec.select, ptr %2, align 8, !tbaa !5
  %13 = add i32 %3, 1
  %14 = zext i32 %13 to i64
  %15 = alloca float, i64 %14, align 16
  %16 = zext i32 %4 to i64
  %17 = alloca float, i64 %16, align 16
  %18 = alloca float, i64 %16, align 16
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %19 = tail call float (...) @randnf() #5
  %20 = getelementptr inbounds float, ptr %17, i64 %indvars.iv
  store float %19, ptr %20, align 4, !tbaa !9
  %21 = tail call float (...) @randnf() #5
  %22 = getelementptr inbounds float, ptr %18, i64 %indvars.iv
  store float %21, ptr %22, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %16
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %5
  %23 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #5
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %.not32 = icmp eq i64 %24, 0
  br i1 %.not32, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %._crit_edge, %.lr.ph30
  %.128 = phi i32 [ %29, %.lr.ph30 ], [ 0, %._crit_edge ]
  %25 = call i32 @polyf_fit(ptr noundef nonnull %17, ptr noundef nonnull %18, i32 noundef %4, ptr noundef nonnull %15, i32 noundef %13) #5
  %26 = call i32 @polyf_fit(ptr noundef nonnull %17, ptr noundef nonnull %18, i32 noundef %4, ptr noundef nonnull %15, i32 noundef %13) #5
  %27 = call i32 @polyf_fit(ptr noundef nonnull %17, ptr noundef nonnull %18, i32 noundef %4, ptr noundef nonnull %15, i32 noundef %13) #5
  %28 = call i32 @polyf_fit(ptr noundef nonnull %17, ptr noundef nonnull %18, i32 noundef %4, ptr noundef nonnull %15, i32 noundef %13) #5
  %29 = add i32 %.128, 1
  %30 = zext i32 %29 to i64
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = icmp ugt i64 %31, %30
  br i1 %32, label %.lr.ph30, label %._crit_edge31, !llvm.loop !13

._crit_edge31:                                    ; preds = %.lr.ph30, %._crit_edge
  %33 = call i32 @getrusage(i32 noundef 0, ptr noundef %1) #5
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = shl i64 %34, 2
  store i64 %35, ptr %2, align 8, !tbaa !5
  ret void
}

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

declare float @randnf(...) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @polyf_fit(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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