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

```asm
<socket_recv>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,-0x34(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x38(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L37
  mov    $0x0,%eax
  jmp    L11
L37:
  movl   $0x0,-0x28(%rbp)
  movl   $0x0,-0x24(%rbp)
  movl   $0x400,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x40(%rbp),%rax
  mov    %rdx,(%rax)
  movl   $0x0,-0x20(%rbp)
  jmp    L54
L24:
  cmpl   $0x0,-0x28(%rbp)
  jle    L34
  mov    -0x28(%rbp),%edx
  mov    -0x1c(%rbp),%eax
  add    %edx,%eax
  add    $0x1,%eax
  mov    %eax,%edx
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,%rdx
  mov    -0x40(%rbp),%rax
  mov    %rdx,(%rax)
L34:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x28(%rbp),%eax
  cltq
  lea    (%rdx,%rax,1),%rsi
  mov    -0x38(%rbp),%edx
  mov    -0x34(%rbp),%eax
  mov    %edx,%ecx
  mov    $0x400,%edx
  mov    %eax,%edi
  call   <recv@plt>
  mov    %eax,-0x24(%rbp)
  mov    -0x20(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x20(%rbp)
  mov    -0x24(%rbp),%edx
  mov    %eax,%esi
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x24(%rbp),%eax
  add    %eax,-0x28(%rbp)
  mov    -0x28(%rbp),%edx
  mov    -0x24(%rbp),%eax
  mov    %eax,%esi
  lea    D26(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rbx
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rbx,%rdx
  mov    %eax,%esi
  lea    D39(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  cmpl   $0x3ff,-0x24(%rbp)
  jle    L45
L54:
  cmpl   $0x0,-0x24(%rbp)
  jns    L24
  jmp    L43
L45:
  nop
L43:
  mov    -0x28(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rcx
  mov    -0x28(%rbp),%edx
  mov    -0x18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x28(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x28(%rbp),%eax
  mov    %eax,%esi
  lea    D38(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ecx
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdx
  mov    %ecx,%esi
  lea    D47(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x28(%rbp),%eax
L11:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: parse_data
arguments: data_label: D18
type: string
name: parse_data
arguments: data_label: D26
type: string
name: parse_data
arguments: data_label: D39
type: string
name: parse_data
arguments: data_label: D38
type: string
name: parse_data
arguments: data_label: D47
type: string

tool: D18: socket_recv iteration #%d, nread = %zd


tool: D26: Read %ld bytes from socket.
Total bytes read so far: %ld.


tool: D39: socket_recv buffer (%lu): %s




tool: D38: End of socket_recv iteration, total_read_size = %ld


tool: D47: socket_recv string output result (%lu): %s




assistant: ```c
ssize_t socket_recv(int sockfd, char **buffer, int flag) {
  if (!buffer) {
    return 0;
  }
  ssize_t total_read_size = 0;
  ssize_t nread = 0;
  ssize_t buffer_default_size = 1024 * sizeof(char);
  *buffer = (char *)malloc(buffer_default_size + sizeof(char));
  int iteration = 0;
  while (nread >= 0) {
    if (total_read_size > 0) {
      *buffer = (char *)realloc(*buffer, total_read_size + buffer_default_size + sizeof(char));
    }
    nread = recv(sockfd, *buffer + total_read_size, 1024, flag);
    if (1)
      printf("socket_recv iteration #%d, nread = %zd\n", iteration++, nread);
    total_read_size += nread;
    if (1)
      printf("Read %ld bytes from socket.\nTotal bytes read so far: %ld.\n", nread, total_read_size);
    if (1)
      printf("socket_recv buffer (%lu): %s\n\n\n", strlen(*buffer), *buffer);
    if (nread < 1024) {
      break;
    }
  }
  char *str_result = (char *)malloc(total_read_size + sizeof(char));
  strncpy(str_result, *buffer, total_read_size);
  str_result[total_read_size] = '\0';
  if (1)
    printf("End of socket_recv iteration, total_read_size = %ld\n", total_read_size);
  if (1)
    printf("socket_recv string output result (%lu): %s\n\n\n", strlen(str_result), str_result);
  return total_read_size;
}
```