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

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  mov    %rsi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edi,%ebx
  sub    $0x68,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x58(%rsp)
  xor    %eax,%eax
  cmp    $0x2,%edi
  jle    L95
  mov    0x8(%rsi),%rdi
  lea    D156(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L202
L88:
  movq   $0x0,(%rsp)
  cmp    $0x3,%ebx
  jg     L67
L128:
  lea    0x30(%rsp),%rbx
  lea    0x4c(%rsp),%rdx
  mov    %rbp,%rdi
  xor    %eax,%eax
  lea    D97(%rip),%r13
  lea    D141(%rip),%rsi
  call   <fscanf@plt>
  mov    %rbx,%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  mov    %rbx,0x8(%rsp)
  lea    D125(%rip),%r12
  call   <fscanf@plt>
  lea    0x50(%rsp),%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x54(%rsp),%rax
  mov    %r13,%rsi
  mov    %rbp,%rdi
  mov    %rax,%rdx
  mov    %rax,0x10(%rsp)
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %rbx,%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x24(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x26(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x38(%rsp),%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x40(%rsp),%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  lea    0x28(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  xor    %eax,%eax
  lea    0x2a(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <fscanf@plt>
  cmpq   $0x10,0x30(%rsp)
  je     L89
  xor    %r15d,%r15d
  lea    0x2c(%rsp),%r12
  lea    D153(%rip),%rbx
  nopw   0x0(%rax,%rax,1)
L105:
  mov    %r12,%rdx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    0x30(%rsp),%rax
  add    $0x1,%r15
  sub    $0x10,%rax
  cmp    %r15,%rax
  ja     L105
L89:
  mov    0x10(%rsp),%rdx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    0x8(%rsp),%rdx
  xor    %eax,%eax
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <fscanf@plt>
  cmpq   $0x0,(%rsp)
  jne    L141
  mov    0x38(%rsp),%rax
  mov    %rax,(%rsp)
L271:
  mov    0x10(%r14),%rdi
  lea    D76(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L42
L120:
  movzwl 0x2a(%rsp),%eax
  movswl 0x26(%rsp),%ecx
  test   %ax,%ax
  lea    0x7(%rax),%ebx
  cmovns %eax,%ebx
  mov    0x30(%rsp),%rax
  xor    %edx,%edx
  sar    $0x3,%bx
  movswl %bx,%ebx
  imul   %ebx,%ecx
  movslq %ecx,%rcx
  div    %rcx
  mov    0x38(%rsp),%rdx
  test   %rdx,%rdx
  js     L22
  pxor   %xmm1,%xmm1
  cvtsi2sd %rdx,%xmm1
L159:
  mov    (%rsp),%rcx
  test   %rcx,%rcx
  js     L175
  pxor   %xmm0,%xmm0
  cvtsi2sd %rcx,%xmm0
L6:
  divsd  %xmm0,%xmm1
  pxor   %xmm7,%xmm7
  cvtsi2sd %eax,%xmm7
  movq   %xmm7,%r13
  movsd  %xmm1,0x10(%rsp)
  test   %eax,%eax
  jle    L110
  pxor   %xmm2,%xmm2
  lea    0x23(%rsp),%r14
  pxor   %xmm7,%xmm7
  movapd %xmm2,%xmm1
  movsd  %xmm2,0x18(%rsp)
  movapd %xmm2,%xmm3
  nopw   0x0(%rax,%rax,1)
L24:
  addsd  0x10(%rsp),%xmm1
  comisd %xmm7,%xmm1
  ja     L104
  jmp    L100
  xchg   %ax,%ax
L262:
  addsd  %xmm0,%xmm3
L188:
  subsd  D148(%rip),%xmm1
  pxor   %xmm4,%xmm4
  comisd %xmm4,%xmm1
  jbe    L100
L104:
  movswl 0x26(%rsp),%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  movsd  %xmm1,0x8(%rsp)
  movsd  %xmm3,(%rsp)
  call   <nextSample@plt>
  movsd  0x8(%rsp),%xmm1
  movsd  (%rsp),%xmm3
  comisd D148(%rip),%xmm1
  movapd %xmm0,%xmm2
  jae    L262
  mulsd  %xmm1,%xmm0
  addsd  %xmm0,%xmm3
  jmp    L188
  nopl   0x0(%rax,%rax,1)
L100:
  divsd  0x10(%rsp),%xmm3
  movapd %xmm3,%xmm0
  movsd  %xmm1,0x8(%rsp)
  movsd  %xmm2,(%rsp)
  call   <round@plt>
  mov    %r12,%rcx
  mov    $0x1,%edx
  mov    %r14,%rdi
  mov    $0x1,%esi
  mov    %al,0x23(%rsp)
  call   <fwrite@plt>
  movsd  0x18(%rsp),%xmm5
  movq   %r13,%xmm6
  addsd  0x10(%rsp),%xmm5
  movsd  (%rsp),%xmm2
  movsd  0x8(%rsp),%xmm1
  comisd %xmm5,%xmm6
  movsd  %xmm5,0x18(%rsp)
  jbe    L110
  pxor   %xmm7,%xmm7
  pxor   %xmm3,%xmm3
  comisd %xmm1,%xmm7
  jbe    L24
  movapd %xmm1,%xmm0
  movapd %xmm7,%xmm3
  mulsd  %xmm2,%xmm0
  subsd  %xmm0,%xmm3
  jmp    L24
  nopw   0x0(%rax,%rax,1)
L110:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r12,%rdi
  call   <fclose@plt>
  mov    0x58(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L113
  add    $0x68,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L141:
  mov    0x38(%rsp),%rdx
  mov    (%rsp),%rax
  cmp    %rax,%rdx
  jae    L271
  mov    %rax,%rsi
  lea    D120(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D126(%rip),%rdi
  call   <puts@plt>
  mov    $0x4,%edi
  call   <exit@plt>
  jmp    L271
L67:
  mov    0x18(%r14),%rdi
  call   <atoi@plt>
  mov    %rax,(%rsp)
  jmp    L128
L175:
  mov    (%rsp),%rsi
  pxor   %xmm0,%xmm0
  mov    %rsi,%rcx
  and    $0x1,%esi
  shr    %rcx
  or     %rsi,%rcx
  cvtsi2sd %rcx,%xmm0
  addsd  %xmm0,%xmm0
  jmp    L6
L22:
  mov    %rdx,%rcx
  and    $0x1,%edx
  pxor   %xmm1,%xmm1
  shr    %rcx
  or     %rdx,%rcx
  cvtsi2sd %rcx,%xmm1
  addsd  %xmm1,%xmm1
  jmp    L159
L95:
  lea    D0(%rip),%rdi
  call   <puts@plt>
  lea    D13(%rip),%rdi
  call   <puts@plt>
  lea    D105(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D158(%rip),%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  mov    0x8(%r14),%rdi
  lea    D156(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L202
  movq   $0x0,(%rsp)
  jmp    L128
L202:
  mov    0x8(%r14),%rsi
  lea    D81(%rip),%rdi
  xor    %eax,%eax
  xor    %ebp,%ebp
  call   <printf@plt>
  mov    $0x2,%edi
  call   <exit@plt>
  jmp    L88
L42:
  mov    0x10(%r14),%rsi
  lea    D60(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x3,%edi
  call   <exit@plt>
  jmp    L120
L113:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D156
data_type: string
name: extract_symbolic_data
arguments: data_tag: D97
data_type: string
name: extract_symbolic_data
arguments: data_tag: D141
data_type: string
name: extract_symbolic_data
arguments: data_tag: D125
data_type: string
name: extract_symbolic_data
arguments: data_tag: D153
data_type: string
name: extract_symbolic_data
arguments: data_tag: D76
data_type: string
name: extract_symbolic_data
arguments: data_tag: D148
data_type: f32
name: extract_symbolic_data
arguments: data_tag: D120
data_type: string
name: extract_symbolic_data
arguments: data_tag: D126
data_type: string
name: extract_symbolic_data
arguments: data_tag: D0
data_type: string
name: extract_symbolic_data
arguments: data_tag: D13
data_type: string
name: extract_symbolic_data
arguments: data_tag: D105
data_type: string
name: extract_symbolic_data
arguments: data_tag: D158
data_type: string
name: extract_symbolic_data
arguments: data_tag: D81
data_type: string
name: extract_symbolic_data
arguments: data_tag: D60
data_type: string

tool: D156: rb

tool: D97: %4c

tool: D141: %4s

tool: D125: %2c

tool: D153: %1c

tool: D76: w

tool: D148: 0

tool: D120: Output rate (%ld) cannot be above input rate (%ld)


tool: D126: Use lower output rate value or higher input rate file

tool: D0: Usage: wav2raw sourceWavFile destRawFile <outRate>

tool: D13: Output rate is given in Hand should be <= to the input sample sample.

tool: D105: Success returns errorlevel 0. Error return greater than zero.

tool: D158: Ex: wav2raw input.wav output.raw 11025

tool: D81: The source file %s was not opened


tool: D60: The output file %s was not opened


assistant: ```c
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  char prefix[4];
  char fileFormat[4];
  char ckID[4];
  unsigned long nChunkSize;
  short wFormatTag;
  short nChannels;
  unsigned long nSamplesPerSecond;
  unsigned long nBytesPerSecond;
  unsigned long nOutputSamplesPerSecond;
  short nBlockAlign;
  short nBitsPerSample;
  int i, j;
  if (argc < 3) {
    printf("Usage: wav2raw sourceWavFile destRawFile <outRate>\n");
    printf("Output rate is given in Hand should be <= to the input sample sample.\n");
    printf("Success returns errorlevel 0. Error return greater than zero.\n");
    printf("\n");
    printf("Ex: wav2raw input.wav output.raw 11025\n");
    exit(1);
  }
  if ((infile = fopen(argv[1], "rb")) == NULL) {
    printf("The source file %s was not opened\n", argv[1]);
    exit(2);
  }
  if (argc > 3)
    nOutputSamplesPerSecond = atoi(argv[3]);
  else
    nOutputSamplesPerSecond = 0;
  fscanf(infile, "%4s", prefix);
  fscanf(infile, "%4c", &nChunkSize);
  fscanf(infile, "%4c", fileFormat);
  fscanf(infile, "%4c", ckID);
  fscanf(infile, "%4c", &nChunkSize);
  fscanf(infile, "%2c", &wFormatTag);
  fscanf(infile, "%2c", &nChannels);
  fscanf(infile, "%4c", &nSamplesPerSecond);
  fscanf(infile, "%4c", &nBytesPerSecond);
  fscanf(infile, "%2c", &nBlockAlign);
  fscanf(infile, "%2c", &nBitsPerSample);
  for (i = 0; i < nChunkSize - 0x10; i++)
    fscanf(infile, "%1c", &j);
  fscanf(infile, "%4c", ckID);
  fscanf(infile, "%4c", &nChunkSize);
  if (nOutputSamplesPerSecond == 0)
    nOutputSamplesPerSecond = nSamplesPerSecond;
  if (nSamplesPerSecond < nOutputSamplesPerSecond) {
    printf("Output rate (%ld) cannot be above input rate (%ld)\n", nOutputSamplesPerSecond, nSamplesPerSecond);
    printf("Use lower output rate value or higher input rate file\n");
    exit(4);
  }
  if ((outfile = fopen(argv[2], "w")) == NULL) {
    printf("The output file %s was not opened\n", argv[2]);
    exit(3);
  }
  int nBytesPerSample = nBitsPerSample / 8;
  int size = nChunkSize / (nChannels * nBytesPerSample);
  double offset;
  double step;
  double value;
  double lastSample;
  step = nSamplesPerSecond;
  step /= nOutputSamplesPerSecond;
  value = 0;
  lastSample = 0;
  for (offset = 0; offset < size; offset += step) {
    char byte;
    double sample = 0;
    if (value < 0)
      sample += lastSample * -value;
    value += step;
    while (value > 0) {
      lastSample = nextSample(infile, nBytesPerSample, nChannels);
      if (value >= 1)
        sample += lastSample;
      else
        sample += lastSample * value;
      value--;
    }
    sample /= step;
    byte = round(sample);
    fwrite(&byte, 1, 1, outfile);
  }
  fclose(infile);
  fclose(outfile);
  return 0;
}
```