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

```asm
<medusaReceiveDataInternal>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %edx,-0x48(%rbp)
  mov    %ecx,-0x54(%rbp)
  mov    %r8d,-0x58(%rbp)
  movl   $0x5dc,-0x2c(%rbp)
  movl   $0x0,-0x34(%rbp)
  movl   $0x0,-0x28(%rbp)
  movl   $0x0,-0x30(%rbp)
  movl   $0x0,-0x24(%rbp)
  movl   $0x0,-0x20(%rbp)
  movl   $0x0,-0x1c(%rbp)
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x14(%rbp)
  mov    -0x50(%rbp),%rax
  movl   $0x0,(%rax)
  mov    -0x2c(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    -0x54(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x431bde83,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x12,%edx
  sar    $0x1f,%eax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  mov    %eax,-0x20(%rbp)
  mov    -0x54(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x431bde83,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x12,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0xf4240,%edx,%edx
  sub    %edx,%eax
  mov    %eax,-0x1c(%rbp)
  mov    -0x58(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x431bde83,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x12,%edx
  sar    $0x1f,%eax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  mov    %eax,-0x18(%rbp)
  mov    -0x58(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x431bde83,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x12,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0xf4240,%edx,%edx
  sub    %edx,%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x1c(%rbp),%edx
  mov    -0x20(%rbp),%ecx
  mov    -0x44(%rbp),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <medusaDataReadyTimed@plt>
  mov    %eax,-0x24(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  jle    L138
  lea    D42(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x2c(%rbp),%edx
  mov    -0x10(%rbp),%rcx
  mov    -0x44(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <medusaReceive@plt>
  mov    %eax,-0x34(%rbp)
  cmpl   $0x0,-0x34(%rbp)
  jg     L49
  lea    D17(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
  jmp    L85
L138:
  cmpl   $0x0,-0x24(%rbp)
  jne    L95
  lea    D37(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
  jmp    L85
L95:
  lea    D66(%rip),%rax
  mov    %rax,%rsi
  mov    $0x3,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x0,%eax
  jmp    L85
L139:
  mov    -0x2c(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    -0x8(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    -0x2c(%rbp),%edx
  mov    -0x8(%rbp),%rcx
  mov    -0x44(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <medusaReceive@plt>
  mov    %eax,-0x28(%rbp)
  cmpl   $0x0,-0x28(%rbp)
  jg     L129
  lea    D35(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  jmp    L111
L129:
  mov    -0x34(%rbp),%edx
  mov    -0x28(%rbp),%eax
  add    %edx,%eax
  cmp    %eax,-0x2c(%rbp)
  jge    L20
  mov    -0x34(%rbp),%edx
  mov    -0x28(%rbp),%eax
  add    %edx,%eax
  lea    0x1(%rax),%edx
  mov    -0x28(%rbp),%eax
  mov    %edx,%ecx
  mov    %eax,%edx
  lea    D15(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x34(%rbp),%edx
  mov    -0x28(%rbp),%eax
  add    %edx,%eax
  lea    0x1(%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x10(%rbp)
L20:
  mov    -0x34(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x28(%rbp),%edx
  mov    -0x8(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x28(%rbp),%eax
  add    %eax,-0x34(%rbp)
  movl   $0x0,-0x28(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L49:
  mov    -0x14(%rbp),%edx
  mov    -0x18(%rbp),%ecx
  mov    -0x44(%rbp),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <medusaDataReadyTimed@plt>
  test   %eax,%eax
  jg     L139
L111:
  mov    -0x34(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  cmpl   $0x0,-0x48(%rbp)
  je     L62
  movl   $0x0,-0x30(%rbp)
  jmp    L71
L103:
  mov    -0x30(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L44
  mov    -0x30(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movb   $0x20,(%rax)
L44:
  addl   $0x1,-0x30(%rbp)
L71:
  mov    -0x30(%rbp),%eax
  cmp    -0x34(%rbp),%eax
  jl     L103
L62:
  mov    -0x10(%rbp),%rdx
  mov    -0x34(%rbp),%eax
  mov    %rdx,%rcx
  mov    %eax,%edx
  lea    D43(%rip),%rax
  mov    %rax,%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    -0x50(%rbp),%rax
  mov    -0x34(%rbp),%edx
  mov    %edx,(%rax)
  mov    -0x10(%rbp),%rax
L85:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: tag: D42
type: string
name: retrieve_data
arguments: tag: D17
type: string
name: retrieve_data
arguments: tag: D37
type: string
name: retrieve_data
arguments: tag: D66
type: string
name: retrieve_data
arguments: tag: D35
type: string
name: retrieve_data
arguments: tag: D15
type: string
name: retrieve_data
arguments: tag: D43
type: string

tool: D42: Data receive: Data waiting.

tool: D17: Data receive: Socket indicated data present, but none found.

tool: D37: Data receive: No data.

tool: D66: Data receive: Failed to read from network socket.

tool: D35: Data receive: No additional data.

tool: D15: Additional data received. Increasing receive buffer %d bytes to %d.

tool: D43: Formatted data received (size %d): %s

assistant: ```c
unsigned char *medusaReceiveDataInternal(int socket, int *nBufferSize, int nConvertNullsToSpaces, int nReceiveDelay1, int nReceiveDelay2) {
  const int BUFFER_SIZE = 1500;
  unsigned char *szBufReceive, *szBufReceiveTmp;
  int nBufReceive = 0, nBufReceiveTmp = 0, BufReceiveIndex = 0;
  int bSocketStatus = 0;
  int nReceiveDelay1sec = 0, nReceiveDelay1usec = 0;
  int nReceiveDelay2sec = 0, nReceiveDelay2usec = 0;
  *nBufferSize = 0;
  szBufReceive = malloc(BUFFER_SIZE + 1);
  memset(szBufReceive, 0, BUFFER_SIZE + 1);
  nReceiveDelay1sec = nReceiveDelay1 / 1000000;
  nReceiveDelay1usec = nReceiveDelay1 % 1000000;
  nReceiveDelay2sec = nReceiveDelay2 / 1000000;
  nReceiveDelay2usec = nReceiveDelay2 % 1000000;
  bSocketStatus = medusaDataReadyTimed(socket, nReceiveDelay1sec, nReceiveDelay1usec);
  if (bSocketStatus > 0) {
    writeError(7, "Data receive: Data waiting.");
    nBufReceive = medusaReceive(socket, szBufReceive, BUFFER_SIZE);
    if (nBufReceive <= 0) {
      writeError(7, "Data receive: Socket indicated data present, but none found.");
      free(szBufReceive);
      return NULL;
    }
  } else if (bSocketStatus == 0) {
    writeError(7, "Data receive: No data.");
    free(szBufReceive);
    return NULL;
  } else {
    writeError(3, "Data receive: Failed to read from network socket.");
    free(szBufReceive);
    return NULL;
  }
  while (medusaDataReadyTimed(socket, nReceiveDelay2sec, nReceiveDelay2usec) > 0) {
    szBufReceiveTmp = malloc(BUFFER_SIZE + 1);
    memset(szBufReceiveTmp, 0, BUFFER_SIZE + 1);
    nBufReceiveTmp = medusaReceive(socket, szBufReceiveTmp, BUFFER_SIZE);
    if (nBufReceiveTmp <= 0) {
      writeError(7, "Data receive: No additional data.");
      free(szBufReceiveTmp);
      break;
    }
    if (nBufReceive + nBufReceiveTmp > BUFFER_SIZE) {
      writeError(7, "Additional data received. Increasing receive buffer %d bytes to %d.", nBufReceiveTmp, nBufReceive + nBufReceiveTmp + 1);
      szBufReceive = realloc(szBufReceive, nBufReceive + nBufReceiveTmp + 1);
    }
    memcpy(szBufReceive + nBufReceive, szBufReceiveTmp, nBufReceiveTmp);
    nBufReceive += nBufReceiveTmp;
    nBufReceiveTmp = 0;
    free(szBufReceiveTmp);
  }
  szBufReceive[nBufReceive] = 0;
  if (nConvertNullsToSpaces != 0)
    for (BufReceiveIndex = 0; BufReceiveIndex < nBufReceive; BufReceiveIndex++)
      if (szBufReceive[BufReceiveIndex] == 0)
        szBufReceive[BufReceiveIndex] = 32;
  writeError(7, "Formatted data received (size %d): %s", nBufReceive, szBufReceive);
  *nBufferSize = nBufReceive;
  return szBufReceive;
}
```