// File: /workspace/github_c_makefile_star2_O1/desion[P]terminal/src/network.c
// Function: try_read_network
int try_read_network(conn *c) {
    int gotdata = 0;
    int res;

    if (c->rcurr != c->rbuf) {
        if (c->rbytes != 0) /* otherwise there's nothing to copy */
            memmove(c->rbuf, c->rcurr, c->rbytes);
        c->rcurr = c->rbuf;
    }

    while (1) {
        if (c->rbytes >= c->rsize) {
            char *new_rbuf = (char *)realloc(c->rbuf, c->rsize*2);
            if (!new_rbuf) {
                if (settings.verbose > 0)
                    fprintf(stderr, "Couldn't realloc input buffer\n");
                c->rbytes = 0; /* ignore what we read */
                out_string(c, "SERVER_ERROR out of memory");
                c->write_and_go = conn_closing;
                return 1;
            }
            c->rcurr  = c->rbuf = new_rbuf;
            c->rsize *= 2;
        }
        int avail = c->rsize - c->rbytes;
        res = read(c->sfd, c->rbuf + c->rbytes, avail);
        if (res > 0) {
            gotdata = 1;
            c->rbytes += res;
            if (res == avail) {
                continue;
            } else {
                break;
            }
        }
        if (res == 0) {
            /* connection closed */
            c->state = conn_closing;
            return 1;
        }

        if (res == -1) {
            if (errno == EAGAIN || errno == EWOULDBLOCK) break;
            else {
                c->state = conn_closing;
                return 1;
            }
        }
    }
    return gotdata;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x90(%rdi), %rdi
movq 0x98(%rbx), %rsi
cmpq %rdi, %rsi
je 0x3ce6
movslq 0xa4(%rbx), %rdx
testq %rdx, %rdx
je 0x3cd8
callq 0x2340
movq 0x90(%rbx), %rax
movq %rax, 0x98(%rbx)
xorl %ebp, %ebp
leaq 0x1da5(%rip), %r12      # 0x5a94
leaq 0x5572(%rip), %r13      # 0x9268
leaq 0x1e31(%rip), %r14      # 0x5b2e
movslq 0xa0(%rbx), %rsi
cmpl %esi, 0xa4(%rbx)
jl 0x3d6c
movq 0x90(%rbx), %rdi
addq %rsi, %rsi
callq 0x2310
movq %rax, %r15
testq %rax, %rax
je 0x3d39
movq %r15, 0x90(%rbx)
movq %r15, 0x98(%rbx)
shll 0xa0(%rbx)
jmp 0x3d63
cmpl $0x0, 0x10(%r13)
jg 0x3e01
movl $0x0, 0xa4(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x432c
movl $0x3, 0xc0(%rbx)
testq %r15, %r15
je 0x3e0b
movslq 0xa0(%rbx), %r15
movslq 0xa4(%rbx), %rsi
subq %rsi, %r15
movl (%rbx), %edi
addq 0x90(%rbx), %rsi
movq %r15, %rdx
callq 0x21d0
movq %rax, %rcx
testl %ecx, %ecx
jle 0x3db6
addl %ecx, 0xa4(%rbx)
xorl %eax, %eax
cmpl %ecx, %r15d
sete %al
xorl $0x3, %eax
movl $0x1, %ebp
movl %eax, %ecx
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
cmpl $-0x1, %ecx
je 0x3dd8
xorl %eax, %eax
testl %ecx, %ecx
jne 0x3df6
movl $0x3, 0x4(%rbx)
movl $0x1, %eax
movl %eax, %ecx
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
callq 0x2040
movq %rax, %rcx
movl $0x3, %eax
cmpl $0xb, (%rcx)
je 0x3df6
movl $0x3, 0x4(%rbx)
movl $0x1, %eax
movl %eax, %ecx
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
callq 0x254c
jmp 0x3d44
movl $0x1, %eax
jmp 0x3e14
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq