// File: /workspace/github_c_makefile_star2_O3/VeeeectorPan[P]MyNetdisk/SourceFile/main.c
// Function: main
int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,5);
    factory_t fact;
    int epoll_fd = epoll_create(1);
    int ret = factory_init(&fact,atoi(argv[3]),atoi(argv[4]),epoll_fd);
    if(ret == -1) return -1;
    factory_start(&fact);

    int sfd = socket(AF_INET,SOCK_STREAM,0);
    ret = bind_sfd(argv + 1,sfd);
    ERROR_CHECK(ret,-1,"bind_sfd");

    add_fd_to_epoll(epoll_fd,sfd,EPOLLIN);
    struct epoll_event evs[10];

    listen(sfd,10);
    int ctl_num;
    while(1)
    {
        int readyNum = epoll_wait(epoll_fd,evs,10,-1);
        for(int i = 0; i < readyNum; ++i)
        {
            if(evs[i].data.fd == sfd)
            {
                int client_fd = accept(sfd,NULL,NULL);
                add_fd_to_epoll(epoll_fd,client_fd,EPOLLIN);
            }
            else
            {
                int client_fd = evs[i].data.fd;
                ret = recv(client_fd,&ctl_num,sizeof(int),MSG_WAITALL);
                if(ret == 0)
                {
                    printf("%d disconnected!\n",client_fd);
                    close(client_fd);
                    continue;
                }
                pthread_mutex_lock(&fact.mutex);
                que_push(&fact.que,client_fd,ctl_num);
                epoll_ctl(epoll_fd,EPOLL_CTL_DEL,client_fd,NULL);
                pthread_mutex_unlock(&fact.mutex);
                pthread_cond_signal(&fact.cond);
            }
        }
    }

    que_free(&fact.que);
    close(sfd);
    close(epoll_fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cmpl $0x5, %edi
jne 0x3c1b
movq %rsi, %r15
movl $0x1, %edi
callq 0x2360
movl %eax, %ebx
movq 0x18(%r15), %rdi
callq 0x2300
movl %eax, %r14d
movq 0x20(%r15), %rdi
callq 0x2300
leaq -0xc0(%rbp), %rdi
movl %r14d, %esi
movl %eax, %edx
movl %ebx, -0x2c(%rbp)
movl %ebx, %ecx
callq 0x3560
cmpl $-0x1, %eax
je 0x3c2e
leaq -0xc0(%rbp), %rdi
callq 0x374c
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, %r14d
addq $0x8, %r15
movq %r15, %rdi
movl %eax, %esi
callq 0x24e4
cmpl $-0x1, %eax
je 0x3c22
movl -0x2c(%rbp), %edi
movl %r14d, %esi
movl $0x1, %edx
callq 0x24bc
movl %r14d, %edi
movl $0xa, %esi
callq 0x2210
movl -0x2c(%rbp), %edi
leaq -0x140(%rbp), %rsi
movl $0xa, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20f0
testl %eax, %eax
jle 0x3b3c
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
movl -0x13c(%rbp,%r15), %r13d
cmpl %r14d, %r13d
jne 0x3b90
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2090
movl -0x2c(%rbp), %edi
movl %eax, %esi
movl $0x1, %edx
callq 0x24bc
jmp 0x3c09
movl $0x4, %edx
movl %r13d, %edi
leaq -0x30(%rbp), %rsi
movl $0x100, %ecx            # imm = 0x100
callq 0x20a0
testl %eax, %eax
je 0x3bf0
leaq -0x88(%rbp), %rbx
movq %rbx, %rdi
callq 0x22b0
movl -0x30(%rbp), %edx
leaq -0xa0(%rbp), %rdi
movl %r13d, %esi
callq 0x46f2
movl -0x2c(%rbp), %edi
movl $0x2, %esi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x2280
movq %rbx, %rdi
callq 0x2170
leaq -0x60(%rbp), %rdi
callq 0x2030
jmp 0x3c09
leaq 0x1964(%rip), %rdi      # 0x555b
movl %r13d, %esi
xorl %eax, %eax
callq 0x2040
movl %r13d, %edi
callq 0x2380
addq $0xc, %r15
cmpq %r15, %r12
jne 0x3b66
jmp 0x3b3c
callq 0x23a0
jmp 0x3c2e
leaq 0x1929(%rip), %rdi      # 0x5552
callq 0x2190
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)