user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<BuildSampler>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r12
  mov    %esi,%ebx
  mov    %esi,0x4(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rcx,%r13
  test   %esi,%esi
  setne  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  test   %ebx,%ebx
  je     L108
  mov    $0x1,%ebx
L56:
  mov    %ebx,%eax
  mov    0x8(%rsp),%rsi
  mov    %ebx,(%rsi,%rax,4)
  mov    %ebx,0x0(%r13,%rax,4)
  lea    (%r12,%rax,8),%rbp
  movsd  0x0(%rbp),%xmm0
  pxor   %xmm7,%xmm7
  comisd %xmm7,%xmm0
  setae  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    0x4(%rsp),%esi
  mov    %esi,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  mulsd  0x0(%rbp),%xmm0
  movsd  %xmm0,0x0(%rbp)
  add    $0x1,%ebx
  cmp    %ebx,%esi
  jae    L56
L108:
  movl   $0x0,0x0(%r13)
  movq   $0x0,(%r12)
  mov    0x4(%rsp),%eax
  lea    0x1(%rax),%ebx
  mov    %ebx,%eax
  mov    %ebx,0x0(%r13,%rax,4)
  mov    D64(%rip),%rdi
  mov    %rdi,(%r12,%rax,8)
  mov    $0x0,%esi
  movsd  D3(%rip),%xmm2
  movapd %xmm2,%xmm1
L29:
  add    $0x1,%esi
  mov    %esi,%eax
  lea    0x0(%r13,%rax,4),%r8
  mov    (%r8),%edi
  mov    %edi,%eax
  comisd (%r12,%rax,8),%xmm2
  ja     L29
L6:
  mov    %ebx,%ebp
  sub    $0x1,%ebx
  mov    %ebx,%eax
  lea    0x0(%r13,%rax,4),%rax
  mov    (%rax),%edx
  mov    %edx,%ecx
  movsd  (%r12,%rcx,8),%xmm0
  comisd %xmm1,%xmm0
  jae    L6
  cmp    %ebx,%esi
  jae    L116
  mov    %edx,(%r8)
  mov    %edi,(%rax)
  jmp    L29
L116:
  test   %ebx,%ebx
  jne    L66
L68:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L40:
  cmp    %ebp,%ebx
  setb   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    (%r15),%eax
  mov    (%r14),%edx
  mov    %edx,(%r15)
  mov    %eax,(%r14)
  add    $0x1,%ebp
L7:
  test   %ebx,%ebx
  je     L68
L66:
  mov    %ebp,%eax
  lea    0x0(%r13,%rax,4),%r14
  mov    (%r14),%eax
  movsd  D3(%rip),%xmm5
  comisd (%r12,%rax,8),%xmm5
  jb     L45
L77:
  add    $0x1,%ebp
  mov    %ebp,%eax
  lea    0x0(%r13,%rax,4),%r14
  mov    (%r14),%eax
  movsd  D3(%rip),%xmm3
  comisd (%r12,%rax,8),%xmm3
  jae    L77
L45:
  mov    %ebx,%eax
  lea    0x0(%r13,%rax,4),%r15
  mov    (%r15),%eax
  movsd  D3(%rip),%xmm4
  comisd (%r12,%rax,8),%xmm4
  seta   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  cmp    %ebp,0x4(%rsp)
  jb     L68
  mov    $0x1,%edi
  call   <assert@plt>
  mov    (%r14),%eax
  movsd  (%r12,%rax,8),%xmm0
  comisd D3(%rip),%xmm0
  seta   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    (%r14),%eax
  lea    (%r12,%rax,8),%rax
  mov    (%r15),%edx
  movsd  D3(%rip),%xmm1
  subsd  (%r12,%rdx,8),%xmm1
  movsd  (%rax),%xmm0
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  mov    (%r14),%eax
  mov    (%r15),%edx
  mov    0x8(%rsp),%rsi
  mov    %eax,(%rsi,%rdx,4)
  mov    %eax,%eax
  movsd  D3(%rip),%xmm6
  comisd (%r12,%rax,8),%xmm6
  ja     L40
  sub    $0x1,%ebx
  jmp    L7
```

tool_calls: name: unpack_data
arguments: label: D64
type_guessed: f64
name: unpack_data
arguments: label: D3
type_guessed: f64

tool: D64: 2

tool: D3: 1

assistant: ```c
void BuildSampler(double *X, unsigned int N, unsigned int *A, unsigned int *B) {
  unsigned int 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--;
    }
  }
}
```