// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x90(%rcx), %rax
je 0x4964
movq -0x10(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
je 0x494e
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0xa4(%rax), %rdx
callq 0x2360
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
jmp 0x4966
movq -0x10(%rbp), %rax
movl 0xa4(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jl 0x4a33
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %eax
shll %eax
movslq %eax, %rsi
callq 0x2330
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4a07
leaq 0x60c7(%rip), %rax      # 0xaa78
cmpl $0x0, 0x10(%rax)
jle 0x49cf
movq 0x563a(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x293b(%rip), %rsi      # 0x7303
movb $0x0, %al
callq 0x2260
movq -0x10(%rbp), %rax
movl $0x0, 0xa4(%rax)
movq -0x10(%rbp), %rdi
leaq 0x293a(%rip), %rsi      # 0x7322
callq 0x5270
movq -0x10(%rbp), %rax
movl $0x3, 0xc0(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x4af9
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %ecx
shll %ecx
movl %ecx, 0xa0(%rax)
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xa4(%rcx), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0xa4(%rax), %rax
addq %rax, %rsi
movslq -0x24(%rbp), %rdx
callq 0x21f0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x4aa4
movl $0x1, -0x14(%rbp)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xa4(%rax), %ecx
movl %ecx, 0xa4(%rax)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x4aa2
jmp 0x4966
jmp 0x4af3
cmpl $0x0, -0x18(%rbp)
jne 0x4abe
movq -0x10(%rbp), %rax
movl $0x3, 0x4(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x4af9
cmpl $-0x1, -0x18(%rbp)
jne 0x4aee
callq 0x2040
cmpl $0xb, (%rax)
je 0x4ad8
callq 0x2040
cmpl $0xb, (%rax)
jne 0x4ada
jmp 0x4af3
movq -0x10(%rbp), %rax
movl $0x3, 0x4(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x4af9
jmp 0x4966
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)