user: Translate the below assembly code into C programming language:

```asm
<resample>:
  endbr64
  push   %r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  mov    %rdi,%r13
  lea    D37(%rip),%rdi
  push   %r12
  mov    %r8d,%r12d
  push   %rbp
  push   %rbx
  mov    %ecx,%ebx
  sub    $0x58,%rsp
  mov    0x90(%rsp),%rax
  mov    %esi,0x38(%rsp)
  lea    D43(%rip),%rsi
  mov    %r9d,0x3c(%rsp)
  mov    %rax,0x30(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  test   %rax,%rax
  je     L1
  pxor   %xmm6,%xmm6
  pxor   %xmm0,%xmm0
  pxor   %xmm5,%xmm5
  mov    %rax,%rbp
  cvtsi2sd %r12d,%xmm0
  xor    %r12d,%r12d
  cvtsi2sd %ebx,%xmm6
  cvtsi2sd %r14d,%xmm5
  divsd  %xmm0,%xmm6
  movsd  %xmm5,0x28(%rsp)
  test   %r14d,%r14d
  jle    L168
  movslq 0x38(%rsp),%r8
  pxor   %xmm4,%xmm4
  xor    %r14d,%r14d
  lea    0x47(%rsp),%rbx
  movsd  D32(%rip),%xmm2
  movapd %xmm4,%xmm5
  movapd %xmm4,%xmm3
  movapd %xmm4,%xmm1
  lea    0x0(%r13,%r8,1),%r15
  jmp    L54
  nopl   0x0(%rax)
L159:
  cvttsd2si %xmm5,%eax
  add    0x38(%rsp),%eax
  pxor   %xmm0,%xmm0
  cltq
  movzbl 0x0(%r13,%rax,1),%eax
  add    $0xffffff80,%eax
  cvtsi2sd %eax,%xmm0
L60:
  movsd  %xmm5,0x20(%rsp)
  add    $0x1,%r12d
  movsd  %xmm1,0x18(%rsp)
  movsd  %xmm6,0x10(%rsp)
  movsd  %xmm3,0x8(%rsp)
  movsd  %xmm0,(%rsp)
  call   <round@plt>
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    %rbx,%rdi
  mov    $0x1,%esi
  mov    %al,0x47(%rsp)
  call   <fwrite@plt>
  movsd  0x10(%rsp),%xmm6
  pxor   %xmm4,%xmm4
  movsd  0x20(%rsp),%xmm5
  movsd  0x28(%rsp),%xmm7
  mov    D32(%rip),%rax
  addsd  %xmm6,%xmm5
  movsd  (%rsp),%xmm0
  movsd  0x8(%rsp),%xmm3
  movsd  0x18(%rsp),%xmm1
  movq   %rax,%xmm2
  comisd %xmm5,%xmm7
  jbe    L62
L54:
  comisd %xmm2,%xmm6
  jb     L159
  comisd %xmm1,%xmm4
  movapd %xmm4,%xmm0
  jbe    L109
  movapd %xmm1,%xmm7
  mulsd  %xmm3,%xmm7
  subsd  %xmm7,%xmm0
L109:
  addsd  %xmm6,%xmm1
  lea    0x1(%r14),%eax
  cltq
  comisd %xmm4,%xmm1
  ja     L6
  jmp    L147
  nopl   (%rax)
L5:
  subsd  %xmm2,%xmm1
  add    $0x1,%rax
  addsd  %xmm3,%xmm0
  comisd %xmm4,%xmm1
  jbe    L147
L6:
  movzbl -0x1(%r15,%rax,1),%edx
  pxor   %xmm3,%xmm3
  mov    %eax,%r14d
  add    $0xffffff80,%edx
  comisd %xmm2,%xmm1
  cvtsi2sd %edx,%xmm3
  jae    L5
  movapd %xmm3,%xmm7
  add    $0x1,%rax
  mulsd  %xmm1,%xmm7
  subsd  %xmm2,%xmm1
  comisd %xmm4,%xmm1
  addsd  %xmm7,%xmm0
  ja     L6
L147:
  divsd  %xmm6,%xmm0
  jmp    L60
  nopw   0x0(%rax,%rax,1)
L62:
  mov    0x3c(%rsp),%ecx
  cmp    $0x1,%ecx
  jle    L168
  lea    -0x1(%rcx),%eax
  mov    %ecx,%r13d
  and    %r12d,%eax
  sub    %eax,%r13d
  cmp    %r13d,%ecx
  je     L168
  pxor   %xmm1,%xmm1
  movapd %xmm0,%xmm6
  cvtsi2sd %r13d,%xmm1
  divsd  %xmm1,%xmm6
  movsd  %xmm6,0x8(%rsp)
  test   %r13d,%r13d
  jle    L168
  xor    %r14d,%r14d
  nopl   0x0(%rax)
L171:
  subsd  0x8(%rsp),%xmm0
  add    $0x1,%r14d
  movsd  %xmm0,(%rsp)
  call   <round@plt>
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    %rbx,%rdi
  mov    $0x1,%esi
  mov    %al,0x47(%rsp)
  call   <fwrite@plt>
  cmp    %r14d,%r13d
  movsd  (%rsp),%xmm0
  jne    L171
  add    %r13d,%r12d
L168:
  mov    0x30(%rsp),%rcx
  mov    %r12d,%edx
  mov    %rbp,%rdi
  xor    %esi,%esi
  call   <inEx@plt>
  mov    %rbp,%rdi
  mov    %rax,%r12
  call   <fclose@plt>
L122:
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L26
  add    $0x58,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L1:
  lea    D31(%rip),%rdi
  xor    %r12d,%r12d
  call   <printf@plt>
  jmp    L122
L26:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D37
data_type: string
name: extract_symbolic_data
arguments: label: D43
data_type: string
name: extract_symbolic_data
arguments: label: D32
data_type: f32[2]
name: extract_symbolic_data
arguments: label: D31
data_type: string

tool: D37: tmp.bin

tool: D43: wb+

tool: {"D32": [0.0,1.875]}

tool: D31: Error: cannot open file tmp.bin


assistant: ```c
unsigned char *resample(unsigned char *data, int offset, int len, int inputRate, int outputRate, int align, int *outSize) {
  FILE *f = fopen("tmp.bin", "wb+");
  if (f == NULL) {
    printf("Error: cannot open file tmp.bin\n");
    return NULL;
  }
  const double step = (double)inputRate / (double)outputRate;
  double value;
  double lastSample;
  double sample = 0;
  unsigned char byte;
  double dOff;
  int off;
  int outOff;
  value = 0;
  lastSample = 0;
  off = 0;
  outOff = 0;
  for (dOff = 0; dOff < len; dOff += step) {
    sample = 0;
    if (step >= 1) {
      if (value < 0)
        sample += lastSample * -value;
      value += step;
      while (value > 0) {
        lastSample = (data[off + offset] & 0xFF) - 0x80;
        off++;
        if (value >= 1)
          sample += lastSample;
        else
          sample += lastSample * value;
        value--;
      }
      sample /= step;
    } else {
      sample = (data[(int)dOff + offset] & 0xFF) - 0x80;
    }
    byte = round(sample);
    fwrite(&byte, 1, 1, f);
    outOff++;
  }
  if (align > 1) {
    const int mask = align - 1;
    const int size = align - (outOff & mask);
    if (size != align) {
      double reduce = sample / size;
      int i;
      for (i = 0; i < size; i++) {
        sample -= reduce;
        byte = round(sample);
        fwrite(&byte, 1, 1, f);
        outOff++;
      }
    }
  }
  unsigned char *result = inEx(f, 0, outOff, outSize);
  fclose(f);
  return result;
}
```