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

```asm
<resample>:
  endbr64
  push   %r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  mov    %rdi,%r13
  lea    D6(%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    D5(%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     L54
  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    L15
  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    L25
  nopl   0x0(%rax)
L99:
  cvttsd2si %xmm5,%eax
  add    0x38(%rsp),%eax
  pxor   %xmm0,%xmm0
  cltq
  movzbl 0x0(%r13,%rax,1),%eax
  add    $0xffffff80,%eax
  cvtsi2sd %eax,%xmm0
L11:
  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    L124
L25:
  comisd %xmm2,%xmm6
  jb     L99
  comisd %xmm1,%xmm4
  movapd %xmm4,%xmm0
  jbe    L146
  movapd %xmm1,%xmm7
  mulsd  %xmm3,%xmm7
  subsd  %xmm7,%xmm0
L146:
  addsd  %xmm6,%xmm1
  lea    0x1(%r14),%eax
  cltq
  comisd %xmm4,%xmm1
  ja     L171
  jmp    L153
  nopl   (%rax)
L129:
  subsd  %xmm2,%xmm1
  add    $0x1,%rax
  addsd  %xmm3,%xmm0
  comisd %xmm4,%xmm1
  jbe    L153
L171:
  movzbl -0x1(%r15,%rax,1),%edx
  pxor   %xmm3,%xmm3
  mov    %eax,%r14d
  add    $0xffffff80,%edx
  comisd %xmm2,%xmm1
  cvtsi2sd %edx,%xmm3
  jae    L129
  movapd %xmm3,%xmm7
  add    $0x1,%rax
  mulsd  %xmm1,%xmm7
  subsd  %xmm2,%xmm1
  comisd %xmm4,%xmm1
  addsd  %xmm7,%xmm0
  ja     L171
L153:
  divsd  %xmm6,%xmm0
  jmp    L11
  nopw   0x0(%rax,%rax,1)
L124:
  mov    0x3c(%rsp),%ecx
  cmp    $0x1,%ecx
  jle    L15
  lea    -0x1(%rcx),%eax
  mov    %ecx,%r13d
  and    %r12d,%eax
  sub    %eax,%r13d
  cmp    %r13d,%ecx
  je     L15
  pxor   %xmm1,%xmm1
  movapd %xmm0,%xmm6
  cvtsi2sd %r13d,%xmm1
  divsd  %xmm1,%xmm6
  movsd  %xmm6,0x8(%rsp)
  test   %r13d,%r13d
  jle    L15
  xor    %r14d,%r14d
  nopl   0x0(%rax)
L44:
  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    L44
  add    %r13d,%r12d
L15:
  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>
L141:
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L116
  add    $0x58,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L54:
  lea    D13(%rip),%rdi
  xor    %r12d,%r12d
  call   <printf@plt>
  jmp    L141
L116:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_tag: D6
type_infered: string
name: parse_data
arguments: data_tag: D5
type_infered: string
name: parse_data
arguments: data_tag: D35
type_infered: f32[2]
name: parse_data
arguments: data_tag: D13
type_infered: string

tool: D6: tmp.bin

tool: D5: wb+

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

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