#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int const);
int medusaDataReadyTimed(int, int, int);
int medusaReceive(int, char *, unsigned int const);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int const);
char *realloc(char *, int);
int /*<<< orphan*/ writeError(int, char *, ...);
char *medusaReceiveDataInternal(int socket, int *nBufferSize,
                                int nConvertNullsToSpaces, int nReceiveDelay1,
                                int nReceiveDelay2) {
  const unsigned int BUFFER_SIZE = 576;
  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;
}


x86 assembly (clang, -O0):
<medusaReceiveDataInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x240,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x241,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x241,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x54(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x58(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
call   1040 <medusaDataReadyTimed@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jle    12b2 <medusaReceiveDataInternal+0x132>
mov    $0x7,%edi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0xc(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x240,%edx
call   1050 <medusaReceive@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    12ad <medusaReceiveDataInternal+0x12d>
mov    $0x7,%edi
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    148f <medusaReceiveDataInternal+0x30f>
jmp    130e <medusaReceiveDataInternal+0x18e>
cmpl   $0x0,-0x48(%rbp)
jne    12e5 <medusaReceiveDataInternal+0x165>
mov    $0x7,%edi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    148f <medusaReceiveDataInternal+0x30f>
mov    $0x3,%edi
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    148f <medusaReceiveDataInternal+0x30f>
jmp    1313 <medusaReceiveDataInternal+0x193>
mov    -0xc(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x58(%rbp),%edx
call   1040 <medusaDataReadyTimed@plt>
cmp    $0x0,%eax
jle    1402 <medusaReceiveDataInternal+0x282>
mov    $0x241,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x241,%edx
call   1060 <memset@plt>
mov    -0xc(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    $0x240,%edx
call   1050 <medusaReceive@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jg     1387 <medusaReceiveDataInternal+0x207>
mov    $0x7,%edi
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    1402 <medusaReceiveDataInternal+0x282>
mov    -0x3c(%rbp),%eax
add    -0x40(%rbp),%eax
cmp    $0x240,%eax
jbe    13cd <medusaReceiveDataInternal+0x24d>
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
add    -0x40(%rbp),%ecx
add    $0x1,%ecx
mov    $0x7,%edi
lea    0xd14(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
add    -0x40(%rbp),%esi
add    $0x1,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    1313 <medusaReceiveDataInternal+0x193>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x1c(%rbp)
je     1464 <medusaReceiveDataInternal+0x2e4>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    145f <medusaReceiveDataInternal+0x2df>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    144c <medusaReceiveDataInternal+0x2cc>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    1451 <medusaReceiveDataInternal+0x2d1>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    141f <medusaReceiveDataInternal+0x29f>
jmp    1464 <medusaReceiveDataInternal+0x2e4>
mov    -0x3c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x7,%edi
lea    0xc91(%rip),%rsi
mov    $0x0,%al
call   1070 <writeError@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<medusaReceiveDataInternal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%r13
mov    %edi,%ebp
movl   $0x0,(%rsi)
mov    $0x241,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x241,%edx
call   1060 <memset@plt>
movslq %r14d,%rdx
imul   $0x431bde83,%rdx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x32,%rsi
add    %eax,%esi
imul   $0xf4240,%esi,%eax
sub    %eax,%edx
mov    %ebp,%edi
call   1040 <medusaDataReadyTimed@plt>
test   %eax,%eax
jle    1318 <medusaReceiveDataInternal+0x198>
lea    0xe0d(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x240,%edx
call   1050 <medusaReceive@plt>
test   %eax,%eax
js     1328 <medusaReceiveDataInternal+0x1a8>
mov    %eax,%r14d
mov    %r12d,0x8(%rsp)
mov    %r13,0x10(%rsp)
movslq %r15d,%rdx
imul   $0x431bde83,%rdx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x32,%rsi
add    %eax,%esi
imul   $0xf4240,%esi,%eax
sub    %eax,%edx
mov    %ebp,%edi
mov    %rsi,0x18(%rsp)
mov    %rdx,0x20(%rsp)
call   1040 <medusaDataReadyTimed@plt>
test   %eax,%eax
jle    136e <medusaReceiveDataInternal+0x1ee>
mov    %ebp,0xc(%rsp)
jmp    12a5 <medusaReceiveDataInternal+0x125>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %r14d,%rdi
add    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1080 <memcpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
mov    0x18(%rsp),%rsi
mov    0x20(%rsp),%rdx
call   1040 <medusaDataReadyTimed@plt>
mov    %r15d,%r14d
test   %eax,%eax
jle    1371 <medusaReceiveDataInternal+0x1f1>
mov    $0x241,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x241,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x240,%edx
call   1050 <medusaReceive@plt>
test   %eax,%eax
jle    1353 <medusaReceiveDataInternal+0x1d3>
mov    %eax,%r12d
mov    %eax,%r15d
add    %r14d,%r15d
cmp    $0x241,%r15d
jb     1270 <medusaReceiveDataInternal+0xf0>
lea    0x1(%r15),%ebp
mov    $0x7,%edi
lea    0xdce(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    0xc(%rsp),%ebp
call   10a0 <realloc@plt>
mov    %rax,%rbx
jmp    1270 <medusaReceiveDataInternal+0xf0>
je     1331 <medusaReceiveDataInternal+0x1b1>
lea    0xd4f(%rip),%rsi
mov    $0x3,%edi
jmp    133d <medusaReceiveDataInternal+0x1bd>
lea    0xced(%rip),%rsi
jmp    1338 <medusaReceiveDataInternal+0x1b8>
lea    0xd21(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    1568 <medusaReceiveDataInternal+0x3e8>
lea    0xd48(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%r15d
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
cmpl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%rbp
je     154b <medusaReceiveDataInternal+0x3cb>
test   %r15d,%r15d
jle    154b <medusaReceiveDataInternal+0x3cb>
mov    %r15d,%eax
cmp    $0x10,%r15d
jae    13a1 <medusaReceiveDataInternal+0x221>
xor    %ecx,%ecx
jmp    1589 <medusaReceiveDataInternal+0x409>
mov    %eax,%ecx
and    $0xfffffff0,%ecx
xor    %edx,%edx
pxor   %xmm0,%xmm0
jmp    13bd <medusaReceiveDataInternal+0x23d>
xchg   %ax,%ax
add    $0x10,%rdx
cmp    %rdx,%rcx
je     1546 <medusaReceiveDataInternal+0x3c6>
movq   (%rbx,%rdx,1),%xmm2
movdqa %xmm2,%xmm1
pcmpeqb %xmm0,%xmm1
movd   %xmm1,%esi
test   $0x1,%sil
je     13d8 <medusaReceiveDataInternal+0x258>
movb   $0x20,(%rbx,%rdx,1)
movdqa %xmm1,%xmm3
pslld  $0x8,%xmm3
movd   %xmm3,%esi
shr    $0x10,%esi
test   $0x1,%sil
je     13f3 <medusaReceiveDataInternal+0x273>
movb   $0x20,0x1(%rbx,%rdx,1)
pshuflw $0x55,%xmm2,%xmm3
pcmpeqb %xmm0,%xmm3
pextrw $0x2,%xmm3,%esi
test   $0x1,%sil
je     140c <medusaReceiveDataInternal+0x28c>
movb   $0x20,0x2(%rbx,%rdx,1)
movdqa %xmm1,%xmm3
psllq  $0x18,%xmm3
pextrw $0x3,%xmm3,%esi
test   $0x1,%sil
je     1425 <medusaReceiveDataInternal+0x2a5>
movb   $0x20,0x3(%rbx,%rdx,1)
pshufd $0x55,%xmm2,%xmm2
pcmpeqb %xmm0,%xmm2
pextrw $0x4,%xmm2,%esi
test   $0x1,%sil
je     143e <medusaReceiveDataInternal+0x2be>
movb   $0x20,0x4(%rbx,%rdx,1)
movdqa %xmm1,%xmm2
pslldq $0x5,%xmm2
pextrw $0x5,%xmm2,%esi
test   $0x1,%sil
je     1457 <medusaReceiveDataInternal+0x2d7>
movb   $0x20,0x5(%rbx,%rdx,1)
pextrw $0x3,%xmm1,%esi
test   $0x1,%sil
je     1467 <medusaReceiveDataInternal+0x2e7>
movb   $0x20,0x6(%rbx,%rdx,1)
pslldq $0x7,%xmm1
pextrw $0x7,%xmm1,%esi
test   $0x1,%sil
je     147c <medusaReceiveDataInternal+0x2fc>
movb   $0x20,0x7(%rbx,%rdx,1)
movq   0x8(%rbx,%rdx,1),%xmm2
movdqa %xmm2,%xmm1
pcmpeqb %xmm0,%xmm1
movd   %xmm1,%esi
test   $0x1,%sil
je     1499 <medusaReceiveDataInternal+0x319>
movb   $0x20,0x8(%rbx,%rdx,1)
movdqa %xmm1,%xmm3
pslld  $0x8,%xmm3
movd   %xmm3,%esi
shr    $0x10,%esi
test   $0x1,%sil
je     14b4 <medusaReceiveDataInternal+0x334>
movb   $0x20,0x9(%rbx,%rdx,1)
pshuflw $0x55,%xmm2,%xmm3
pcmpeqb %xmm0,%xmm3
pextrw $0x2,%xmm3,%esi
test   $0x1,%sil
je     14cd <medusaReceiveDataInternal+0x34d>
movb   $0x20,0xa(%rbx,%rdx,1)
movdqa %xmm1,%xmm3
psllq  $0x18,%xmm3
pextrw $0x3,%xmm3,%esi
test   $0x1,%sil
je     14e6 <medusaReceiveDataInternal+0x366>
movb   $0x20,0xb(%rbx,%rdx,1)
pshufd $0x55,%xmm2,%xmm2
pcmpeqb %xmm0,%xmm2
pextrw $0x4,%xmm2,%esi
test   $0x1,%sil
je     14ff <medusaReceiveDataInternal+0x37f>
movb   $0x20,0xc(%rbx,%rdx,1)
movdqa %xmm1,%xmm2
pslldq $0x5,%xmm2
pextrw $0x5,%xmm2,%esi
test   $0x1,%sil
je     1518 <medusaReceiveDataInternal+0x398>
movb   $0x20,0xd(%rbx,%rdx,1)
pextrw $0x3,%xmm1,%esi
test   $0x1,%sil
je     1528 <medusaReceiveDataInternal+0x3a8>
movb   $0x20,0xe(%rbx,%rdx,1)
pslldq $0x7,%xmm1
pextrw $0x7,%xmm1,%esi
test   $0x1,%sil
je     13b0 <medusaReceiveDataInternal+0x230>
movb   $0x20,0xf(%rbx,%rdx,1)
jmp    13b0 <medusaReceiveDataInternal+0x230>
cmp    %rax,%rcx
jne    1589 <medusaReceiveDataInternal+0x409>
lea    0xbb6(%rip),%rsi
mov    $0x7,%edi
mov    %r15d,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %r15d,0x0(%rbp)
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rax
je     154b <medusaReceiveDataInternal+0x3cb>
cmpb   $0x0,(%rbx,%rcx,1)
jne    1580 <medusaReceiveDataInternal+0x400>
movb   $0x20,(%rbx,%rcx,1)
jmp    1580 <medusaReceiveDataInternal+0x400>

LLVM IR (-O0):
@.str = [28 x i8] c"Data receive: Data waiting.\00"
@.str.1 = [61 x i8] c"Data receive: Socket indicated data present, but none found.\00"
@.str.2 = [23 x i8] c"Data receive: No data.\00"
@.str.3 = [50 x i8] c"Data receive: Failed to read from network socket.\00"
@.str.4 = [34 x i8] c"Data receive: No additional data.\00"
@.str.5 = [68 x i8] c"Additional data received. Increasing receive buffer %d bytes to %d.\00"
@.str.6 = [38 x i8] c"Formatted data received (size %d): %s\00"
define i8* @medusaReceiveDataInternal(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 576, i32* %12
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
%23 = load i32*, i32** %8
store i32 0, i32* %23
%24 = call i8* @malloc(i32 577)
store i8* %24, i8** %13
%25 = load i8*, i8** %13
%26 = call i32 @memset(i8* %25, i32 0, i32 577)
%27 = load i32, i32* %10
%28 = sdiv i32 %27, 1000000
store i32 %28, i32* %19
%29 = load i32, i32* %10
%30 = srem i32 %29, 1000000
store i32 %30, i32* %20
%31 = load i32, i32* %11
%32 = sdiv i32 %31, 1000000
store i32 %32, i32* %21
%33 = load i32, i32* %11
%34 = srem i32 %33, 1000000
store i32 %34, i32* %22
%35 = load i32, i32* %7
%36 = load i32, i32* %19
%37 = load i32, i32* %20
%38 = call i32 @medusaDataReadyTimed(i32 %35, i32 %36, i32 %37)
store i32 %38, i32* %18
%39 = load i32, i32* %18
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %53
41: ; preds = %5
%42 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%43 = load i32, i32* %7
%44 = load i8*, i8** %13
%45 = call i32 @medusaReceive(i32 %43, i8* %44, i32 576)
store i32 %45, i32* %15
%46 = load i32, i32* %15
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%50 = load i8*, i8** %13
%51 = call i32 @free(i8* %50)
store i8* null, i8** %6
br label %152
52: ; preds = %41
br label %64
53: ; preds = %5
%54 = load i32, i32* %18
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%58 = load i8*, i8** %13
%59 = call i32 @free(i8* %58)
store i8* null, i8** %6
br label %152
60: ; preds = %53
%61 = call i32 (i32, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%62 = load i8*, i8** %13
%63 = call i32 @free(i8* %62)
store i8* null, i8** %6
br label %152
64: ; preds = %52
br label %65
65: ; preds = %102, %64
%66 = load i32, i32* %7
%67 = load i32, i32* %21
%68 = load i32, i32* %22
%69 = call i32 @medusaDataReadyTimed(i32 %66, i32 %67, i32 %68)
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %115
71: ; preds = %65
%72 = call i8* @malloc(i32 577)
store i8* %72, i8** %14
%73 = load i8*, i8** %14
%74 = call i32 @memset(i8* %73, i32 0, i32 577)
%75 = load i32, i32* %7
%76 = load i8*, i8** %14
%77 = call i32 @medusaReceive(i32 %75, i8* %76, i32 576)
store i32 %77, i32* %16
%78 = load i32, i32* %16
%79 = icmp sle i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %71
%81 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%82 = load i8*, i8** %14
%83 = call i32 @free(i8* %82)
br label %115
84: ; preds = %71
%85 = load i32, i32* %15
%86 = load i32, i32* %16
%87 = add nsw i32 %85, %86
%88 = icmp ugt i32 %87, 576
br i1 %88, label %89, label %102
89: ; preds = %84
%90 = load i32, i32* %16
%91 = load i32, i32* %15
%92 = load i32, i32* %16
%93 = add nsw i32 %91, %92
%94 = add nsw i32 %93, 1
%95 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i32 %90, i32 %94)
%96 = load i8*, i8** %13
%97 = load i32, i32* %15
%98 = load i32, i32* %16
%99 = add nsw i32 %97, %98
%100 = add nsw i32 %99, 1
%101 = call i8* @realloc(i8* %96, i32 %100)
store i8* %101, i8** %13
br label %102
102: ; preds = %89, %84
%103 = load i8*, i8** %13
%104 = load i32, i32* %15
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
%107 = load i8*, i8** %14
%108 = load i32, i32* %16
%109 = call i32 @memcpy(i8* %106, i8* %107, i32 %108)
%110 = load i32, i32* %16
%111 = load i32, i32* %15
%112 = add nsw i32 %111, %110
store i32 %112, i32* %15
store i32 0, i32* %16
%113 = load i8*, i8** %14
%114 = call i32 @free(i8* %113)
br label %65
115: ; preds = %80, %65
%116 = load i8*, i8** %13
%117 = load i32, i32* %15
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %116, i64 %118
store i8 0, i8* %119
%120 = load i32, i32* %9
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %145
122: ; preds = %115
store i32 0, i32* %17
br label %123
123: ; preds = %141, %122
%124 = load i32, i32* %17
%125 = load i32, i32* %15
%126 = icmp slt i32 %124, %125
br i1 %126, label %127, label %144
127: ; preds = %123
%128 = load i8*, i8** %13
%129 = load i32, i32* %17
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %128, i64 %130
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %140
135: ; preds = %127
%136 = load i8*, i8** %13
%137 = load i32, i32* %17
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %136, i64 %138
store i8 32, i8* %139
br label %140
140: ; preds = %135, %127
br label %141
141: ; preds = %140
%142 = load i32, i32* %17
%143 = add nsw i32 %142, 1
store i32 %143, i32* %17
br label %123
144: ; preds = %123
br label %145
145: ; preds = %144, %115
%146 = load i32, i32* %15
%147 = load i8*, i8** %13
%148 = call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %146, i8* %147)
%149 = load i32, i32* %15
%150 = load i32*, i32** %8
store i32 %149, i32* %150
%151 = load i8*, i8** %13
store i8* %151, i8** %6
br label %152
152: ; preds = %145, %60, %56, %48
%153 = load i8*, i8** %6
ret i8* %153
}

LLVM IR (-O2):
@.str = [28 x i8] c"Data receive: Data waiting.\00"
@.str.1 = [61 x i8] c"Data receive: Socket indicated data present, but none found.\00"
@.str.2 = [23 x i8] c"Data receive: No data.\00"
@.str.3 = [50 x i8] c"Data receive: Failed to read from network socket.\00"
@.str.4 = [34 x i8] c"Data receive: No additional data.\00"
@.str.5 = [68 x i8] c"Additional data received. Increasing receive buffer %d bytes to %d.\00"
@.str.6 = [38 x i8] c"Formatted data received (size %d): %s\00"
define i8* @medusaReceiveDataInternal(i32 %0, i32* nocapture writeonly %1, i32 %2, i32 %3, i32 %4) {
store i32 0, i32* %1
%6 = tail call dereferenceable_or_null(577) i8* @malloc(i32 577)
%7 = tail call i32 @memset(i8* %6, i32 0, i32 577)
%8 = sdiv i32 %3, 1000000
%9 = srem i32 %3, 1000000
%10 = sdiv i32 %4, 1000000
%11 = srem i32 %4, 1000000
%12 = tail call i32 @medusaDataReadyTimed(i32 %0, i32 %8, i32 %9)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %5
%15 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @medusaReceive(i32 %0, i8* %6, i32 576)
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @medusaDataReadyTimed(i32 %0, i32 %10, i32 %11)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %32, label %57
21: ; preds = %14
%22 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @free(i8* %6)
br label %176
24: ; preds = %5
%25 = icmp eq i32 %12, 0
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @free(i8* %6)
br label %176
29: ; preds = %24
%30 = tail call i32 (i32, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @free(i8* %6)
br label %176
32: ; preds = %18, %49
%33 = phi i8* [ %50, %49 ], [ %6, %18 ]
%34 = phi i32 [ %43, %49 ], [ %16, %18 ]
%35 = tail call dereferenceable_or_null(577) i8* @malloc(i32 577)
%36 = tail call i32 @memset(i8* %35, i32 0, i32 577)
%37 = tail call i32 @medusaReceive(i32 %0, i8* %35, i32 576)
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%41 = tail call i32 @free(i8* %35)
br label %57
42: ; preds = %32
%43 = add nsw i32 %37, %34
%44 = icmp ugt i32 %43, 576
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = add nsw i32 %43, 1
%47 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %46)
%48 = tail call i8* @realloc(i8* %33, i32 %46)
br label %49
49: ; preds = %45, %42
%50 = phi i8* [ %48, %45 ], [ %33, %42 ]
%51 = sext i32 %34 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
%53 = tail call i32 @memcpy(i8* %52, i8* %35, i32 %37)
%54 = tail call i32 @free(i8* %35)
%55 = tail call i32 @medusaDataReadyTimed(i32 %0, i32 %10, i32 %11)
%56 = icmp sgt i32 %55, 0
br i1 %56, label %32, label %57
57: ; preds = %49, %18, %39
%58 = phi i32 [ %34, %39 ], [ %16, %18 ], [ %43, %49 ]
%59 = phi i8* [ %33, %39 ], [ %6, %18 ], [ %50, %49 ]
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %59, i64 %60
store i8 0, i8* %61
%62 = icmp ne i32 %2, 0
%63 = icmp sgt i32 %58, 0
%64 = select i1 %62, i1 %63, i1 false
br i1 %64, label %65, label %174
65: ; preds = %57
%66 = zext i32 %58 to i64
%67 = icmp ult i32 %58, 16
br i1 %67, label %163, label %68
68: ; preds = %65
%69 = and i64 %66, 4294967280
br label %70
70: ; preds = %158, %68
%71 = phi i64 [ 0, %68 ], [ %159, %158 ]
%72 = or i64 %71, 8
%73 = getelementptr inbounds i8, i8* %59, i64 %71
%74 = bitcast i8* %73 to <8 x i8>*
%75 = load <8 x i8>, <8 x i8>* %74
%76 = getelementptr inbounds i8, i8* %73, i64 8
%77 = bitcast i8* %76 to <8 x i8>*
%78 = load <8 x i8>, <8 x i8>* %77
%79 = icmp eq <8 x i8> %75, zeroinitializer
%80 = icmp eq <8 x i8> %78, zeroinitializer
%81 = extractelement <8 x i1> %79, i64 0
br i1 %81, label %82, label %84
82: ; preds = %70
%83 = getelementptr inbounds i8, i8* %59, i64 %71
store i8 32, i8* %83
br label %84
84: ; preds = %82, %70
%85 = extractelement <8 x i1> %79, i64 1
br i1 %85, label %86, label %89
86: ; preds = %84
%87 = or i64 %71, 1
%88 = getelementptr inbounds i8, i8* %59, i64 %87
store i8 32, i8* %88
br label %89
89: ; preds = %86, %84
%90 = extractelement <8 x i1> %79, i64 2
br i1 %90, label %91, label %94
91: ; preds = %89
%92 = or i64 %71, 2
%93 = getelementptr inbounds i8, i8* %59, i64 %92
store i8 32, i8* %93
br label %94
94: ; preds = %91, %89
%95 = extractelement <8 x i1> %79, i64 3
br i1 %95, label %96, label %99
96: ; preds = %94
%97 = or i64 %71, 3
%98 = getelementptr inbounds i8, i8* %59, i64 %97
store i8 32, i8* %98
br label %99
99: ; preds = %96, %94
%100 = extractelement <8 x i1> %79, i64 4
br i1 %100, label %101, label %104
101: ; preds = %99
%102 = or i64 %71, 4
%103 = getelementptr inbounds i8, i8* %59, i64 %102
store i8 32, i8* %103
br label %104
104: ; preds = %101, %99
%105 = extractelement <8 x i1> %79, i64 5
br i1 %105, label %106, label %109
106: ; preds = %104
%107 = or i64 %71, 5
%108 = getelementptr inbounds i8, i8* %59, i64 %107
store i8 32, i8* %108
br label %109
109: ; preds = %106, %104
%110 = extractelement <8 x i1> %79, i64 6
br i1 %110, label %111, label %114
111: ; preds = %109
%112 = or i64 %71, 6
%113 = getelementptr inbounds i8, i8* %59, i64 %112
store i8 32, i8* %113
br label %114
114: ; preds = %111, %109
%115 = extractelement <8 x i1> %79, i64 7
br i1 %115, label %116, label %119
116: ; preds = %114
%117 = or i64 %71, 7
%118 = getelementptr inbounds i8, i8* %59, i64 %117
store i8 32, i8* %118
br label %119
119: ; preds = %116, %114
%120 = extractelement <8 x i1> %80, i64 0
br i1 %120, label %121, label %123
121: ; preds = %119
%122 = getelementptr inbounds i8, i8* %59, i64 %72
store i8 32, i8* %122
br label %123
123: ; preds = %121, %119
%124 = extractelement <8 x i1> %80, i64 1
br i1 %124, label %125, label %128
125: ; preds = %123
%126 = or i64 %71, 9
%127 = getelementptr inbounds i8, i8* %59, i64 %126
store i8 32, i8* %127
br label %128
128: ; preds = %125, %123
%129 = extractelement <8 x i1> %80, i64 2
br i1 %129, label %130, label %133
130: ; preds = %128
%131 = or i64 %71, 10
%132 = getelementptr inbounds i8, i8* %59, i64 %131
store i8 32, i8* %132
br label %133
133: ; preds = %130, %128
%134 = extractelement <8 x i1> %80, i64 3
br i1 %134, label %135, label %138
135: ; preds = %133
%136 = or i64 %71, 11
%137 = getelementptr inbounds i8, i8* %59, i64 %136
store i8 32, i8* %137
br label %138
138: ; preds = %135, %133
%139 = extractelement <8 x i1> %80, i64 4
br i1 %139, label %140, label %143
140: ; preds = %138
%141 = or i64 %71, 12
%142 = getelementptr inbounds i8, i8* %59, i64 %141
store i8 32, i8* %142
br label %143
143: ; preds = %140, %138
%144 = extractelement <8 x i1> %80, i64 5
br i1 %144, label %145, label %148
145: ; preds = %143
%146 = or i64 %71, 13
%147 = getelementptr inbounds i8, i8* %59, i64 %146
store i8 32, i8* %147
br label %148
148: ; preds = %145, %143
%149 = extractelement <8 x i1> %80, i64 6
br i1 %149, label %150, label %153
150: ; preds = %148
%151 = or i64 %71, 14
%152 = getelementptr inbounds i8, i8* %59, i64 %151
store i8 32, i8* %152
br label %153
153: ; preds = %150, %148
%154 = extractelement <8 x i1> %80, i64 7
br i1 %154, label %155, label %158
155: ; preds = %153
%156 = or i64 %71, 15
%157 = getelementptr inbounds i8, i8* %59, i64 %156
store i8 32, i8* %157
br label %158
158: ; preds = %155, %153
%159 = add nuw i64 %71, 16
%160 = icmp eq i64 %159, %69
br i1 %160, label %161, label %70
161: ; preds = %158
%162 = icmp eq i64 %69, %66
br i1 %162, label %174, label %163
163: ; preds = %65, %161
%164 = phi i64 [ 0, %65 ], [ %69, %161 ]
br label %165
165: ; preds = %163, %171
%166 = phi i64 [ %172, %171 ], [ %164, %163 ]
%167 = getelementptr inbounds i8, i8* %59, i64 %166
%168 = load i8, i8* %167
%169 = icmp eq i8 %168, 0
br i1 %169, label %170, label %171
170: ; preds = %165
store i8 32, i8* %167
br label %171
171: ; preds = %165, %170
%172 = add nuw nsw i64 %166, 1
%173 = icmp eq i64 %172, %66
br i1 %173, label %174, label %165
174: ; preds = %171, %161, %57
%175 = tail call i32 (i32, i8*, ...) @writeError(i32 7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %58, i8* %59)
store i32 %58, i32* %1
br label %176
176: ; preds = %174, %29, %26, %21
%177 = phi i8* [ null, %21 ], [ %59, %174 ], [ null, %26 ], [ null, %29 ]
ret i8* %177
}