user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<fast_s_large_n>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x138,%rsp
  movslq (%rdx),%rbp
  mov    (%rcx),%r12d
  mov    0x198(%rsp),%rax
  mov    0x188(%rsp),%rbx
  mov    %rdi,0xf0(%rsp)
  mov    %rsi,0xa0(%rsp)
  mov    0x190(%rsp),%rdi
  mov    0x180(%rsp),%rsi
  mov    %rax,0x100(%rsp)
  mov    0x1a0(%rsp),%rax
  mov    %rcx,0x48(%rsp)
  mov    %r8,0xf8(%rsp)
  mov    %r9,0x50(%rsp)
  mov    %rsi,0x88(%rsp)
  mov    %rbx,0xa8(%rsp)
  mov    %rdi,0xb0(%rsp)
  mov    %rax,0xd8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x128(%rsp)
  xor    %eax,%eax
  mov    (%r9),%eax
  mov    %ebp,0x5c(%rsp)
  shl    $0x3,%rbp
  mov    %eax,0x58(%rsp)
  mov    0x170(%rsp),%rax
  mov    (%rax),%eax
  mov    %eax,0x68(%rsp)
  mov    0x178(%rsp),%rax
  movsd  (%rbx),%xmm6
  movsd  (%rdi),%xmm7
  mov    %rbp,%rdi
  movslq %r12d,%rbx
  mov    (%rax),%eax
  lea    0x0(,%rbx,8),%r14
  movsd  %xmm6,0x90(%rsp)
  mov    %eax,0x8(%rsp)
  mov    %eax,0x114(%rsp)
  mov    (%rsi),%eax
  movsd  %xmm7,0x98(%rsp)
  mov    %eax,0x2c(%rsp)
  call   <malloc@plt>
  mov    %rbp,%rdi
  mov    %rax,0x80(%rsp)
  call   <malloc@plt>
  mov    %rbp,%rdi
  mov    %rax,0x30(%rsp)
  call   <malloc@plt>
  mov    %rbp,%rdi
  mov    %rax,0x38(%rsp)
  call   <malloc@plt>
  mov    %r14,%rdi
  mov    %rax,0x40(%rsp)
  call   <malloc@plt>
  mov    %r14,%rdi
  mov    %rax,0x10(%rsp)
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  test   %r12d,%r12d
  jle    L368
  xor    %r15d,%r15d
  mov    %rbp,0x20(%rsp)
  mov    0x10(%rsp),%rbp
  lea    0x8(%r14),%r13
  mov    %r12d,0x60(%rsp)
  mov    %r15,%r12
  mov    0x18(%rsp),%r15
  nopl   0x0(%rax)
L326:
  mov    %r14,%rdi
  call   <malloc@plt>
  mov    %r13,%rdi
  mov    %rax,0x0(%rbp,%r12,8)
  call   <malloc@plt>
  mov    %rax,(%r15,%r12,8)
  add    $0x1,%r12
  cmp    %rbx,%r12
  jne    L326
  mov    0x20(%rsp),%rbp
  mov    0x60(%rsp),%r12d
L368:
  mov    %r14,%rdi
  call   <malloc@plt>
  mov    %rax,%r13
  movslq 0x2c(%rsp),%rax
  mov    %rax,%r15
  shl    $0x3,%rax
  mov    %rax,%rdi
  mov    %rax,0xe0(%rsp)
  call   <malloc@plt>
  mov    %rax,0x60(%rsp)
  test   %r15d,%r15d
  jle    L161
  mov    0x60(%rsp),%rsi
  mov    0x2c(%rsp),%eax
  mov    %rbx,0x20(%rsp)
  lea    (%rsi,%rax,8),%rax
  mov    %rsi,%rbx
  mov    %rax,%r15
  nopl   (%rax)
L61:
  mov    %r14,%rdi
  add    $0x8,%rbx
  call   <malloc@plt>
  mov    %rax,-0x8(%rbx)
  cmp    %r15,%rbx
  jne    L61
  mov    0x20(%rsp),%rbx
