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

```asm
<patch_hdr>:
  endbr64
  push   %r15
  mov    %rdx,%r15
  push   %r14
  mov    %r9,%r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %r8,%r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x48,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  lea    0x8(%rsp),%rcx
  mov    %rsp,%rdx
  sub    $0x8,%rsp
  lea    0x38(%rsp),%rax
  push   %rax
  lea    0x38(%rsp),%rax
  push   %rax
  lea    0x38(%rsp),%rax
  push   %rax
  lea    0x30(%rsp),%r8
  lea    0x38(%rsp),%r9
  call   <parse_hdr@plt>
  add    $0x20,%rsp
  mov    %rax,%r8
  xor    %eax,%eax
  cmp    %rbp,%r8
  jne    L88
  mov    0x8(%rsp),%rdx
  lea    0x1c(%rdx),%rcx
  cmp    %rbp,%rcx
  je     L69
L88:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L57
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L69:
  cmp    $0x10,%rdx
  ja     L24
L64:
  mov    0x28(%rsp),%rcx
  mov    0x18(%rsp),%rsi
  test   %r12,%r12
  je     L97
L71:
  add    $0x7,%rcx
  shr    $0x3,%rcx
  imul   %rsi,%rcx
  imul   %r12,%rcx
  lea    0x24(%rcx),%rax
  movzbl %ch,%esi
  mov    %rcx,%rdx
  mov    %ecx,%r11d
  movzbl %ah,%edi
  mov    %rsi,%r8
  mov    %rcx,%rsi
  mov    %eax,%r10d
  shr    $0x10,%rsi
  mov    %rdi,%r9
  mov    %rax,%rdi
  shr    $0x18,%rdx
  shr    $0x10,%rdi
  shr    $0x18,%rax
L17:
  test   %r14,%r14
  je     L33
  mov    %rcx,(%r14)
L33:
  mov    %al,0x7(%rbx)
  mov    %rbp,%rax
  mov    %r10b,0x4(%rbx)
  mov    %r9b,0x5(%rbx)
  mov    %dil,0x6(%rbx)
  mov    %r11b,0x28(%rbx)
  mov    %r8b,0x29(%rbx)
  mov    %sil,0x2a(%rbx)
  mov    %dl,0x2b(%rbx)
  jmp    L88
  cs nopw 0x0(%rax,%rax,1)
L97:
  movabs $0x28f5c28f5c28f5c3,%rdx
  mov    0x20(%rsp),%rax
  imul   %rax,%r15
  shr    $0x2,%rax
  mul    %rdx
  mov    %r13,%rax
  shr    $0x2,%rdx
  mov    %rdx,%r12
  movabs $0xcccccccccccccccd,%rdx
  mul    %rdx
  shr    $0x3,%rdx
  imul   %rdx,%r12
  movabs $0x20c49ba5e353f7cf,%rdx
  shr    $0x3,%r12
  mov    %r12,%rax
  mul    %rdx
  shr    $0x4,%rdx
  add    %r15,%rdx
  mov    %rdx,%r12
  jne    L71
  mov    $0xffffffff,%edx
  mov    $0xffffffff,%esi
  mov    $0xffffffff,%eax
  mov    $0xffffffff,%r8d
  mov    $0xffffffdb,%r11d
  mov    $0xffffffff,%edi
  mov    $0xffffffdb,%ecx
  mov    $0xffffffff,%r9d
  mov    $0xffffffff,%r10d
  jmp    L17
  nopl   0x0(%rax,%rax,1)
L24:
  lea    0x14(%rbx,%rdx,1),%rsi
  lea    0x24(%rbx),%rdi
  mov    $0x8,%edx
  mov    $0x2c,%ebp
  call   <memmove@plt>
  movl   $0x10,0x10(%rbx)
  jmp    L64
L57:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
size_t patch_hdr(unsigned char *hdr, size_t hdr_len, unsigned long sec, unsigned long us, unsigned long samples, size_t *data_length_ret) {
  unsigned long chunk_data_length;
  unsigned long format_data_length;
  unsigned long compression_code;
  unsigned long channel_count;
  unsigned long sample_rate;
  unsigned long sample_bit_length;
  unsigned long data_length;
  unsigned long bytes_per_sample;
  if (parse_hdr(hdr, hdr_len, &chunk_data_length, &format_data_length, &compression_code, &channel_count, &sample_rate, &sample_bit_length, &data_length) != hdr_len)
    return 0;
  if (hdr_len != (20 + format_data_length + 8))
    return 0;
  if (format_data_length > 16) {
    memmove(hdr + 20 + 16, hdr + 20 + format_data_length, 8);
    hdr[16] = 16;
    hdr[17] = 0;
    hdr[18] = 0;
    hdr[19] = 0;
    format_data_length = 16;
    hdr_len = 44;
  }
  bytes_per_sample = channel_count * ((sample_bit_length + 7) / 8);
  if (samples == 0) {
    samples = sample_rate * sec;
    samples += ((sample_rate / 100) * (us / 10)) / 1000;
  }
  if (samples > 0) {
    data_length = samples * bytes_per_sample;
    chunk_data_length = data_length + 36;
  } else {
    chunk_data_length = 0xffffffff;
    data_length = chunk_data_length - 36;
  }
  if (data_length_ret != NULL)
    *data_length_ret = data_length;
  hdr[4] = chunk_data_length % 0x100;
  hdr[5] = (chunk_data_length >> 8) % 0x100;
  hdr[6] = (chunk_data_length >> 16) % 0x100;
  hdr[7] = (chunk_data_length >> 24) % 0x100;
  hdr[40] = data_length % 0x100;
  hdr[41] = (data_length >> 8) % 0x100;
  hdr[42] = (data_length >> 16) % 0x100;
  hdr[43] = (data_length >> 24) % 0x100;
  return hdr_len;
}
```