// File: /workspace/github_c_makefile_star2_O1/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 0x3c57
movq %rsi, %r15
movl $0x1, %edi
callq 0x2350
movl %eax, %ebx
movq 0x18(%r15), %rdi
callq 0x22f0
movl %eax, %r14d
movq 0x20(%r15), %rdi
callq 0x22f0
leaq -0xc0(%rbp), %rdi
movl %r14d, %esi
movl %eax, %edx
movl %ebx, -0x2c(%rbp)
movl %ebx, %ecx
callq 0x35a8
cmpl $-0x1, %eax
je 0x3c6a
leaq -0xc0(%rbp), %rdi
callq 0x3788
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, %r14d
addq $0x8, %r15
movq %r15, %rdi
movl %eax, %esi
callq 0x24d4
cmpl $-0x1, %eax
je 0x3c5e
movl -0x2c(%rbp), %edi
movl %r14d, %esi
movl $0x1, %edx
callq 0x24ac
movl %r14d, %edi
movl $0xa, %esi
callq 0x2200
movl -0x2c(%rbp), %edi
leaq -0x140(%rbp), %rsi
movl $0xa, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20f0
testl %eax, %eax
jle 0x3b78
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
movl -0x13c(%rbp,%r15), %r13d
cmpl %r14d, %r13d
jne 0x3bcc
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2090
movl -0x2c(%rbp), %edi
movl %eax, %esi
movl $0x1, %edx
callq 0x24ac
jmp 0x3c45
movl $0x4, %edx
movl %r13d, %edi
leaq -0x30(%rbp), %rsi
movl $0x100, %ecx            # imm = 0x100
callq 0x20a0
testl %eax, %eax
je 0x3c2c
leaq -0x88(%rbp), %rbx
movq %rbx, %rdi
callq 0x22a0
movl -0x30(%rbp), %edx
leaq -0xa0(%rbp), %rdi
movl %r13d, %esi
callq 0x4736
movl -0x2c(%rbp), %edi
movl $0x2, %esi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x2270
movq %rbx, %rdi
callq 0x2160
leaq -0x60(%rbp), %rdi
callq 0x2030
jmp 0x3c45
leaq 0x1928(%rip), %rdi      # 0x555b
movl %r13d, %esi
xorl %eax, %eax
callq 0x2040
movl %r13d, %edi
callq 0x2370
addq $0xc, %r15
cmpq %r15, %r12
jne 0x3ba2
jmp 0x3b78
callq 0x2390
jmp 0x3c6a
leaq 0x18ed(%rip), %rdi      # 0x5552
callq 0x2180
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)