L161:
  mov    0xe0(%rsp),%rdi
  call   <malloc@plt>
  mov    %rax,0xb8(%rsp)
  mov    0x68(%rsp),%eax
  imul   0x2c(%rsp),%eax
  movslq %eax,%r15
  mov    %eax,0x6c(%rsp)
  shl    $0x3,%r15
  mov    %r15,%rdi
  call   <malloc@plt>
  mov    %r15,%rdi
  mov    %rax,0x78(%rsp)
  call   <malloc@plt>
  mov    %rax,0xd0(%rsp)
  mov    0x6c(%rsp),%eax
  test   %eax,%eax
  jle    L248
  mov    0x78(%rsp),%rsi
  mov    0x6c(%rsp),%eax
  mov    %rbx,0x20(%rsp)
  lea    (%rsi,%rax,8),%rax
  mov    %rsi,%rbx
  mov    %rax,%r15
L548:
  mov    %r14,%rdi
  add    $0x8,%rbx
  call   <malloc@plt>
  mov    %rax,-0x8(%rbx)
  cmp    %r15,%rbx
  jne    L548
  mov    0x20(%rsp),%rbx
L248:
  mov    %rbp,%rdi
  call   <malloc@plt>
  mov    %rax,0x70(%rsp)
  mov    0x5c(%rsp),%eax
  test   %eax,%eax
  jle    L189
  mov    0x70(%rsp),%rsi
  mov    0x5c(%rsp),%eax
  mov    %rbx,0x20(%rsp)
  lea    (%rsi,%rax,8),%rax
  mov    %rsi,%rbx
  mov    %rax,%r15
  nopl   0x0(%rax,%rax,1)
L547:
  mov    %r14,%rdi
  add    $0x8,%rbx
  call   <malloc@plt>
  mov    %rax,-0x8(%rbx)
  cmp    %r15,%rbx
  jne    L547
  mov    0x8(%rsp),%eax
  imul   0x68(%rsp),%eax
  mov    0x20(%rsp),%rbx
  movslq %eax,%r15
  mov    %eax,0xc0(%rsp)
  lea    0x0(,%r15,4),%rdi
  shl    $0x3,%r15
  call   <malloc@plt>
  mov    %r15,%rdi
  mov    %rax,0xc8(%rsp)
  call   <malloc@plt>
  mov    %r15,%rdi
  mov    %rax,0x8(%rsp)
  call   <malloc@plt>
  mov    0x5c(%rsp),%esi
  mov    %rax,0x20(%rsp)
  lea    -0x1(%rsi),%ecx
  mov    %ecx,0xe8(%rsp)
  mov    0xc0(%rsp),%ecx
  test   %ecx,%ecx
  jle    L50
L39:
  mov    0x8(%rsp),%rsi
  mov    0xc0(%rsp),%eax
  mov    %rbx,0x108(%rsp)
  lea    (%rsi,%rax,8),%rax
  mov    %rsi,%rbx
  mov    %rax,%r15
  nopw   0x0(%rax,%rax,1)
L469:
  mov    %r14,%rdi
  add    $0x8,%rbx
  call   <malloc@plt>
  mov    %rax,-0x8(%rbx)
  cmp    %r15,%rbx
  jne    L469
  mov    0x5c(%rsp),%edi
  mov    0x108(%rsp),%rbx
  test   %edi,%edi
  jle    L243
L50:
  lea    -0x1(%r12),%eax
  mov    0xf0(%rsp),%rdi
  mov    0x5c(%rsp),%r9d
  xor    %esi,%esi
  mov    0x70(%rsp),%r10
  lea    0x8(,%rax,8),%r8
  nopw   0x0(%rax,%rax,1)
L24:
  test   %r12d,%r12d
  jle    L22
  mov    (%r10,%rsi,8),%rax
  mov    %rdi,%rdx
  lea    (%r8,%rax,1),%rcx
L482:
  movsd  (%rdx),%xmm0
  add    $0x8,%rax
  add    %rbp,%rdx
  movsd  %xmm0,-0x8(%rax)
  cmp    %rax,%rcx
  jne    L482
L22:
  add    $0x1,%rsi
  add    $0x8,%rdi
  cmp    %esi,%r9d
  jg     L24
  mov    $0x25,%edi
  xor    %eax,%eax
  call   <srand@plt>
  mov    0xc0(%rsp),%r15d
  mov    0xc8(%rsp),%rdx
  mov    0xe8(%rsp),%esi
  mov    %r15d,%edi
  call   <sample_n_outof_N@plt>
  test   %r15d,%r15d
  jle    L262
L291:
  mov    0x20(%rsp),%r8
  mov    0xc0(%rsp),%r9d
  xor    %esi,%esi
  mov    0xc8(%rsp),%r10
  mov    0x8(%rsp),%rbp
  mov    0x70(%rsp),%r14
  mov    0xa0(%rsp),%r11
  nopl   0x0(%rax,%rax,1)
L405:
  movslq (%r10,%rsi,4),%rdi
  test   %r12d,%r12d
  jle    L545
  mov    (%r14,%rdi,8),%rcx
  mov    0x0(%rbp,%rsi,8),%rdx
  xor    %eax,%eax
  nopl   0x0(%rax)
L523:
  movsd  (%rcx,%rax,8),%xmm0
  movsd  %xmm0,(%rdx,%rax,8)
  add    $0x1,%rax
  cmp    %rbx,%rax
  jne    L523
L545:
  movsd  (%r11,%rdi,8),%xmm0
  movsd  %xmm0,(%r8,%rsi,8)
  add    $0x1,%rsi
  cmp    %esi,%r9d
  jg     L405
L262:
  mov    0x68(%rsp),%eax
  test   %eax,%eax
  jle    L436
  mov    0xd0(%rsp),%r15
  xor    %r14d,%r14d
  mov    %r13,0xe8(%rsp)
  lea    0x114(%rsp),%rax
  mov    %rbx,0xf0(%rsp)
  mov    0x78(%rsp),%rbp
  mov    0xf8(%rsp),%r13
  mov    0xe0(%rsp),%rbx
  mov    %r12d,0xc0(%rsp)
  mov    %r14d,%r12d
  mov    %r15,%r14
  mov    %rax,%r15
  nopl   (%rax)
L396:
  mov    0x20(%rsp),%rax
  sub    $0x8,%rsp
  mov    %r13,%r8
  mov    %r15,%rdx
  mov    0x11c(%rsp),%edi
  imul   %r12d,%edi
  add    $0x1,%r12d
  movslq %edi,%rdi
  shl    $0x3,%rdi
  lea    (%rax,%rdi,1),%rsi
  add    0x10(%rsp),%rdi
  push   %r14
  add    %rbx,%r14
  push   %rbp
  add    %rbx,%rbp
  push   0xc8(%rsp)
  push   0xc8(%rsp)
  push   0xb0(%rsp)
  mov    0x80(%rsp),%r9
  mov    0x78(%rsp),%rcx
  call   <fast_s_with_memory@plt>
  add    $0x30,%rsp
  cmp    %r12d,0x68(%rsp)
  jne    L396
  mov    0xc0(%rsp),%r12d
  mov    0xe8(%rsp),%r13
  mov    0xf0(%rsp),%rbx
L436:
  mov    0x2c(%rsp),%r15d
  test   %r15d,%r15d
  jle    L530
  mov    0xb8(%rsp),%rsi
  mov    0x2c(%rsp),%edx
  movsd  D7(%rip),%xmm0
  mov    %rsi,%rax
  lea    (%rsi,%rdx,8),%rdx
  movsd  %xmm0,0xe0(%rsp)
  nopl   0x0(%rax,%rax,1)
L360:
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rax,%rdx
  jne    L360
  mov    0x2c(%rsp),%esi
  mov    0x60(%rsp),%rdi
  mov    %r12d,%edx
  call   <reset_mat@plt>
  mov    0x6c(%rsp),%r8d
  mov    0x68(%rsp),%ebp
  imul   0x114(%rsp),%ebp
  test   %r8d,%r8d
  jle    L442
