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

```asm
<zlib_inflate>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x68,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x2058(%rsp)
  mov    D45(%rip),%rax
  lea    0x10(%rsp),%r12
  mov    %rdi,%rbx
  mov    %rsi,%rbp
  movq   $0x0,0x10(%rsp)
  mov    %r12,%rdi
  mov    (%rax),%rax
  movq   %rax,%xmm0
  mov    %rax,0x40(%rsp)
  punpcklqdq %xmm0,%xmm0
  mov    %rax,0x18(%rsp)
  movaps %xmm0,0x30(%rsp)
  call   <inflateInit@plt>
  mov    %eax,%r15d
  mov    D51(%rip),%rax
  cmp    %r15d,(%rax)
  jne    L55
  lea    0x50(%rsp),%r13
  lea    0x1050(%rsp),%r14
L77:
  mov    %r13,%rdi
  mov    %rbx,%rcx
  mov    $0x1000,%edx
  mov    $0x1,%esi
  call   <fread@plt>
  mov    %rbx,%rdi
  mov    %rax,0x10(%rsp)
  call   <ferror@plt>
  test   %rax,%rax
  jne    L167
  cmpq   $0x0,0x10(%rsp)
  je     L20
  mov    %r13,0x18(%rsp)
L164:
  mov    D7(%rip),%rax
  mov    %r12,%rdi
  mov    %r14,0x28(%rsp)
  movl   $0x1000,0x20(%rsp)
  mov    (%rax),%esi
  call   <inflate@plt>
  mov    %eax,%r15d
  mov    D29(%rip),%rax
  cmp    %r15d,(%rax)
  je     L55
  cmp    $0x80,%r15d
  je     L144
  lea    -0x81(%r15),%eax
  cmp    $0x1,%eax
  ja     L35
L143:
  mov    %r12,%rdi
  call   <inflateEnd@plt>
L55:
  mov    0x2058(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L0
  add    $0x2068,%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L35:
  mov    $0x1000,%edx
  mov    %rbp,%rcx
  sub    0x20(%rsp),%edx
  mov    %r14,%rdi
  mov    $0x1,%esi
  mov    %edx,0x8(%rsp)
  call   <fwrite@plt>
  mov    0x8(%rsp),%edx
  cmp    %edx,%eax
  jne    L167
  mov    %rbp,%rdi
  call   <ferror@plt>
  test   %rax,%rax
  jne    L167
  mov    0x20(%rsp),%eax
  test   %eax,%eax
  je     L164
  mov    D39(%rip),%rdx
  cmp    %r15d,(%rdx)
  jne    L77
L131:
  mov    %r12,%rdi
  mov    %rdx,0x8(%rsp)
  call   <inflateEnd@plt>
  mov    0x8(%rsp),%rdx
  cmp    %r15d,(%rdx)
  jne    L94
  mov    D51(%rip),%rax
  mov    (%rax),%r15d
  jmp    L55
  nopl   0x0(%rax)
L144:
  mov    $0x82,%r15d
  jmp    L143
  nopl   0x0(%rax,%rax,1)
L167:
  mov    %r12,%rdi
  call   <inflateEnd@plt>
  mov    D20(%rip),%rax
  mov    (%rax),%r15d
  jmp    L55
L20:
  mov    D39(%rip),%rdx
  jmp    L131
L94:
  mov    $0x82,%r15d
  jmp    L55
L0:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int zlib_inflate(FILE *fin, FILE *fout) {
  z_stream strm;
  unsigned char bin[0x1000];
  unsigned char bout[0x1000];
  int nleft, result;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = 0;
  strm.next_in = Z_NULL;
  result = inflateInit(&strm);
  if (result != Z_OK)
    return result;
  do {
    strm.avail_in = fread(bin, 1, 0x1000, fin);
    if (ferror(fin)) {
      inflateEnd(&strm);
      return Z_ERRNO;
    }
    if (strm.avail_in == 0)
      break;
    strm.next_in = bin;
    do {
      strm.avail_out = 0x1000;
      strm.next_out = bout;
      result = inflate(&strm, Z_NO_FLUSH);
      if (result == Z_STREAM_ERROR)
        return result;
      switch (result) {
      case Z_NEED_DICT:
        result = Z_DATA_ERROR;
      case Z_DATA_ERROR:
      case Z_MEM_ERROR:
        inflateEnd(&strm);
        return result;
        break;
      }
      nleft = 0x1000 - strm.avail_out;
      if ((fwrite(bout, 1, nleft, fout) != nleft) || ferror(fout)) {
        inflateEnd(&strm);
        return Z_ERRNO;
      }
    } while (strm.avail_out == 0);
  } while (result != Z_STREAM_END);
  inflateEnd(&strm);
  if (result != Z_STREAM_END)
    return Z_DATA_ERROR;
  return Z_OK;
}
```