// File: /workspace/github_c_makefile_star2_O0/desion[P]terminal/src/connection.c
// Function: conn_new
conn *conn_new(int sfd, int init_state, int event_flags, struct event_base *base) {
    conn *c;
    if (freecurr > 0) {
        c = freeconns[--freecurr];
    } else {
        if (!(c = (conn *)malloc(sizeof(conn)))) {
            perror("malloc(conn)");
            return NULL;
        }

        c->rbuf = c->wbuf = 0;
        c->rbuf = (char *) malloc(DATA_BUFFER_SIZE);
        c->wbuf = (char *) malloc(DATA_BUFFER_SIZE);

        if (c->rbuf == 0 || c->wbuf == 0) {
            if (c->rbuf != 0) free(c->rbuf);
            if (c->wbuf != 0) free(c->wbuf);
            free(c);
            perror("malloc()");
            return NULL;
        }
        c->rsize = c->wsize = DATA_BUFFER_SIZE;
        c->rcurr = c->rbuf;

        STATS_LOCK(stats);
        stats.conn_structs++;
        STATS_UNLOCK(stats);
    }

    if (settings.verbose > 1) {
        if (init_state == conn_listening)
            fprintf(stderr, "<%d server listening\n", sfd);
        else
            fprintf(stderr, "<%d new client connection\n", sfd);
    }

    c->sfd = sfd;
    c->state = init_state;
    c->rbytes = c->wbytes = 0;
    c->wcurr = c->wbuf;
    c->write_and_go = conn_read;
    event_set(&c->event, sfd, event_flags, event_handler, (void *)c);
    event_base_set(base, &c->event);
    c->ev_flags = event_flags;
    if (event_add(&c->event, 0) == -1) {
        if (freecurr < freetotal) {
            freeconns[freecurr++] = c;
        } else {
            free (c->rbuf);
            free (c->wbuf);
            free (c);

            STATS_LOCK(stats);
            stats.conn_structs--;
            STATS_UNLOCK(stats);
        }
        return NULL;
    }

    STATS_LOCK(stats);
    stats.curr_conns++;
    STATS_UNLOCK(stats);
    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0x6e50(%rip), %rax      # 0xab8c
cmpl $0x0, (%rax)
jle 0x3d70
leaq 0x6e38(%rip), %rax      # 0xab80
movq (%rax), %rax
leaq 0x6e3a(%rip), %rcx      # 0xab8c
movl (%rcx), %ecx
addl $-0x1, %ecx
leaq 0x6e2e(%rip), %rdx      # 0xab8c
movl %ecx, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x3ece
movl $0xe8, %edi
callq 0x22e0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x3d9d
leaq 0x3441(%rip), %rdi      # 0x71cc
callq 0x23b0
movq $0x0, -0x8(%rbp)
jmp 0x40b4
movq -0x28(%rbp), %rax
movq $0x0, 0xa8(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x90(%rax)
movl $0x2000, %edi           # imm = 0x2000
callq 0x22e0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x90(%rax)
movl $0x2000, %edi           # imm = 0x2000
callq 0x22e0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x3e07
movq -0x28(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
jne 0x3e65
movq -0x28(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x3e25
movq -0x28(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x2030
movq -0x28(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0x3e43
movq -0x28(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
leaq 0x3386(%rip), %rdi      # 0x71d9
callq 0x23b0
movq $0x0, -0x8(%rbp)
jmp 0x40b4
movq -0x28(%rbp), %rax
movl $0x2000, 0xb8(%rax)     # imm = 0x2000
movq -0x28(%rbp), %rax
movl $0x2000, 0xa0(%rax)     # imm = 0x2000
movq -0x28(%rbp), %rax
movq 0x90(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x98(%rax)
leaq 0x6cf2(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x2490
leaq 0x6ce2(%rip), %rax      # 0xab90
movl 0x4(%rax), %ecx
addl $0x1, %ecx
leaq 0x6cd5(%rip), %rax      # 0xab90
movl %ecx, 0x4(%rax)
leaq 0x6ccb(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x22d0
leaq 0x6ba3(%rip), %rax      # 0xaa78
cmpl $0x1, 0x10(%rax)
jle 0x3f1b
cmpl $0x0, -0x10(%rbp)
jne 0x3efe
movq 0x6110(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0x32ed(%rip), %rsi      # 0x71e2
movb $0x0, %al
callq 0x2260
jmp 0x3f19
movq 0x60f3(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0x32e6(%rip), %rsi      # 0x71f8
movb $0x0, %al
callq 0x2260
jmp 0x3f1b
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0xbc(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0xa4(%rax)
movq -0x28(%rbp), %rax
movq 0xa8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0xb0(%rax)
movq -0x28(%rbp), %rax
movl $0x1, 0xc0(%rax)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
movl -0xc(%rbp), %esi
movl -0x14(%rbp), %eax
movq -0x28(%rbp), %r8
leaq 0x6b9(%rip), %rcx       # 0x4640
movswl %ax, %edx
callq 0x2380
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x2060
movl -0x14(%rbp), %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x88(%rax)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2250
cmpl $-0x1, %eax
jne 0x4077
leaq 0x6bba(%rip), %rax      # 0xab8c
movl (%rax), %eax
leaq 0x6bad(%rip), %rcx      # 0xab88
cmpl (%rcx), %eax
jge 0x400d
movq -0x28(%rbp), %rdx
leaq 0x6b96(%rip), %rax      # 0xab80
movq (%rax), %rax
leaq 0x6b98(%rip), %rcx      # 0xab8c
movl (%rcx), %ecx
movl %ecx, %edi
addl $0x1, %edi
leaq 0x6b8a(%rip), %rsi      # 0xab8c
movl %edi, (%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x406d
movq -0x28(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x2030
movq -0x28(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
leaq 0x6b53(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x2490
leaq 0x6b43(%rip), %rax      # 0xab90
movl 0x4(%rax), %ecx
addl $-0x1, %ecx
leaq 0x6b36(%rip), %rax      # 0xab90
movl %ecx, 0x4(%rax)
leaq 0x6b2c(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x22d0
movq $0x0, -0x8(%rbp)
jmp 0x40b4
leaq 0x6b12(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x2490
leaq 0x6b02(%rip), %rax      # 0xab90
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x6af6(%rip), %rax      # 0xab90
movl %ecx, (%rax)
leaq 0x6aed(%rip), %rdi      # 0xab90
addq $0x28, %rdi
callq 0x22d0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop