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

```asm
<BuildSampler>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rdi,%r12
  xor    %edi,%edi
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  mov    $0x1,%ebx
  sub    $0x28,%rsp
  test   %ebp,%ebp
  setne  %dil
  mov    %ebp,0x4(%rsp)
  mov    %rdx,0x8(%rsp)
  call   <assert@plt>
  test   %ebp,%ebp
  je     L97
  nopl   0x0(%rax)
L134:
  mov    %ebx,%eax
  mov    0x8(%rsp),%rsi
  pxor   %xmm3,%xmm3
  xor    %edi,%edi
  lea    (%r12,%rax,8),%r14
  movsd  (%r14),%xmm0
  mov    %ebx,(%rsi,%rax,4)
  mov    %ebx,0x0(%r13,%rax,4)
  comisd %xmm3,%xmm0
  setae  %dil
  add    $0x1,%ebx
  call   <assert@plt>
  pxor   %xmm0,%xmm0
  cvtsi2sd %rbp,%xmm0
  mulsd  (%r14),%xmm0
  movsd  %xmm0,(%r14)
  cmp    %ebx,0x4(%rsp)
  jae    L134
L97:
  mov    0x4(%rsp),%eax
  mov    D14(%rip),%rdx
  xor    %r8d,%r8d
  movl   $0x0,0x0(%r13)
  movq   $0x0,(%r12)
  movsd  D22(%rip),%xmm0
  add    $0x1,%eax
  mov    %eax,0x0(%r13,%rax,4)
  mov    %rax,%rbx
  mov    %rdx,(%r12,%rax,8)
  nopl   0x0(%rax)
L39:
  lea    0x1(%r8),%eax
  lea    0x0(%r13,%rax,4),%r10
  mov    %rax,%r8
  mov    (%r10),%eax
  comisd (%r12,%rax,8),%xmm0
  mov    %rax,%r9
  ja     L39
  nopw   0x0(%rax,%rax,1)
L52:
  lea    -0x1(%rbx),%r14d
  mov    %ebx,%ebp
  lea    0x0(%r13,%r14,4),%rax
  mov    %r14,%rbx
  mov    (%rax),%edi
  movsd  (%r12,%rdi,8),%xmm1
  comisd %xmm0,%xmm1
  jae    L52
  cmp    %r14d,%r8d
  jae    L78
  mov    %edi,(%r10)
  mov    %r9d,(%rax)
  jmp    L39
  nopl   0x0(%rax)
L78:
  mov    %ebp,%r15d
  test   %r14d,%r14d
  jne    L70
  jmp    L90
  nopl   (%rax)
L53:
  lea    0x1(%rbp),%r15d
  mov    %r15,%rbp
L70:
  lea    0x0(%r13,%r15,4),%rcx
  mov    (%rcx),%eax
  comisd (%r12,%rax,8),%xmm0
  jae    L53
  xor    %edi,%edi
  comisd %xmm1,%xmm0
  lea    0x0(%r13,%r14,4),%rax
  mov    %rcx,0x10(%rsp)
  mov    %rax,0x18(%rsp)
  seta   %dil
  call   <assert@plt>
  cmp    %ebp,0x4(%rsp)
  jb     L90
  mov    $0x1,%edi
  call   <assert@plt>
  mov    0x10(%rsp),%rcx
  xor    %edi,%edi
  mov    (%rcx),%eax
  movsd  (%r12,%rax,8),%xmm1
  mov    D22(%rip),%rax
  movq   %rax,%xmm0
  comisd %xmm0,%xmm1
  seta   %dil
  call   <assert@plt>
  mov    0x10(%rsp),%rcx
  mov    0x8(%rsp),%rsi
  mov    D22(%rip),%rdx
  mov    (%rcx),%eax
  movq   %rdx,%xmm2
  movq   %rdx,%xmm0
  lea    (%r12,%rax,8),%r9
  mov    %rax,%rdi
  lea    0x0(%r13,%r14,4),%rax
  mov    (%rax),%eax
  movsd  (%r9),%xmm1
  subsd  (%r12,%rax,8),%xmm2
  subsd  %xmm2,%xmm1
  movsd  %xmm1,(%r9)
  mov    %edi,(%rsi,%rax,4)
  mov    (%rcx),%eax
  comisd (%r12,%rax,8),%xmm0
  ja     L35
  sub    $0x1,%ebx
  je     L90
  mov    %ebx,%r14d
L36:
  mov    0x0(%r13,%r14,4),%eax
  movsd  (%r12,%rax,8),%xmm1
  jmp    L70
  nopl   0x0(%rax)
L35:
  xor    %edi,%edi
  cmp    %ebx,%ebp
  lea    0x1(%rbp),%r15d
  seta   %dil
  mov    %r15,%rbp
  call   <assert@plt>
  mov    0x18(%rsp),%rdx
  mov    0x10(%rsp),%rcx
  mov    (%rdx),%eax
  mov    (%rcx),%edi
  mov    %edi,(%rdx)
  mov    %eax,(%rcx)
  mov    D22(%rip),%rax
  movq   %rax,%xmm0
  jmp    L36
  nopl   0x0(%rax)
L90:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: extract_symbolic_data
arguments: tag: D14
datatype: f64
name: extract_symbolic_data
arguments: tag: D22
datatype: f64

tool: D14: 2

tool: D22: 1

assistant: ```c
void BuildSampler(double *X, unsigned N, unsigned *A, unsigned *B) {
  unsigned i, j, k;
  assert(1 <= N);
  for (i = 1; i <= N; i++) {
    A[i] = i;
    B[i] = i;
    assert(X[i] >= 0.0);
    X[i] = X[i] * N;
  }
  B[0] = 0;
  X[0] = 0.0;
  B[N + 1] = N + 1;
  X[N + 1] = 2.0;
  i = 0;
  j = N + 1;
  for (;;) {
    do {
      i++;
    } while (X[B[i]] < 1.0);
    do {
      j--;
    } while (X[B[j]] >= 1.0);
    if (i >= j)
      break;
    k = B[i];
    B[i] = B[j];
    B[j] = k;
  }
  i = j;
  j++;
  while (i > 0) {
    while (X[B[j]] <= 1.0)
      j++;
    assert(X[B[i]] < 1.0);
    if (j > N)
      break;
    assert(j <= N);
    assert(X[B[j]] > 1.0);
    X[B[j]] -= 1.0 - X[B[i]];
    A[B[i]] = B[j];
    if (X[B[j]] < 1.0) {
      assert(i < j);
      k = B[i];
      B[i] = B[j];
      B[j] = k;
      j++;
    } else
      i--;
  }
}
```