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

```asm
<medusaReceiveDataInternal>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %r8d,%r13d
  push   %r12
  mov    %edi,%r12d
  mov    $0x5dd,%edi
  push   %rbp
  push   %rbx
  mov    %ecx,%ebx
  sub    $0x28,%rsp
  movl   $0x0,(%rsi)
  mov    %rsi,0x10(%rsp)
  mov    %edx,0x1c(%rsp)
  call   <malloc@plt>
  xor    %esi,%esi
  mov    $0x5dd,%edx
  mov    %rax,%rdi
  mov    %rax,%rbp
  call   <memset@plt>
  movslq %ebx,%rsi
  mov    %ebx,%eax
  mov    %r12d,%edi
  imul   $0x431bde83,%rsi,%rsi
  sar    $0x1f,%eax
  sar    $0x32,%rsi
  sub    %eax,%esi
  imul   $0xf4240,%esi,%eax
  sub    %eax,%ebx
  mov    %ebx,%edx
  call   <medusaDataReadyTimed@plt>
  test   %eax,%eax
  jg     L0
  lea    D37(%rip),%rsi
  mov    $0x7,%edi
  jne    L100
L2:
  xor    %eax,%eax
  call   <writeError@plt>
  mov    %rbp,%rdi
  xor    %ebp,%ebp
  call   <free@plt>
L34:
  add    $0x28,%rsp
  mov    %rbp,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L100:
  lea    D60(%rip),%rsi
  mov    $0x3,%edi
  jmp    L2
  cs nopw 0x0(%rax,%rax,1)
L0:
  lea    D52(%rip),%rsi
  mov    $0x7,%edi
  xor    %eax,%eax
  call   <writeError@plt>
  mov    $0x5dc,%edx
  mov    %rbp,%rsi
  mov    %r12d,%edi
  call   <medusaReceive@plt>
  mov    %eax,%ebx
  test   %eax,%eax
  jle    L78
  movslq %r13d,%r14
  mov    %r13d,%eax
  imul   $0x431bde83,%r14,%r14
  sar    $0x1f,%eax
  sar    $0x32,%r14
  sub    %eax,%r14d
  imul   $0xf4240,%r14d,%eax
  sub    %eax,%r13d
  mov    %r13d,0x8(%rsp)
  jmp    L96
  nopl   (%rax)
L121:
  movslq %ebx,%rdi
  mov    %r15,%rsi
  mov    %r13d,%ebx
  add    %rbp,%rdi
  call   <memcpy@plt>
  mov    %r15,%rdi
  call   <free@plt>
L96:
  mov    0x8(%rsp),%edx
  mov    %r14d,%esi
  mov    %r12d,%edi
  call   <medusaDataReadyTimed@plt>
  test   %eax,%eax
  jle    L65
  mov    $0x5dd,%edi
  call   <malloc@plt>
  mov    $0x5dd,%edx
  xor    %esi,%esi
  mov    %rax,%r15
  mov    %rax,%rdi
  call   <memset@plt>
  mov    $0x5dc,%edx
  mov    %r15,%rsi
  mov    %r12d,%edi
  call   <medusaReceive@plt>
  mov    %eax,%edx
  test   %eax,%eax
  jle    L138
  lea    (%rbx,%rax,1),%r13d
  cmp    $0x5dc,%r13d
  jle    L121
  lea    0x1(%r13),%r9d
  mov    %eax,0xc(%rsp)
  mov    $0x7,%edi
  xor    %eax,%eax
  mov    %r9d,%ecx
  lea    D1(%rip),%rsi
  mov    %r9d,0x18(%rsp)
  call   <writeError@plt>
  mov    0x18(%rsp),%esi
  mov    %rbp,%rdi
  call   <realloc@plt>
  mov    0xc(%rsp),%edx
  mov    %rax,%rbp
  jmp    L121
  nopw   0x0(%rax,%rax,1)
L138:
  mov    $0x7,%edi
  lea    D16(%rip),%rsi
  xor    %eax,%eax
  call   <writeError@plt>
  mov    %r15,%rdi
  call   <free@plt>
L65:
  movslq %ebx,%rax
  movb   $0x0,0x0(%rbp,%rax,1)
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  je     L23
  lea    -0x1(%rbx),%edx
  mov    %rbp,%rax
  lea    0x1(%rbp,%rdx,1),%rdx
  xchg   %ax,%ax
L122:
  cmpb   $0x0,(%rax)
  jne    L13
  movb   $0x20,(%rax)
L13:
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L122
L23:
  mov    %rbp,%rcx
  mov    %ebx,%edx
  lea    D39(%rip),%rsi
  xor    %eax,%eax
  mov    $0x7,%edi
  call   <writeError@plt>
  mov    0x10(%rsp),%rax
  mov    %ebx,(%rax)
  jmp    L34
L78:
  lea    D7(%rip),%rsi
  mov    $0x7,%edi
  jmp    L2
```

tool_calls: name: unpack_data
arguments: data_tag: D37
type: string
name: unpack_data
arguments: data_tag: D60
type: string
name: unpack_data
arguments: data_tag: D52
type: string
name: unpack_data
arguments: data_tag: D1
type: string
name: unpack_data
arguments: data_tag: D16
type: string
name: unpack_data
arguments: data_tag: D39
type: string
name: unpack_data
arguments: data_tag: D7
type: string

tool: D37: Data receive: No data.

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

tool: D52: Data receive: Data waiting.

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

tool: D16: Data receive: No additional data.

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

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

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;
}
```