// File: mikeakohn[P]cloudtari/build/../src/Network.cxx
// Function: Network::net_recv(unsigned char*, int, bool)
int Network::net_recv(uint8_t *buffer, int length, bool wait_for_full_buffer)
{
  struct timeval tv;
  fd_set readset;
  int empty_count = 0;

  int bytes_received = 0;

  while (bytes_received < length)
  {
    FD_ZERO(&readset);
    FD_SET(client, &readset);

    tv.tv_sec = 10;
    tv.tv_usec = 0;

    int n = select(client + 1, &readset, NULL, NULL, &tv);

    if (n == -1)
    {
      if (errno == EINTR) { continue; }

      perror("Problem with select in net_recv");
      return -1;
    }

    if (n == 0) { return -3; }

    if (!FD_ISSET(client, &readset)) { continue; }

    n = recv(client, buffer + bytes_received, length - bytes_received, 0);
    if (n < 0) { return -4; }

    bytes_received += n;

    if (bytes_received == 0)
    {
      empty_count++;

      if (empty_count == 1) { continue; }
    }

    if (!wait_for_full_buffer) { break; }
  }

  return bytes_received;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x0, -0xb4(%rbp)
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x9fbd
jmp 0x9dbd
leaq -0xb0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpq $0x10, %rax
jae 0x9e07
movq -0xc8(%rbp), %rax
movl -0xbc(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x9dd5
jmp 0x9e09
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xd8(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, -0xe0(%rbp)
movl 0x4(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xe0(%rbp), %rdx
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movslq %ecx, %rcx
orq -0xb0(%rbp,%rcx,8), %rdx
movq %rdx, -0xb0(%rbp,%rcx,8)
movq $0xa, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
movl 0x4(%rax), %edi
addl $0x1, %edi
leaq -0xb0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r8
movq %rcx, %rdx
callq 0x4240
movl %eax, -0xcc(%rbp)
cmpl $-0x1, -0xcc(%rbp)
jne 0x9ec4
callq 0x4040
cmpl $0x4, (%rax)
jne 0x9eac
jmp 0x9dac
leaq 0x5ad6(%rip), %rdi      # 0xf989
callq 0x4200
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9fc6
cmpl $0x0, -0xcc(%rbp)
jne 0x9ed9
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x9fc6
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movslq %ecx, %rcx
movq -0xb0(%rbp,%rcx,8), %rcx
movq %rcx, -0xe8(%rbp)
movl 0x4(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xe8(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x9f33
jmp 0x9dac
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x18(%rbp), %rsi
movslq -0xb8(%rbp), %rax
addq %rax, %rsi
movl -0x1c(%rbp), %eax
subl -0xb8(%rbp), %eax
movslq %eax, %rdx
xorl %ecx, %ecx
callq 0x4100
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jge 0x9f76
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x9fc6
movl -0xcc(%rbp), %eax
addl -0xb8(%rbp), %eax
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
jne 0x9fb0
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
cmpl $0x1, -0xb4(%rbp)
jne 0x9fae
jmp 0x9dac
jmp 0x9fb0
testb $0x1, -0x1d(%rbp)
jne 0x9fb8
jmp 0x9fbd
jmp 0x9dac
movl -0xb8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)