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

```asm
<medusaReceiveDataInternal>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %edi,%r13d
  mov    %rsi,0x10(%rsp)
  mov    %edx,0x1c(%rsp)
  mov    %ecx,%ebx
  mov    %r8d,%ebp
  movl   $0x0,(%rsi)
  mov    $0x5dd,%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    $0x5dd,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movslq %ebx,%rsi
  imul   $0x431bde83,%rsi,%rsi
  sar    $0x32,%rsi
  mov    %ebx,%eax
  sar    $0x1f,%eax
  sub    %eax,%esi
  imul   $0xf4240,%esi,%eax
  sub    %eax,%ebx
  mov    %ebx,%edx
  mov    %r13d,%edi
  call   <medusaDataReadyTimed@plt>
  test   %eax,%eax
  jg     L70
  jne    L72
  lea    D39(%rip),%rsi
  mov    $0x7,%edi
  call   <writeError@plt>
  mov    %r15,%rdi
  call   <free@plt>
  mov    $0x0,%r15d
  jmp    L54
L70:
  lea    D45(%rip),%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    $0x5dc,%edx
  mov    %r15,%rsi
  mov    %r13d,%edi
  call   <medusaReceive@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  jle    L97
  movslq %ebp,%rax
  imul   $0x431bde83,%rax,%rax
  sar    $0x32,%rax
  mov    %ebp,%edx
  sar    $0x1f,%edx
  sub    %edx,%eax
  mov    %eax,0xc(%rsp)
  imul   $0xf4240,%eax,%eax
  sub    %eax,%ebp
  mov    %ebp,0x18(%rsp)
  mov    %r15,(%rsp)
  jmp    L103
L97:
  lea    D5(%rip),%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    %r15,%rdi
  call   <free@plt>
  mov    $0x0,%r15d
  jmp    L54
L72:
  lea    D10(%rip),%rsi
  mov    $0x3,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    %r15,%rdi
  call   <free@plt>
  mov    $0x0,%r15d
  jmp    L54
L47:
  mov    (%rsp),%r15
  lea    D42(%rip),%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  jmp    L66
L62:
  movslq %ebx,%rdi
  add    (%rsp),%rdi
  mov    %r12d,%edx
  mov    %rbp,%rsi
  call   <memcpy@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    %r14d,%ebx
L103:
  mov    0x18(%rsp),%edx
  mov    0xc(%rsp),%esi
  mov    %r13d,%edi
  call   <medusaDataReadyTimed@plt>
  test   %eax,%eax
  jle    L22
  mov    $0x5dd,%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  mov    $0x5dd,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    $0x5dc,%edx
  mov    %rbp,%rsi
  mov    %r13d,%edi
  call   <medusaReceive@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jle    L47
  lea    (%rbx,%rax,1),%r14d
  cmp    $0x5dc,%r14d
  jle    L62
  lea    0x1(%r14),%r15d
  mov    %r15d,%ecx
  mov    %eax,%edx
  lea    D23(%rip),%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    %r15d,%esi
  mov    (%rsp),%rdi
  call   <realloc@plt>
  mov    %rax,(%rsp)
  jmp    L62
L22:
  mov    (%rsp),%r15
L66:
  movslq %ebx,%rax
  movb   $0x0,(%r15,%rax,1)
  cmpl   $0x0,0x1c(%rsp)
  je     L152
  test   %ebx,%ebx
  jle    L152
  mov    %r15,%rax
  lea    -0x1(%rbx),%edx
  lea    0x1(%r15,%rdx,1),%rdx
  jmp    L144
L170:
  add    $0x1,%rax
  cmp    %rdx,%rax
  je     L152
L144:
  cmpb   $0x0,(%rax)
  jne    L170
  movb   $0x20,(%rax)
  jmp    L170
L152:
  mov    %r15,%rcx
  mov    %ebx,%edx
  lea    D62(%rip),%rsi
  mov    $0x7,%edi
  mov    $0x0,%eax
  call   <writeError@plt>
  mov    0x10(%rsp),%rax
  mov    %ebx,(%rax)
L54:
  mov    %r15,%rax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D39
type_guessed: string
name: retrieve_data
arguments: data_label: D45
type_guessed: string
name: retrieve_data
arguments: data_label: D5
type_guessed: string
name: retrieve_data
arguments: data_label: D10
type_guessed: string
name: retrieve_data
arguments: data_label: D42
type_guessed: string
name: retrieve_data
arguments: data_label: D23
type_guessed: string
name: retrieve_data
arguments: data_label: D62
type_guessed: string

tool: D39: Data receive: No data.

tool: D45: Data receive: Data waiting.

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

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

tool: D42: Data receive: No additional data.

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

tool: D62: 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;
}
```