// File: /workspace/github_c_makefile_star2_O2/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 %rbx
subq $0x10, %rsp
movl %esi, %edx
movq %rdi, %rbx
incl 0x10(%rdi)
testb $0x1, %dl
jne 0x1a62
testb $0x4, %dl
jne 0x1aab
testw $0x2010, %dx            # imm = 0x2010
je 0x1bb3
movl 0x14(%rbx), %esi
leaq 0x192a(%rip), %rdi      # 0x3378
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
callq 0x14b8
jmp 0x1b2b
leaq 0x20(%rbx), %rdi
movl 0x14(%rbx), %esi
callq 0x17b0
testb %al, %al
je 0x1b3f
movq %rbx, %rdi
callq 0x1df6
testb %al, %al
je 0x1b2b
movq %rbx, %rdi
callq 0x1e2a
cmpb $0x1, 0x18(%rbx)
jne 0x1af5
subl $0x1, 0x10(%rbx)
jae 0x1b39
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
jmp 0x1030
leaq 0x30(%rbx), %rdi
movl 0x14(%rbx), %esi
callq 0x183e
testb %al, %al
je 0x1b67
cmpq $0x0, 0x38(%rbx)
jne 0x1b2b
leaq 0x4(%rsp), %rcx
movl $0x1, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x466d(%rip), %edi      # 0x6148
movl 0x14(%rbx), %edx
pushq $0x3
popq %rsi
callq 0x10e0
cmpl $-0x1, %eax
je 0x1b7d
movb $0x1, 0x19(%rbx)
jmp 0x1b2b
cmpb $0x1, 0x19(%rbx)
jne 0x1b2b
cmpq $0x0, 0x38(%rbx)
je 0x1b2b
leaq 0x4(%rsp), %rcx
movl $0x5, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x4631(%rip), %edi      # 0x6148
movl 0x14(%rbx), %edx
pushq $0x3
popq %rsi
callq 0x10e0
cmpl $-0x1, %eax
je 0x1b93
movb $0x0, 0x19(%rbx)
subl $0x1, 0x10(%rbx)
jae 0x1b39
movq %rbx, %rdi
callq 0x1030
addq $0x10, %rsp
popq %rbx
retq
movq 0x44b2(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %edx
leaq 0x17a2(%rip), %rsi      # 0x32f5
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
callq 0x14b8
jmp 0x1a76
movq 0x448a(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %edx
leaq 0x17a5(%rip), %rsi      # 0x3320
jmp 0x1ba7
movq 0x4474(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %edx
leaq 0x17b9(%rip), %rsi      # 0x334a
jmp 0x1ba7
movq 0x445e(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %edx
leaq 0x1483(%rip), %rsi      # 0x302a
xorl %eax, %eax
callq 0x1130
jmp 0x1a55
movq 0x443e(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %ecx
leaq 0x17d6(%rip), %rsi      # 0x339d
xorl %eax, %eax
callq 0x1130
pushq $0x41
popq %rdi
callq 0x11f0