// File: /workspace/github_c_makefile_star2_O0/yancanchen[P]mc-bloom-filter/mc_bloom_filter.c
// Function: drive_machine
void drive_machine(conn *c) {

    int exit = 0;
    int sfd, flags = 1;
    socklen_t addrlen;
    struct sockaddr_in addr;
    conn *newc;
    int res;

    while (!exit) {
        /* printf("state %d\n", c->state);*/
        switch(c->state) {
            case conn_listening:
                addrlen = sizeof(addr);
                if ((sfd = accept(c->sfd, (struct sockaddr*)(&addr), &addrlen)) == -1) {
                    if (errno == EAGAIN || errno == EWOULDBLOCK) {
                        exit = 1;
                        break;
                    } else {
                        perror("accept()");
                        exit = 1;
                        break;
                    }
                    break;
                }
                if ((flags = fcntl(sfd, F_GETFL, 0)) < 0 ||
                        fcntl(sfd, F_SETFL, flags | O_NONBLOCK) < 0) {
                    perror("setting O_NONBLOCK");
                    close(sfd);
                    break;
                }        
                newc = conn_new(sfd, conn_read, EV_READ | EV_PERSIST);
                if (!newc) {
                    if (my_srv.verbose > 0)
                        fprintf(stderr, "couldn't create new connection\n");
                    close(sfd);
                    break;
                }

                break;

            case conn_read:
                if (try_read_command(c)) {
                    continue;
                }
                if (try_read_network(c)) {
                    continue;
                }
                /* we have no command line and no data to read from network */
                if (!update_event(c, EV_READ | EV_PERSIST)) {
                    if (my_srv.verbose > 0)
                        fprintf(stderr, "Couldn't update event\n");
                    c->state = conn_closing;
                    break;
                }
                exit = 1;
                break;

            case conn_nread:
                /* we are reading rlbytes into ritem; */
                if (c->rbytes >= c->rlbytes) {
                    complete_nread(c);
                    c->rcurr += c->rlbytes;
                    c->rbytes -= c->rlbytes;
                    c->rlbytes = 0;
                    continue;
                }

                if (try_read_network(c)) {
                    continue;
                }

                /* we have no command line and no data to read from network */
                if (!update_event(c, EV_READ | EV_PERSIST)) {
                    if (my_srv.verbose > 0)
                        fprintf(stderr, "Couldn't update event\n");
                    c->state = conn_closing;
                    break;
                }
                exit = 1;
                break;

            case conn_swallow:
                /* we are reading sbytes and throwing them away */
                if (c->sbytes == 0) {
                    c->state = conn_read;
                    break;
                }

                /* first check if we have leftovers in the conn_read buffer */
                if (c->rbytes > 0) {
                    int tocopy = c->rbytes > c->sbytes ? c->sbytes : c->rbytes;
                    c->sbytes -= tocopy;
                    c->rcurr += tocopy;
                    c->rbytes -= tocopy;
                    break;
                }

                /*  now try reading from the socket */
                res = read(c->sfd, c->rbuf, c->rsize > c->sbytes ? c->sbytes : c->rsize);
                if (res > 0) {
                    stats.bytes_read += res;
                    c->sbytes -= res;
                    break;
                }
                if (res == 0) { /* end of stream */
                    c->state = conn_closing;
                    break;
                }
                if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                    if (!update_event(c, EV_READ | EV_PERSIST)) {
                        if (my_srv.verbose > 0)
                            fprintf(stderr, "Couldn't update event\n");
                        c->state = conn_closing;
                        break;
                    }
                    exit = 1;
                    break;
                }
                /* otherwise we have a real error, on which we close the connection */
                if (my_srv.verbose > 0)
                    fprintf(stderr, "Failed to read, and not due to blocking\n");
                c->state = conn_closing;
                break;

            case conn_write:
                /* we are writing wbytes bytes starting from wcurr */
                if (c->wbytes == 0) {
                    c->state = c->write_and_go;
                    if (c->state == conn_read)
                        set_cork(c, 0);
                    break;
                }
                res = write(c->sfd, c->wcurr, c->wbytes);
                if (res > 0) {
                    stats.bytes_written += res;
                    c->wcurr  += res;
                    c->wbytes -= res;
                    break;
                }
                if (res == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                    if (!update_event(c, EV_WRITE | EV_PERSIST)) {
                        if (my_srv.verbose > 0)
                            fprintf(stderr, "Couldn't update event\n");
                        c->state = conn_closing;
                        break;
                    }        
                    exit = 1;
                    break;
                }
                /* if res==0 or res==-1 and error is not EAGAIN or EWOULDBLOCK,
                   we have a real error, on which we close the connection */
                if (my_srv.verbose > 0)
                    fprintf(stderr, "Failed to write, and not due to blocking\n");
                c->state = conn_closing;
                break;

            case conn_closing:
                conn_close(c);
                exit = 1;
                break;
        }

    }

    return;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x1, 0x44(%rsp)
