// File: /workspace/github_c_makefile_star2_O3/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 0x2158
testb $0x4, %sil
jne 0x21a7
testl $0x2010, %esi           # imm = 0x2010
je 0x22aa
movl 0x14(%rbx), %esi
leaq 0x2234(%rip), %rdi      # 0x4378
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
callq 0x1c5b
jmp 0x2287
leaq 0x20(%rbx), %rdi
leaq 0x14(%rbx), %r14
movl 0x14(%rbx), %esi
callq 0x1f2d
testb %al, %al
je 0x225f
cmpb $0x0, 0x18(%rbx)
jne 0x2287
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x2287
movq 0x20(%rbx), %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %esi
testl %esi, %esi
je 0x2202
cmpl $0xa, %esi
je 0x21fe
incq %rdx
cmpq %rdx, %rax
jne 0x218d
jmp 0x2287
leaq 0x30(%rbx), %rdi
leaq 0x14(%rbx), %r14
movl 0x14(%rbx), %esi
callq 0x1fc0
testb %al, %al
je 0x226f
cmpq $0x0, 0x38(%rbx)
jne 0x2287
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x4f69(%rip), %edi      # 0x7148
movl 0x14(%rbx), %edx
movl $0x3, %esi
callq 0x10e0
cmpl $-0x1, %eax
je 0x227c
movb $0x1, 0x19(%rbx)
jmp 0x2287
movb $0x0, (%rcx,%rdx)
movq %rbx, %rdi
callq 0x2455
cmpb $0x1, 0x18(%rbx)
jne 0x2225
subl $0x1, 0x10(%rbx)
jae 0x2295
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x1030
cmpb $0x1, 0x19(%rbx)
jne 0x2287
cmpq $0x0, 0x38(%rbx)
je 0x2287
leaq 0xc(%rsp), %rcx
movl $0x5, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x4f01(%rip), %edi      # 0x7148
movl 0x14(%rbx), %edx
movl $0x3, %esi
callq 0x10e0
cmpl $-0x1, %eax
je 0x229d
movb $0x0, 0x19(%rbx)
jmp 0x2287
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13ee
jmp 0x2170
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1443
jmp 0x2287
movq %r14, %rdi
movq %rbx, %rsi
callq 0x146d
subl $0x1, 0x10(%rbx)
jae 0x2295
movq %rbx, %rdi
callq 0x1030
addq $0x18, %rsp
popq %rbx
popq %r14
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1418
jmp 0x2287
movq %rbx, %rdi
callq 0x1498