user: Please show me the C implementation that matches the assembly code listed below:

```asm
<read_flag>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %edi,%r15d
  push   %r14
  push   %r13
  mov    %edx,%r13d
  push   %r12
  mov    %ecx,%r12d
  push   %rbx
  sub    $0x38,%rsp
  mov    %rsi,-0x50(%rbp)
  mov    %rsp,%rcx
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  movslq %edx,%rax
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L148
L85:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L85
L148:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L67
L103:
  movl   $0x0,-0x3c(%rbp)
  mov    %rsp,%r14
  mov    %r13d,%ebx
  test   %r12d,%r12d
  je     L98
  lea    -0x3c(%rbp),%rax
  movl   $0x0,-0x48(%rbp)
  xor    %edx,%edx
  mov    %rax,-0x58(%rbp)
  xchg   %ax,%ax
L50:
  movslq %edx,%rsi
  xor    %ecx,%ecx
  mov    %ebx,%edx
  mov    %r15d,%edi
  add    %r14,%rsi
  call   <recvn@plt>
  cmp    %eax,%ebx
  jne    L17
  mov    -0x58(%rbp),%r8
  mov    -0x50(%rbp),%rdx
  mov    %r13d,%ecx
  mov    %r13d,%esi
  mov    %r14,%rdi
  call   <search_flag@plt>
  test   %eax,%eax
  je     L57
  mov    -0x3c(%rbp),%edx
  sub    %edx,%ebx
  add    %ebx,-0x48(%rbp)
  mov    -0x48(%rbp),%eax
  cmp    %eax,%r12d
  jle    L17
  mov    %r13d,%ebx
  sub    %edx,%ebx
  test   %edx,%edx
  jle    L50
  movslq %ebx,%rsi
  mov    %r14,%rdi
  add    %r14,%rsi
  call   <memmove@plt>
  mov    -0x3c(%rbp),%edx
  jmp    L50
  nopl   0x0(%rax)
L17:
  mov    $0xffffffff,%eax
L95:
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  jne    L55
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopw   0x0(%rax,%rax,1)
L57:
  xor    %eax,%eax
  jmp    L95
L98:
  lea    -0x3c(%rbp),%rax
  mov    %rax,-0x48(%rbp)
  nopl   0x0(%rax)
L113:
  movslq %r12d,%rsi
  xor    %ecx,%ecx
  mov    %ebx,%edx
  mov    %r15d,%edi
  add    %r14,%rsi
  call   <recvn@plt>
  cmp    %ebx,%eax
  jne    L17
  mov    -0x48(%rbp),%r8
  mov    -0x50(%rbp),%rdx
  mov    %r13d,%ecx
  mov    %r13d,%esi
  mov    %r14,%rdi
  call   <search_flag@plt>
  test   %eax,%eax
  je     L57
  mov    -0x3c(%rbp),%r12d
  mov    %r13d,%ebx
  sub    %r12d,%ebx
  test   %r12d,%r12d
  jle    L113
  movslq %ebx,%rsi
  mov    %r12d,%edx
  mov    %r14,%rdi
  add    %r14,%rsi
  call   <memmove@plt>
  mov    -0x3c(%rbp),%r12d
  jmp    L113
  cs nopw 0x0(%rax,%rax,1)
L67:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L103
L55:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int read_flag(int fd, const void *flag, const int flag_size, const int max_bytes) {
  char buff[flag_size];
  int left = 0;
  int bytes;
  int ret;
  int total_bytes = 0;
  while (1) {
    bytes = sizeof(buff) - left;
    if (left > 0)
      memmove(buff, &buff[bytes], left);
    if (recvn(fd, &buff[left], bytes, 0) != bytes)
      goto err;
    ret = search_flag(buff, sizeof(buff), flag, flag_size, &left);
    if (ret == 0)
      return 0;
    if (max_bytes == 0)
      continue;
    total_bytes += (bytes - left);
    if (total_bytes >= max_bytes)
      goto err;
  }
err:
  return -1;
}
```