// File: /workspace/github_c_makefile_star2_O1/panux[P]linit/src/linitd.c
// Function: handle_conn
void handle_conn(struct conn *c, uint32_t events) {
    ref(c); //make sure that c isn't freed in the middle
    if(EPOLL_MODE(events, EPOLLIN)) {
        if(!readBuf(&c->rx, c->fd)) {
            fprintf(stderr, "[ERROR] Failed to read from connection %d\n", c->fd);
            close_conn(c);
        }
        if(conn_has_cmd(c)) {
            handle_scmd(c);
            if(c->closed) { //command closed connection
                deref(c);
                return;
            }
            if(c->txoff && (c->tx.len > 0)) {  //tx buffer was just populated
                //enable write in epoll
                struct epoll_event ev = {.events = EPOLLIN | EPOLLOUT, .data = {.ptr = &c->e}};
                if(epoll_ctl(epollfd, EPOLL_CTL_MOD, c->fd, &ev) == -1) {   //failed to enable - close and forget
                    fprintf(stderr, "[ERROR] Failed to enable writing on conn %d\n", c->fd);
                    close_conn(c);
                } else {
                    c->txoff = false;
                }
            }
        }
    } else if(EPOLL_MODE(events, EPOLLOUT)) {   //available for writing
        if(!writeBuf(&c->tx, c->fd)) {
            fprintf(stderr, "[ERROR] Failed to write to connection %d\n", c->fd);
            close_conn(c);
        } else {
            if(c->tx.len == 0) {    //write done - disable it in epoll
                struct epoll_event ev = {.events = EPOLLIN, .data = {.ptr = &c->e}};
                if(epoll_ctl(epollfd, EPOLL_CTL_MOD, c->fd, &ev) == -1) {   //failed to disable - close and forget
                    fprintf(stderr, "[ERROR] Failed to disable writing on conn %d\n", c->fd);
                    close_conn(c);
                } else {
                    c->txoff = true;
                }
            }
        }
    } else if(EPOLL_MODE(events, EPOLLRDHUP) || EPOLL_MODE(events, EPOLLHUP)) {
        printf("[INFO] Connection %d closed by peer\n", c->fd);
        close_conn(c);
    } else {
        fprintf(stderr, "[FATAL] Unrecognized epoll event %d on fd %d\n", events, c->fd);
        exit(65);
    }
    deref(c);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
incl 0x10(%rdi)
testb $0x1, %sil
jne 0x21d9
testb $0x4, %sil
jne 0x2251
testl $0x2010, %esi           # imm = 0x2010
je 0x22e4
movl 0x14(%rbx), %esi
leaq 0x21cf(%rip), %rdi      # 0x4394
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
callq 0x1c93
jmp 0x2297
leaq 0x20(%rbx), %rdi
leaq 0x14(%rbx), %r14
movl 0x14(%rbx), %esi
callq 0x1f8a
testb %al, %al
je 0x22ad
movq %rbx, %rdi
callq 0x246b
testb %al, %al
je 0x2297
movq %rbx, %rdi
callq 0x24a4
cmpb $0x1, 0x18(%rbx)
je 0x2297
cmpb $0x1, 0x19(%rbx)
jne 0x2297
cmpq $0x0, 0x38(%rbx)
je 0x2297
leaq 0xc(%rsp), %rcx
movl $0x5, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x4f1b(%rip), %edi      # 0x7150
movl 0x14(%rbx), %edx
movl $0x3, %esi
callq 0x10f0
cmpl $-0x1, %eax
je 0x22d7
movb $0x0, 0x19(%rbx)
jmp 0x2297
leaq 0x30(%rbx), %rdi
leaq 0x14(%rbx), %r14
movl 0x14(%rbx), %esi
callq 0x2029
testb %al, %al
je 0x22bd
cmpq $0x0, 0x38(%rbx)
jne 0x2297
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x4ecf(%rip), %edi      # 0x7150
movl 0x14(%rbx), %edx
movl $0x3, %esi
callq 0x10f0
cmpl $-0x1, %eax
je 0x22ca
movb $0x1, 0x19(%rbx)
subl $0x1, 0x10(%rbx)
jae 0x22a5
movq %rbx, %rdi
callq 0x1030
addq $0x18, %rsp
popq %rbx
popq %r14
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13fe
jmp 0x21f1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1453
jmp 0x2297
movq %r14, %rdi
movq %rbx, %rsi
callq 0x147d
jmp 0x2297
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1428
jmp 0x2297
movq %rbx, %rdi
callq 0x14a8