L433:
  mov    0xd0(%rsp),%r14
  lea    0x118(%rsp),%rax
  xor    %r15d,%r15d
  movsd  0xe0(%rsp),%xmm2
  mov    %rbx,0xc0(%rsp)
  movsd  0x90(%rsp),%xmm3
  mov    %r14,%rbx
  mov    %ebp,%r14d
  movl   $0x0,0xb0(%rsp)
  movsd  0x98(%rsp),%xmm1
  mov    %rax,0xa8(%rsp)
  mov    0x80(%rsp),%rbp
  movsd  %xmm2,0x88(%rsp)
  jmp    L430
  nopw   0x0(%rax,%rax,1)
L345:
  add    $0x1,%r15
  add    $0x8,%rbx
  cmp    %r15d,0x6c(%rsp)
  jle    L193
L430:
  push   0xa8(%rsp)
  mov    %rbp,%r9
  mov    %r12d,%r8d
  mov    %r14d,%ecx
  push   %r13
  movapd %xmm3,%xmm0
  push   %rbx
  push   $0x0
  mov    0x78(%rsp),%eax
  push   %rax
  mov    0xa0(%rsp),%rax
  push   (%rax,%r15,8)
  push   0x48(%rsp)
  push   0x48(%rsp)
  push   0x80(%rsp)
  push   0x80(%rsp)
  mov    0x80(%rsp),%rdx
  mov    0x70(%rsp),%rsi
  mov    0x58(%rsp),%rdi
  movsd  %xmm3,0xa0(%rsp)
  movsd  %xmm1,0x98(%rsp)
  call   <refine_fast_s@plt>
  add    $0x50,%rsp
  mov    %r12d,%edx
  mov    %r14d,%esi
  movsd  0x48(%rsp),%xmm1
  mov    %rbp,%rdi
  movsd  0x88(%rsp),%xmm0
  call   <loss_rho@plt>
  movsd  0x50(%rsp),%xmm3
  movsd  0x48(%rsp),%xmm1
  comisd %xmm0,%xmm3
  jbe    L345
  movapd %xmm3,%xmm0
  mov    %r12d,%edx
  mov    %r14d,%esi
  mov    %rbp,%rdi
  movsd  0x118(%rsp),%xmm2
  movsd  %xmm1,0x50(%rsp)
  movsd  %xmm3,0x48(%rsp)
  call   <find_scale@plt>
  movslq 0xb0(%rsp),%rax
  test   %r12d,%r12d
  mov    0xb8(%rsp),%rcx
  movsd  0x48(%rsp),%xmm3
  movsd  0x50(%rsp),%xmm1
  movsd  %xmm0,0x118(%rsp)
  movsd  %xmm0,(%rcx,%rax,8)
  jle    L349
  mov    0x60(%rsp),%rcx
  mov    (%rcx,%rax,8),%rdx
  mov    0xc0(%rsp),%rcx
  xor    %eax,%eax
  nopl   0x0(%rax)
L51:
  movsd  0x0(%r13,%rax,8),%xmm0
  movsd  %xmm0,(%rdx,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L51
L349:
  mov    0x2c(%rsp),%esi
  movsd  %xmm1,0x50(%rsp)
  add    $0x1,%r15
  mov    0xb8(%rsp),%rdi
  movsd  %xmm3,0x48(%rsp)
  add    $0x8,%rbx
  call   <find_max@plt>
  mov    0xb8(%rsp),%rsi
  movsd  0x48(%rsp),%xmm3
  mov    %eax,0xb0(%rsp)
  cltq
  movsd  0x50(%rsp),%xmm1
  movsd  (%rsi,%rax,8),%xmm5
  movsd  %xmm5,0x88(%rsp)
  cmp    %r15d,0x6c(%rsp)
  jg     L430
L193:
  mov    0x2c(%rsp),%r14d
  mov    0xc0(%rsp),%rbx
  test   %r14d,%r14d
  jle    L240
L442:
  mov    0xb8(%rsp),%r14
  lea    0x120(%rsp),%rbp
  xor    %r15d,%r15d
  movsd  0xe0(%rsp),%xmm6
  mov    %rbp,0x50(%rsp)
  mov    %r12d,%ebp
  movsd  %xmm6,0x48(%rsp)
  mov    %r14,%r12
  mov    0x100(%rsp),%r14
  jmp    L428
  nopl   (%rax)
L176:
  add    $0x1,%r15
  add    $0x8,%r12
  cmp    %r15d,0x2c(%rsp)
  jle    L473
L428:
  push   0x50(%rsp)
  mov    %ebp,%r8d
  push   %r13
  push   %r12
  push   $0x1
  mov    0x78(%rsp),%eax
  push   %rax
  mov    0x88(%rsp),%rax
  push   (%rax,%r15,8)
  push   0x48(%rsp)
  push   0x48(%rsp)
  push   0x80(%rsp)
  push   0x80(%rsp)
  movsd  0xe8(%rsp),%xmm1
  movsd  0xe0(%rsp),%xmm0
  mov    0xd0(%rsp),%r9
  mov    0xac(%rsp),%ecx
  mov    0x80(%rsp),%rdx
  mov    0xf0(%rsp),%rsi
  mov    0xc0(%rsp),%rdi
  call   <refine_fast_s@plt>
  movsd  0x170(%rsp),%xmm1
  add    $0x50,%rsp
  movsd  0x48(%rsp),%xmm4
  comisd %xmm1,%xmm4
  jbe    L176
  mov    0xd8(%rsp),%rax
  movsd  %xmm1,(%rax)
  test   %ebp,%ebp
  jle    L419
  xor    %edx,%edx
  nopl   0x0(%rax)
L230:
  movsd  0x0(%r13,%rdx,8),%xmm0
  movsd  %xmm0,(%r14,%rdx,8)
  add    $0x1,%rdx
  cmp    %rdx,%rbx
  jne    L230
L419:
  movsd  %xmm1,0x48(%rsp)
  add    $0x1,%r15
  add    $0x8,%r12
  cmp    %r15d,0x2c(%rsp)
  jg     L428
L473:
  mov    %ebp,%r12d
  mov    0x5c(%rsp),%ebp
  test   %ebp,%ebp
  jle    L486
L88:
  mov    0x70(%rsp),%rsi
  mov    0x5c(%rsp),%eax
  mov    %rsi,%r14
  lea    (%rsi,%rax,8),%rbp
  nopw   0x0(%rax,%rax,1)
L228:
  mov    (%r14),%rdi
  add    $0x8,%r14
  call   <free@plt>
  cmp    %r14,%rbp
  jne    L228
L486:
  mov    0x70(%rsp),%rdi
  call   <free@plt>
  mov    0xd0(%rsp),%rdi
  call   <free@plt>
  mov    0x6c(%rsp),%r11d
  test   %r11d,%r11d
  jle    L395
L379:
  mov    0x78(%rsp),%rsi
  mov    0x6c(%rsp),%eax
  mov    %rsi,%r14
  lea    (%rsi,%rax,8),%rbp
  nopw   0x0(%rax,%rax,1)
L220:
  mov    (%r14),%rdi
  add    $0x8,%r14
  call   <free@plt>
  cmp    %r14,%rbp
  jne    L220
L395:
  mov    0x78(%rsp),%rdi
  call   <free@plt>
  mov    0xc8(%rsp),%rdi
  call   <free@plt>
  mov    0x20(%rsp),%rdi
  call   <free@plt>
  mov    0x68(%rsp),%eax
  imul   0x114(%rsp),%eax
  test   %eax,%eax
  jle    L194
  mov    0x8(%rsp),%rcx
  mov    %rcx,%r14
  lea    (%rcx,%rax,8),%rbp
  xchg   %ax,%ax
L67:
  mov    (%r14),%rdi
  add    $0x8,%r14
  call   <free@plt>
  cmp    %r14,%rbp
  jne    L67
L194:
  mov    0x8(%rsp),%rdi
  xor    %ebp,%ebp
  call   <free@plt>
  mov    0x38(%rsp),%rdi
  call   <free@plt>
  mov    0x40(%rsp),%rdi
  call   <free@plt>
  test   %r12d,%r12d
  jle    L522
  mov    0x10(%rsp),%r12
  mov    0x18(%rsp),%r14
L289:
  mov    (%r12,%rbp,8),%rdi
  call   <free@plt>
  mov    (%r14,%rbp,8),%rdi
  add    $0x1,%rbp
  call   <free@plt>
  cmp    %rbx,%rbp
  jne    L289
L522:
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rdi
  call   <free@plt>
  mov    0x30(%rsp),%rdi
  call   <free@plt>
  mov    0x2c(%rsp),%r10d
  test   %r10d,%r10d
  jle    L146
  mov    0x60(%rsp),%rsi
  mov    0x2c(%rsp),%eax
  mov    %rsi,%rbx
  lea    (%rsi,%rax,8),%rbp
  nopl   0x0(%rax,%rax,1)
L79:
  mov    (%rbx),%rdi
  add    $0x8,%rbx
  call   <free@plt>
  cmp    %rbx,%rbp
  jne    L79
L146:
  mov    0x60(%rsp),%rdi
  call   <free@plt>
  mov    0xb8(%rsp),%rdi
  call   <free@plt>
  mov    0x80(%rsp),%rdi
  call   <free@plt>
  mov    0x128(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L81
  add    $0x138,%rsp
  mov    %r13,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10f0 <free@plt>
L240:
  mov    0x5c(%rsp),%eax
  test   %eax,%eax
  jg     L88
  mov    0x70(%rsp),%rdi
  call   <free@plt>
  mov    0xd0(%rsp),%rdi
  call   <free@plt>
  jmp    L379
  nopl   (%rax)
L189:
  mov    0x8(%rsp),%eax
  imul   0x68(%rsp),%eax
  movslq %eax,%r15
  mov    %eax,0xc0(%rsp)
  lea    0x0(,%r15,4),%rdi
  shl    $0x3,%r15
  call   <malloc@plt>
  mov    %r15,%rdi
  mov    %rax,0xc8(%rsp)
  call   <malloc@plt>
  mov    %r15,%rdi
  mov    %rax,0x8(%rsp)
  call   <malloc@plt>
  mov    0x5c(%rsp),%ecx
  mov    0xc0(%rsp),%edx
  mov    %rax,0x20(%rsp)
  sub    $0x1,%ecx
  mov    %ecx,0xe8(%rsp)
  test   %edx,%edx
  jg     L39
  mov    $0x25,%edi
  xor    %eax,%eax
  call   <srand@plt>
  mov    0xc8(%rsp),%rdx
  mov    0xe8(%rsp),%esi
  mov    0xc0(%rsp),%edi
  call   <sample_n_outof_N@plt>
  jmp    L262
L530:
  mov    0x2c(%rsp),%esi
  mov    0x60(%rsp),%rdi
  mov    %r12d,%edx
  call   <reset_mat@plt>
  mov    0x6c(%rsp),%r9d
  mov    0x68(%rsp),%ebp
  movsd  D7(%rip),%xmm7
  imul   0x114(%rsp),%ebp
  movsd  %xmm7,0xe0(%rsp)
  test   %r9d,%r9d
  jg     L433
  mov    0x5c(%rsp),%esi
  test   %esi,%esi
  jg     L88
  mov    0x70(%rsp),%rdi
  call   <free@plt>
  mov    0xd0(%rsp),%rdi
  call   <free@plt>
  jmp    L395
  nopl   0x0(%rax,%rax,1)
L243:
  mov    $0x25,%edi
  xor    %eax,%eax
  call   <srand@plt>
  mov    0xc8(%rsp),%rdx
  mov    0xe8(%rsp),%esi
  mov    0xc0(%rsp),%edi
  call   <sample_n_outof_N@plt>
  jmp    L291
L81:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D7
type_guessed: byte[8]

tool: {"D7": [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);
}
```