// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x18(%rsp)
testl %edx, %edx
jle 0x7487
movl %edx, %ebx
movq %rdi, %r15
xorb $0x1, %cl
movzbl %cl, %eax
leal (%rax,%rax,2), %eax
movl %eax, 0xc(%rsp)
xorl %r12d, %r12d
leaq 0x20(%rsp), %rbp
leaq 0x360f(%rip), %r14      # 0xa930
movl $0x1, %eax
movl %eax, %eax
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl 0x4(%r15), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x30(%rsp,%rax,8)
movq $0xa, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
incl %edi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbp, %r8
callq 0x41a0
testl %eax, %eax
je 0x73f4
cmpl $-0x1, %eax
jne 0x7404
callq 0x4040
movl $0x2, %r13d
cmpl $0x4, (%rax)
je 0x7459
leaq 0x3587(%rip), %rdi      # 0xa960
callq 0x4150
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl $0xfffffffd, 0x8(%rsp)  # imm = 0xFFFFFFFD
movl $0x1, %r13d
jmp 0x7459
movl 0x4(%r15), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0x30(%rsp,%rax,8), %rax
movl $0x2, %r13d
btq %rdi, %rax
jae 0x7459
movl %r12d, %esi
addq 0x18(%rsp), %rsi
movl %ebx, %eax
subl %r12d, %eax
movslq %eax, %rdx
xorl %ecx, %ecx
callq 0x40d0
testl %eax, %eax
js 0x7470
addl %eax, %r12d
jne 0x7454
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x747a
incl %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rsp), %r13d
movl %r13d, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
cmpl %ebx, %r12d
jl 0x7335
jmp 0x7493
movl $0xfffffffc, 0x8(%rsp)  # imm = 0xFFFFFFFC
jmp 0x73fc
xorl %r12d, %r12d
movl $0x1, 0x4(%rsp)
jmp 0x7459
xorl %r12d, %r12d
jmp 0x7493
movl 0x8(%rsp), %eax
movl %eax, %r12d
movl %r12d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq