user: Converte this assembly snippet into its equivalent C code:

```asm
<fast_s_large_n>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x128,%rsp
  mov    %rdi,0xc8(%rsp)
  mov    %rsi,0x80(%rsp)
  mov    %rcx,0x88(%rsp)
  mov    %r8,0x90(%rsp)
  mov    %r9,0x98(%rsp)
  mov    0x170(%rsp),%rsi
  mov    %rsi,0xd0(%rsp)
  mov    0x178(%rsp),%rbx
  mov    %rbx,0xd8(%rsp)
  mov    0x180(%rsp),%rdi
  mov    %rdi,0xe0(%rsp)
  mov    0x188(%rsp),%rax
  mov    %rax,0xe8(%rsp)
  mov    0x190(%rsp),%rax
  mov    %rax,0xc0(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x118(%rsp)
  xor    %eax,%eax
  mov    (%rdx),%edx
  mov    %edx,0x5c(%rsp)
  mov    (%rcx),%r15d
  mov    (%r9),%eax
  mov    %eax,0x54(%rsp)
  mov    0x160(%rsp),%rax
  mov    (%rax),%eax
  mov    %eax,0x78(%rsp)
  mov    0x168(%rsp),%rax
  mov    (%rax),%eax
  mov    %eax,0x18(%rsp)
  mov    %eax,0x104(%rsp)
  mov    (%rsi),%eax
  mov    %eax,0x58(%rsp)
  movsd  (%rbx),%xmm6
  movsd  %xmm6,0x8(%rsp)
  movsd  (%rdi),%xmm7
  movsd  %xmm7,0x10(%rsp)
  movslq %edx,%rax
  lea    0x0(,%rax,8),%rbx
  mov    %rbx,0xa0(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,0x38(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,0x40(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,0x48(%rsp)
  movslq %r15d,%r12
  shl    $0x3,%r12
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,%r14
  mov    %rax,0x28(%rsp)
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,0x30(%rsp)
  test   %r15d,%r15d
  jle    L70
  lea    0x8(%r12),%r13
  mov    %r15d,%ebp
  mov    $0x0,%ebx
  mov    %r15d,0x20(%rsp)
  mov    %rax,%r15
L533:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,(%r14,%rbx,8)
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,(%r15,%rbx,8)
  add    $0x1,%rbx
  cmp    %rbp,%rbx
  jne    L533
  mov    0x20(%rsp),%r15d
L70:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,%rbp
  mov    0x58(%rsp),%ebx
  movslq %ebx,%rax
  shl    $0x3,%rax
  mov    %rax,0x70(%rsp)
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,%rcx
  mov    %rax,0x60(%rsp)
  mov    %ebx,%esi
  test   %ebx,%ebx
  jle    L169
  mov    %rax,%rbx
  mov    %esi,%eax
  lea    (%rcx,%rax,8),%r13
L351:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,(%rbx)
  add    $0x8,%rbx
  cmp    %r13,%rbx
  jne    L351
L169:
  mov    0x70(%rsp),%rdi
  call   <malloc@plt>
  mov    %rax,0xa8(%rsp)
  mov    0x78(%rsp),%r14d
  imul   0x58(%rsp),%r14d
  mov    %r14d,0x7c(%rsp)
  movslq %r14d,%rbx
  shl    $0x3,%rbx
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,%r13
  mov    %rax,0x68(%rsp)
  mov    %rbx,%rdi
  call   <malloc@plt>
  mov    %rax,0xb8(%rsp)
  test   %r14d,%r14d
  jle    L558
  mov    %r13,%rbx
  mov    %r14d,%eax
  lea    0x0(%r13,%rax,8),%r13
L335:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,(%rbx)
  add    $0x8,%rbx
  cmp    %r13,%rbx
  jne    L335
L558:
  mov    0xa0(%rsp),%rdi
  call   <malloc@plt>
  mov    %rax,%rbx
  mov    0x5c(%rsp),%eax
  test   %eax,%eax
  jle    L404
  mov    %rbx,%r13
  mov    %eax,%eax
  lea    (%rbx,%rax,8),%r14
L104:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,0x0(%r13)
  add    $0x8,%r13
  cmp    %r14,%r13
  jne    L104
  mov    0x18(%rsp),%r14d
  imul   0x78(%rsp),%r14d
  movslq %r14d,%r13
  lea    0x0(,%r13,4),%rdi
  call   <malloc@plt>
  mov    %rax,0xb0(%rsp)
  shl    $0x3,%r13
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,0x20(%rsp)
  test   %r14d,%r14d
  jle    L155
L535:
  mov    0x18(%rsp),%rcx
  mov    %rcx,%r13
  mov    %r14d,%eax
  lea    (%rcx,%rax,8),%rax
  mov    %r14d,0xf0(%rsp)
  mov    %rax,%r14
L383:
  mov    %r12,%rdi
  call   <malloc@plt>
  mov    %rax,0x0(%r13)
  add    $0x8,%r13
  cmp    %r14,%r13
  jne    L383
  mov    0xf0(%rsp),%r14d
  cmpl   $0x0,0x5c(%rsp)
  jle    L91
L155:
  mov    0xc8(%rsp),%r9
  mov    %rbx,%rsi
  lea    -0x1(%r15),%eax
  lea    0x8(,%rax,8),%rdi
  mov    $0x0,%r8d
  mov    0xa0(%rsp),%r10
  mov    0x5c(%rsp),%r11d
  jmp    L424
L158:
  movsd  (%rdx),%xmm0
  mov    (%rsi),%rcx
  movsd  %xmm0,(%rcx,%rax,1)
  add    $0x8,%rax
  add    %r10,%rdx
  cmp    %rdi,%rax
  jne    L158
L418:
  add    $0x1,%r8d
  add    $0x8,%r9
  add    $0x8,%rsi
  cmp    %r8d,%r11d
  jle    L389
L424:
  mov    %r9,%rdx
  mov    $0x0,%eax
  test   %r15d,%r15d
  jg     L158
  jmp    L418
L389:
  mov    $0x25,%edi
  mov    $0x0,%eax
  call   <srand@plt>
  mov    0x5c(%rsp),%eax
  lea    -0x1(%rax),%esi
  mov    0xb0(%rsp),%rdx
  mov    %r14d,%edi
  call   <sample_n_outof_N@plt>
  test   %r14d,%r14d
  jle    L89
L440:
  mov    0xb0(%rsp),%rcx
  mov    0x18(%rsp),%rsi
  lea    -0x1(%r15),%eax
  lea    0x8(,%rax,8),%rdi
  mov    $0x0,%r8d
  mov    0x20(%rsp),%r9
  mov    0x80(%rsp),%r10
  jmp    L419
L208:
  movslq (%rcx),%rdx
  mov    (%rbx,%rdx,8),%rdx
  movsd  (%rdx,%rax,1),%xmm0
  mov    (%rsi),%rdx
  movsd  %xmm0,(%rdx,%rax,1)
  add    $0x8,%rax
  cmp    %rdi,%rax
  jne    L208
L312:
  movslq (%rcx),%rax
  movsd  (%r10,%rax,8),%xmm0
  movsd  %xmm0,(%r9,%r8,8)
  add    $0x1,%r8
  add    $0x4,%rcx
  add    $0x8,%rsi
  cmp    %r8d,%r14d
  jle    L89
L419:
  mov    $0x0,%eax
  test   %r15d,%r15d
  jg     L208
  jmp    L312
L356:
  mov    0x58(%rsp),%esi
  mov    0xa8(%rsp),%rdi
  call   <find_max@plt>
  mov    %eax,0x90(%rsp)
  cltq
  mov    0xa8(%rsp),%rcx
  movsd  (%rcx,%rax,8),%xmm5
  movsd  %xmm5,0x70(%rsp)
L55:
  add    $0x1,%r12
  add    $0x8,%r13
  cmp    %r12d,0x7c(%rsp)
  jle    L304
L504:
  push   0x88(%rsp)
  push   %rbp
  push   %r13
  push   $0x0
  mov    0x74(%rsp),%eax
  push   %rax
  mov    0x90(%rsp),%rax
  push   (%rax,%r12,8)
  push   0x60(%rsp)
  push   0x60(%rsp)
  push   0x88(%rsp)
  push   0x88(%rsp)
  movsd  0x60(%rsp),%xmm1
  movsd  0x58(%rsp),%xmm0
  mov    0x50(%rsp),%r9
  mov    %r15d,%r8d
  mov    %r14d,%ecx
  mov    0x88(%rsp),%rdx
  mov    0x70(%rsp),%rsi
  mov    0x68(%rsp),%rdi
  call   <refine_fast_s@plt>
  add    $0x50,%rsp
  movsd  0x10(%rsp),%xmm1
  mov    %r15d,%edx
  mov    %r14d,%esi
  movsd  0x70(%rsp),%xmm0
  mov    (%rsp),%rdi
  call   <loss_rho@plt>
  movsd  0x8(%rsp),%xmm3
  comisd %xmm0,%xmm3
  jbe    L55
  mov    %r15d,%edx
  mov    %r14d,%esi
  movsd  0x108(%rsp),%xmm2
  movsd  0x10(%rsp),%xmm1
  movapd %xmm3,%xmm0
  mov    (%rsp),%rdi
  call   <find_scale@plt>
  movsd  %xmm0,0x108(%rsp)
  movslq 0x90(%rsp),%rax
  lea    0x0(,%rax,8),%rcx
  mov    0xa8(%rsp),%rsi
  movsd  %xmm0,(%rsi,%rax,8)
  test   %r15d,%r15d
  jle    L356
  mov    $0x0,%eax
  mov    0x98(%rsp),%rsi
L270:
  movsd  0x0(%rbp,%rax,1),%xmm0
  mov    (%rbx,%rcx,1),%rdx
  movsd  %xmm0,(%rdx,%rax,1)
  add    $0x8,%rax
  cmp    %rax,%rsi
  jne    L270
  jmp    L356
L304:
  mov    0xa0(%rsp),%rbx
  cmpl   $0x0,0x58(%rsp)
  jle    L238
L460:
  mov    0xa8(%rsp),%r13
  mov    $0x0,%r12d
  movsd  D4(%rip),%xmm6
  movsd  %xmm6,0x70(%rsp)
  lea    0x110(%rsp),%r14
  mov    %rbx,0x88(%rsp)
  mov    0xe8(%rsp),%rbx
  jmp    L113
L396:
  movsd  0x0(%rbp,%rax,8),%xmm0
  movsd  %xmm0,(%rbx,%rax,8)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L396
  movsd  %xmm1,0x70(%rsp)
L447:
  add    $0x1,%r12
  add    $0x8,%r13
  cmp    %r12d,0x58(%rsp)
  jle    L14
L113:
  push   %r14
  push   %rbp
  push   %r13
  push   $0x1
  mov    0x74(%rsp),%eax
  push   %rax
  mov    0x88(%rsp),%rax
  push   (%rax,%r12,8)
  push   0x60(%rsp)
  push   0x60(%rsp)
  push   0x88(%rsp)
  push   0x88(%rsp)
  movsd  0x60(%rsp),%xmm1
  movsd  0x58(%rsp),%xmm0
  mov    0x50(%rsp),%r9
  mov    %r15d,%r8d
  mov    0xac(%rsp),%ecx
  mov    0x88(%rsp),%rdx
  mov    0xd0(%rsp),%rsi
  mov    0xd8(%rsp),%rdi
  call   <refine_fast_s@plt>
  movsd  0x160(%rsp),%xmm1
  add    $0x50,%rsp
  movsd  0x70(%rsp),%xmm4
  comisd %xmm1,%xmm4
  jbe    L447
  mov    0xc0(%rsp),%rax
  movsd  %xmm1,(%rax)
  test   %r15d,%r15d
  jle    L397
  mov    %r15d,%edx
  mov    $0x0,%eax
  jmp    L396
L397:
  movsd  %xmm1,0x70(%rsp)
  jmp    L447
L14:
  mov    0x88(%rsp),%rbx
L238:
  cmpl   $0x0,0x5c(%rsp)
  jle    L61
L353:
  mov    %rbx,%r12
  mov    0x5c(%rsp),%eax
  lea    (%rbx,%rax,8),%r13
L156:
  mov    (%r12),%rdi
  call   <free@plt>
  add    $0x8,%r12
  cmp    %r13,%r12
  jne    L156
L61:
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0xb8(%rsp),%rdi
  call   <free@plt>
  mov    0x7c(%rsp),%eax
  test   %eax,%eax
  jle    L372
  mov    0x68(%rsp),%rsi
  mov    %rsi,%rbx
  mov    %eax,%eax
  lea    (%rsi,%rax,8),%r12
L385:
  mov    (%rbx),%rdi
  call   <free@plt>
  add    $0x8,%rbx
  cmp    %rbx,%r12
  jne    L385
L372:
  mov    0x68(%rsp),%rdi
  call   <free@plt>
  mov    0xb0(%rsp),%rdi
  call   <free@plt>
  mov    0x20(%rsp),%rdi
  call   <free@plt>
  mov    0x78(%rsp),%eax
  imul   0x104(%rsp),%eax
  test   %eax,%eax
  jle    L122
  mov    0x18(%rsp),%rsi
  mov    %rsi,%rbx
  mov    %eax,%eax
  lea    (%rsi,%rax,8),%r12
L252:
  mov    (%rbx),%rdi
  call   <free@plt>
  add    $0x8,%rbx
  cmp    %r12,%rbx
  jne    L252
L122:
  mov    0x18(%rsp),%rdi
  call   <free@plt>
  mov    0x40(%rsp),%rdi
  call   <free@plt>
  mov    0x48(%rsp),%rdi
  call   <free@plt>
  test   %r15d,%r15d
  jle    L408
  mov    %r15d,%r15d
  mov    $0x0,%ebx
  mov    0x28(%rsp),%r12
  mov    0x30(%rsp),%r13
L195:
  mov    (%r12,%rbx,8),%rdi
  call   <free@plt>
  mov    0x0(%r13,%rbx,8),%rdi
  call   <free@plt>
  add    $0x1,%rbx
  cmp    %r15,%rbx
  jne    L195
L408:
  mov    0x28(%rsp),%rdi
  call   <free@plt>
  mov    0x30(%rsp),%rdi
  call   <free@plt>
  mov    0x38(%rsp),%rdi
  call   <free@plt>
  mov    0x58(%rsp),%eax
  test   %eax,%eax
  jle    L298
  mov    0x60(%rsp),%rcx
  mov    %rcx,%rbx
  mov    %eax,%eax
  lea    (%rcx,%rax,8),%r12
L494:
  mov    (%rbx),%rdi
  call   <free@plt>
  add    $0x8,%rbx
  cmp    %rbx,%r12
  jne    L494
L298:
  mov    0x60(%rsp),%rdi
  call   <free@plt>
  mov    0xa8(%rsp),%rdi
  call   <free@plt>
  mov    (%rsp),%rdi
  call   <free@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    0x118(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L1
  add    $0x128,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L519:
  mov    %r15d,%edx
  mov    0x58(%rsp),%esi
  mov    0x60(%rsp),%rdi
  call   <reset_mat@plt>
  mov    0x78(%rsp),%r14d
  imul   0x104(%rsp),%r14d
  cmpl   $0x0,0x7c(%rsp)
  jg     L135
  cmpl   $0x0,0x5c(%rsp)
  jg     L353
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0xb8(%rsp),%rdi
  call   <free@plt>
  jmp    L372
L91:
  mov    $0x25,%edi
  mov    $0x0,%eax
  call   <srand@plt>
  mov    0x5c(%rsp),%eax
  lea    -0x1(%rax),%esi
  mov    0xb0(%rsp),%rdx
  mov    %r14d,%edi
  call   <sample_n_outof_N@plt>
  jmp    L440
L404:
  mov    0x18(%rsp),%r14d
  imul   0x78(%rsp),%r14d
  movslq %r14d,%r13
  lea    0x0(,%r13,4),%rdi
  call   <malloc@plt>
  mov    %rax,0xb0(%rsp)
  shl    $0x3,%r13
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,0x20(%rsp)
  test   %r14d,%r14d
  jg     L535
  mov    $0x25,%edi
  mov    $0x0,%eax
  call   <srand@plt>
  mov    0x5c(%rsp),%eax
  lea    -0x1(%rax),%esi
  mov    0xb0(%rsp),%rdx
  mov    %r14d,%edi
  call   <sample_n_outof_N@plt>
L89:
  cmpl   $0x0,0x78(%rsp)
  jle    L294
  mov    0x68(%rsp),%r14
  mov    0xb8(%rsp),%r13
  mov    $0x0,%r12d
  lea    0x104(%rsp),%rax
  mov    %rax,0xa0(%rsp)
  mov    %r15d,0xc8(%rsp)
  mov    %rbp,0xf0(%rsp)
  mov    %rbx,0xf8(%rsp)
  mov    0xd0(%rsp),%rbx
  mov    0xd8(%rsp),%rbp
  mov    0xe0(%rsp),%r15
L415:
  mov    %r12d,%edi
  imul   0x104(%rsp),%edi
  movslq %edi,%rdi
  shl    $0x3,%rdi
  mov    0x20(%rsp),%rax
  lea    (%rax,%rdi,1),%rsi
  add    0x18(%rsp),%rdi
  sub    $0x8,%rsp
  push   %r13
  push   %r14
  push   %r15
  push   %rbp
  push   %rbx
  mov    0xc8(%rsp),%r9
  mov    0xc0(%rsp),%r8
  mov    0xb8(%rsp),%rcx
  mov    0xd0(%rsp),%rdx
  call   <fast_s_with_memory@plt>
  add    $0x1,%r12d
  mov    0xa0(%rsp),%rax
  add    %rax,%r14
  add    %rax,%r13
  add    $0x30,%rsp
  cmp    %r12d,0x78(%rsp)
  jne    L415
  mov    0xc8(%rsp),%r15d
  mov    0xf0(%rsp),%rbp
  mov    0xf8(%rsp),%rbx
L294:
  mov    0x58(%rsp),%esi
  test   %esi,%esi
  jle    L519
  mov    0xa8(%rsp),%rcx
  mov    %rcx,%rax
  mov    %esi,%edx
  lea    (%rcx,%rdx,8),%rdx
  movsd  D4(%rip),%xmm0
L179:
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L179
  mov    %r15d,%edx
  mov    0x58(%rsp),%esi
  mov    0x60(%rsp),%rdi
  call   <reset_mat@plt>
  mov    0x78(%rsp),%r14d
  imul   0x104(%rsp),%r14d
  cmpl   $0x0,0x7c(%rsp)
  jle    L460
L135:
  mov    0xb8(%rsp),%r13
  lea    -0x1(%r15),%eax
  lea    0x8(,%rax,8),%rax
  mov    %rax,0x98(%rsp)
  mov    $0x0,%r12d
  movl   $0x0,0x90(%rsp)
  movsd  D4(%rip),%xmm2
  movsd  %xmm2,0x70(%rsp)
  lea    0x108(%rsp),%rax
  mov    %rax,0x88(%rsp)
  mov    %rbx,0xa0(%rsp)
  mov    0x60(%rsp),%rbx
  jmp    L504
L1:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_label: D4
type_guessed: byte[8]

tool: {"D4": [0x40,0x8c,0xb5,0x78,0x1d,0xaf,0x15,0x44]}

assistant: ```c
void fast_s_large_n(double *X, double *y, int *nn, int *pp, int *NN, int *K, int *ggroups, int *nn_group, int *bbest_r, double *bb, double *rrhoc, double *bbeta, double *sscale) {
  void reset_mat(double **a, int n, int m);
  double loss_rho(double *r, double scale, int n, int p, double rhoc);
  double find_scale(double *r, double b, double rhoc, double initial_scale, int n, int p);
  void fast_s_with_memory(double **x, double *y, int *nn, int *pp, int *NN, int *K, int *bbest_r, double *bb, double *rrhoc, double **best_betas, double *best_scales);
  void sample_n_outof_N(int n, int N, int *x);
  void refine_fast_s(double **x, double *y, double *weights, int n, int p, double *res, double *tmp, double *tmp2, double **tmp_mat, double **tmp_mat2, double *beta_cand, int kk, int conv, double b, double rhoc, double *is, double *beta_ref, double *scale);
  int find_max(double *a, int n);
  register int i, j, k, k2;
  int n = *nn, p = *pp, kk = *K, *indices;
  int groups = *ggroups, n_group = *nn_group, best_r = *bbest_r;
  double **best_betas, *best_scales;
  double **final_best_betas, *final_best_scales;
  double **x, **xsamp, *ysamp, *res, sc, *beta_ref;
  double *tmp, *tmp2, **tmp_mat, **tmp_mat2, *weights;
  double best_sc, worst_sc, b = *bb, rhoc = *rrhoc, aux;
  int pos_worst_scale, conv;
  res = (double *)malloc(n * sizeof(double));
  weights = (double *)malloc(n * sizeof(double));
  tmp = (double *)malloc(n * sizeof(double));
  tmp2 = (double *)malloc(n * sizeof(double));
  tmp_mat = (double **)malloc(p * sizeof(double *));
  tmp_mat2 = (double **)malloc(p * sizeof(double *));
  for (i = 0; i < p; i++) {
    tmp_mat[i] = (double *)malloc(p * sizeof(double));
    tmp_mat2[i] = (double *)malloc((p + 1) * sizeof(double));
  };
  beta_ref = (double *)malloc(p * sizeof(double));
  final_best_betas = (double **)malloc(best_r * sizeof(double *));
  for (i = 0; i < best_r; i++)
    final_best_betas[i] = (double *)malloc(p * sizeof(double));
  final_best_scales = (double *)malloc(best_r * sizeof(double));
  k = best_r * groups;
  best_betas = (double **)malloc(k * sizeof(double *));
  best_scales = (double *)malloc(k * sizeof(double));
  for (i = 0; i < k; i++)
    best_betas[i] = (double *)malloc(p * sizeof(double));
  x = (double **)malloc(n * sizeof(double *));
  for (i = 0; i < n; i++)
    x[i] = (double *)malloc(p * sizeof(double));
  k = n_group * groups;
  indices = (int *)malloc(k * sizeof(int));
  xsamp = (double **)malloc(k * sizeof(double *));
  ysamp = (double *)malloc(k * sizeof(double));
  for (i = 0; i < k; i++)
    xsamp[i] = (double *)malloc(p * sizeof(double));
  for (i = 0; i < n; i++)
    for (j = 0; j < p; j++)
      x[i][j] = X[j * n + i];
  srand((long)37);
  sample_n_outof_N(k, n - 1, indices);
  for (i = 0; i < k; i++) {
    for (j = 0; j < p; j++)
      xsamp[i][j] = x[indices[i]][j];
    ysamp[i] = y[indices[i]];
  };
  for (i = 0; i < groups; i++) {
    fast_s_with_memory(xsamp + i * n_group, ysamp + i * n_group, &n_group, pp, NN, K, bbest_r, bb, rrhoc, best_betas + i * best_r, best_scales + i * best_r);
  };
  best_sc = 1e+20;
  pos_worst_scale = conv = 0;
  for (i = 0; i < best_r; i++)
    final_best_scales[i] = 1e+20;
  worst_sc = 1e+20;
  reset_mat(final_best_betas, best_r, p);
  k = n_group * groups;
  for (i = 0; i < (best_r * groups); i++) {
    refine_fast_s(xsamp, ysamp, weights, k, p, res, tmp, tmp2, tmp_mat, tmp_mat2, best_betas[i], kk, conv, b, rhoc, best_scales + i, beta_ref, &sc);
    if (loss_rho(res, worst_sc, k, p, rhoc) < b) {
      sc = find_scale(res, b, rhoc, sc, k, p);
      k2 = pos_worst_scale;
      final_best_scales[k2] = sc;
      for (j = 0; j < p; j++)
        final_best_betas[k2][j] = beta_ref[j];
      pos_worst_scale = find_max(final_best_scales, best_r);
      worst_sc = final_best_scales[pos_worst_scale];
    };
  };
  best_sc = 1e+20;
  conv = 1;
  for (i = 0; i < best_r; i++) {
    refine_fast_s(x, y, weights, n, p, res, tmp, tmp2, tmp_mat, tmp_mat2, final_best_betas[i], kk, conv, b, rhoc, final_best_scales + i, beta_ref, &aux);
    if (aux < best_sc) {
      *sscale = best_sc = aux;
      for (j = 0; j < p; j++)
        bbeta[j] = beta_ref[j];
    };
  };
  for (i = 0; i < n; i++)
    free(x[i]);
  free(x);
  free(best_scales);
  k = best_r * groups;
  for (i = 0; i < k; i++)
    free(best_betas[i]);
  free(best_betas);
  free(indices);
  free(ysamp);
  k = n_group * groups;
  for (i = 0; i < k; i++)
    free(xsamp[i]);
  free(xsamp);
  free(tmp);
  free(tmp2);
  for (i = 0; i < p; i++) {
    free(tmp_mat[i]);
    free(tmp_mat2[i]);
  };
  free(tmp_mat);
  free(tmp_mat2);
  free(weights);
  for (i = 0; i < best_r; i++)
    free(final_best_betas[i]);
  free(final_best_betas);
  free(final_best_scales);
  free(res);
  free(beta_ref);
}
```