cmpl $0x0, 0x4c(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x55ec
jmp 0x5bfa
movq 0x50(%rsp), %rax
movl 0x4(%rax), %eax
movq %rax, 0x18(%rsp)
subq $0x5, %rax
ja 0x5bf5
movq 0x18(%rsp), %rax
leaq 0x1c3d(%rip), %rcx      # 0x724c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x10, 0x40(%rsp)
movq 0x50(%rsp), %rax
movl (%rax), %edi
leaq 0x30(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x23a0
movl %eax, 0x48(%rsp)
cmpl $-0x1, %eax
jne 0x5679
callq 0x2040
cmpl $0xb, (%rax)
je 0x5653
callq 0x2040
cmpl $0xb, (%rax)
jne 0x5660
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
leaq 0x221c(%rip), %rdi      # 0x7883
callq 0x2380
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
movl 0x48(%rsp), %edi
movl $0x3, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20b0
movl %eax, 0x44(%rsp)
cmpl $0x0, %eax
jl 0x56b3
movl 0x48(%rsp), %edi
movl 0x44(%rsp), %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x20b0
cmpl $0x0, %eax
jge 0x56cd
leaq 0x21d2(%rip), %rdi      # 0x788c
callq 0x2380
movl 0x48(%rsp), %edi
callq 0x21d0
jmp 0x5bf5
movl 0x48(%rsp), %edi
movl $0x1, %esi
movl $0x12, %edx
callq 0x3670
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x571c
cmpl $0x0, 0x4bb0(%rip)      # 0xa2a4
jle 0x570e
movq 0x48fb(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2198(%rip), %rsi      # 0x789f
movb $0x0, %al
callq 0x2250
movl 0x48(%rsp), %edi
callq 0x21d0
jmp 0x5bf5
jmp 0x5bf5
movq 0x50(%rsp), %rdi
callq 0x51c0
cmpl $0x0, %eax
je 0x5735
jmp 0x55d9
movq 0x50(%rsp), %rdi
callq 0x52d0
cmpl $0x0, %eax
je 0x5749
jmp 0x55d9
movq 0x50(%rsp), %rdi
movl $0x12, %esi
callq 0x5500
cmpl $0x0, %eax
jne 0x578f
cmpl $0x0, 0x4b40(%rip)      # 0xa2a4
jle 0x577e
movq 0x488b(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2148(%rip), %rsi      # 0x78bf
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
movq 0x50(%rsp), %rax
movl 0xa4(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0xa8(%rcx), %eax
jl 0x5814
movq 0x50(%rsp), %rdi
callq 0x49e0
movq 0x50(%rsp), %rax
movl 0xa8(%rax), %edx
movq 0x50(%rsp), %rax
movq 0x98(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x98(%rax)
movq 0x50(%rsp), %rax
movl 0xa8(%rax), %edx
movq 0x50(%rsp), %rax
movl 0xa4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xa4(%rax)
movq 0x50(%rsp), %rax
movl $0x0, 0xa8(%rax)
jmp 0x55d9
movq 0x50(%rsp), %rdi
callq 0x52d0
cmpl $0x0, %eax
je 0x5828
jmp 0x55d9
movq 0x50(%rsp), %rdi
movl $0x12, %esi
callq 0x5500
cmpl $0x0, %eax
jne 0x586e
cmpl $0x0, 0x4a61(%rip)      # 0xa2a4
jle 0x585d
movq 0x47ac(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2069(%rip), %rsi      # 0x78bf
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
movq 0x50(%rsp), %rax
cmpl $0x0, 0xf0(%rax)
jne 0x589a
movq 0x50(%rsp), %rax
movl $0x1, 0x4(%rax)
jmp 0x5bf5
movq 0x50(%rsp), %rax
cmpl $0x0, 0xa4(%rax)
jle 0x593c
movq 0x50(%rsp), %rax
movl 0xa4(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0xf0(%rcx), %eax
jle 0x58d5
movq 0x50(%rsp), %rax
movl 0xf0(%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0x58e4
movq 0x50(%rsp), %rax
movl 0xa4(%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %edx
movq 0x50(%rsp), %rax
movl 0xf0(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xf0(%rax)
movl 0x20(%rsp), %edx
movq 0x50(%rsp), %rax
movq 0x98(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x98(%rax)
movl 0x20(%rsp), %edx
movq 0x50(%rsp), %rax
movl 0xa4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xa4(%rax)
jmp 0x5bf5
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq 0x50(%rsp), %rax
movq 0x90(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %rax
movl 0xa0(%rax), %eax
movq 0x50(%rsp), %rcx
cmpl 0xf0(%rcx), %eax
jle 0x5980
movq 0x50(%rsp), %rax
movl 0xf0(%rax), %eax
movl %eax, (%rsp)
jmp 0x598e
movq 0x50(%rsp), %rax
movl 0xa0(%rax), %eax
movl %eax, (%rsp)
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edi
movl (%rsp), %eax
movslq %eax, %rdx
callq 0x2210
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jle 0x59dc
movslq 0x24(%rsp), %rax
addq 0x48cf(%rip), %rax      # 0xa288
movq %rax, 0x48c8(%rip)      # 0xa288
movl 0x24(%rsp), %edx
movq 0x50(%rsp), %rax
movl 0xf0(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xf0(%rax)
jmp 0x5bf5
cmpl $0x0, 0x24(%rsp)
jne 0x59f4
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
cmpl $-0x1, 0x24(%rsp)
jne 0x5a62
callq 0x2040
cmpl $0xb, (%rax)
je 0x5a0f
callq 0x2040
cmpl $0xb, (%rax)
jne 0x5a62
movq 0x50(%rsp), %rdi
movl $0x12, %esi
callq 0x5500
cmpl $0x0, %eax
jne 0x5a55
cmpl $0x0, 0x487a(%rip)      # 0xa2a4
jle 0x5a44
movq 0x45c5(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1e82(%rip), %rsi      # 0x78bf
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
cmpl $0x0, 0x483b(%rip)      # 0xa2a4
jle 0x5a83
movq 0x4586(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1e5a(%rip), %rsi      # 0x78d6
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movq 0x50(%rsp), %rax
cmpl $0x0, 0xc4(%rax)
jne 0x5ad1
movq 0x50(%rsp), %rax
movl 0xc8(%rax), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x50(%rsp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x5acc
movq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x35e0
jmp 0x5bf5
movq 0x50(%rsp), %rax
movl (%rax), %edi
movq 0x50(%rsp), %rax
movq 0xb8(%rax), %rsi
movq 0x50(%rsp), %rax
movslq 0xc4(%rax), %rdx
callq 0x20c0
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jle 0x5b4c
movslq 0x24(%rsp), %rax
addq 0x4784(%rip), %rax      # 0xa290
movq %rax, 0x477d(%rip)      # 0xa290
movl 0x24(%rsp), %edx
movq 0x50(%rsp), %rax
movq 0xb8(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0xb8(%rax)
movl 0x24(%rsp), %edx
movq 0x50(%rsp), %rax
movl 0xc4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc4(%rax)
jmp 0x5bf5
cmpl $-0x1, 0x24(%rsp)
jne 0x5bb4
callq 0x2040
cmpl $0xb, (%rax)
je 0x5b67
callq 0x2040
cmpl $0xb, (%rax)
jne 0x5bb4
movq 0x50(%rsp), %rdi
movl $0x14, %esi
callq 0x5500
cmpl $0x0, %eax
jne 0x5baa
cmpl $0x0, 0x4722(%rip)      # 0xa2a4
jle 0x5b9c
movq 0x446d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1d2a(%rip), %rsi      # 0x78bf
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movl $0x1, 0x4c(%rsp)
jmp 0x5bf5
cmpl $0x0, 0x46e9(%rip)      # 0xa2a4
jle 0x5bd5
movq 0x4434(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1d31(%rip), %rsi      # 0x78ff
movb $0x0, %al
callq 0x2250
movq 0x50(%rsp), %rax
movl $0x5, 0x4(%rax)
jmp 0x5bf5
movq 0x50(%rsp), %rdi
callq 0x3a30
movl $0x1, 0x4c(%rsp)
jmp 0x55d9
addq $0x58, %rsp
retq
nop