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    D44(%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    D2(%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     L40
  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    L97
  movslq 0x38(%rsp),%r8
  pxor   %xmm4,%xmm4
  xor    %r14d,%r14d
  lea    0x47(%rsp),%rbx
  movsd  D35(%rip),%xmm2
  movapd %xmm4,%xmm5
  movapd %xmm4,%xmm3
  movapd %xmm4,%xmm1
  lea    0x0(%r13,%r8,1),%r15
  jmp    L157
  nopl   0x0(%rax)
L134:
  cvttsd2si %xmm5,%eax
  add    0x38(%rsp),%eax
  pxor   %xmm0,%xmm0
  cltq
  movzbl 0x0(%r13,%rax,1),%eax
  add    $0xffffff80,%eax
  cvtsi2sd %eax,%xmm0
L110:
  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    D35(%rip),%rax
  addsd  %xmm6,%xmm5
  movsd  (%rsp),%xmm0
  movsd  0x8(%rsp),%xmm3
  movsd  0x18(%rsp),%xmm1
  movq   %rax,%xmm2
  comisd %xmm5,%xmm7
  jbe    L131
L157:
  comisd %xmm2,%xmm6
  jb     L134
  comisd %xmm1,%xmm4
  movapd %xmm4,%xmm0
  jbe    L60
  movapd %xmm1,%xmm7
  mulsd  %xmm3,%xmm7
  subsd  %xmm7,%xmm0
L60:
  addsd  %xmm6,%xmm1
  lea    0x1(%r14),%eax
  cltq
  comisd %xmm4,%xmm1
  ja     L138
  jmp    L108
  nopl   (%rax)
L113:
  subsd  %xmm2,%xmm1
  add    $0x1,%rax
  addsd  %xmm3,%xmm0
  comisd %xmm4,%xmm1
  jbe    L108
L138:
  movzbl -0x1(%r15,%rax,1),%edx
  pxor   %xmm3,%xmm3
  mov    %eax,%r14d
  add    $0xffffff80,%edx
  comisd %xmm2,%xmm1
  cvtsi2sd %edx,%xmm3
  jae    L113
  movapd %xmm3,%xmm7
  add    $0x1,%rax
  mulsd  %xmm1,%xmm7
  subsd  %xmm2,%xmm1
  comisd %xmm4,%xmm1
  addsd  %xmm7,%xmm0
  ja     L138
L108:
  divsd  %xmm6,%xmm0
  jmp    L110
  nopw   0x0(%rax,%rax,1)
L131:
  mov    0x3c(%rsp),%ecx
  cmp    $0x1,%ecx
  jle    L97
  lea    -0x1(%rcx),%eax
  mov    %ecx,%r13d
  and    %r12d,%eax
  sub    %eax,%r13d
  cmp    %r13d,%ecx
  je     L97
  pxor   %xmm1,%xmm1
  movapd %xmm0,%xmm6
  cvtsi2sd %r13d,%xmm1
  divsd  %xmm1,%xmm6
  movsd  %xmm6,0x8(%rsp)
  test   %r13d,%r13d
  jle    L97
  xor    %r14d,%r14d
  nopl   0x0(%rax)
L34:
  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    L34
  add    %r13d,%r12d
L97:
  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>
L129:
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L49
  add    $0x58,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L40:
  lea    D47(%rip),%rdi
  xor    %r12d,%r12d
  call   <printf@plt>
  jmp    L129
L49:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_label: D44
data_type: string
name: read_data
arguments: data_label: D2
data_type: string
name: read_data
arguments: data_label: D35
data_type: f32[2]
name: read_data
arguments: data_label: D47
data_type: string

tool: D44: tmp.bin

tool: D2: wb+

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

tool: D47: 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;
}
```