// File: /workspace/github_c_makefile_star2_O2/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 0x3b13
movq %rsi, %r15
pushq $0x1
popq %rdi
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 0x34a8
cmpl $-0x1, %eax
je 0x3b3d
leaq -0xc0(%rbp), %rdi
callq 0x367c
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x2070
movl %eax, %r14d
addq $0x8, %r15
movq %r15, %rdi
movl %eax, %esi
callq 0x24b0
cmpl $-0x1, %eax
je 0x3b31
pushq $0x1
popq %rdx
movl -0x2c(%rbp), %edi
movl %r14d, %esi
callq 0x248c
pushq $0xa
popq %rsi
movl %r14d, %edi
callq 0x2210
movl -0x2c(%rbp), %edi
leaq -0x140(%rbp), %rsi
pushq $0xa
popq %rdx
pushq $-0x1
popq %rcx
callq 0x20f0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
imulq $0xc, %rax, %r15
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x3a42
movl -0x13c(%rbp,%r13), %r12d
cmpl %r14d, %r12d
jne 0x3a95
movl %r14d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2090
movl -0x2c(%rbp), %edi
movl %eax, %esi
pushq $0x1
popq %rdx
callq 0x248c
jmp 0x3b0a
movl %r12d, %edi
leaq -0x30(%rbp), %rsi
pushq $0x4
popq %rdx
movl $0x100, %ecx            # imm = 0x100
callq 0x20a0
testl %eax, %eax
je 0x3af1
leaq -0x88(%rbp), %rbx
movq %rbx, %rdi
callq 0x22b0
movl -0x30(%rbp), %edx
leaq -0xa0(%rbp), %rdi
movl %r12d, %esi
callq 0x44f3
movl -0x2c(%rbp), %edi
pushq $0x2
popq %rsi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x2280
movq %rbx, %rdi
callq 0x2170
leaq -0x60(%rbp), %rdi
callq 0x2030
jmp 0x3b0a
leaq 0x1a63(%rip), %rdi      # 0x555b
movl %r12d, %esi
xorl %eax, %eax
callq 0x2040
movl %r12d, %edi
callq 0x2380
addq $0xc, %r13
jmp 0x3a68
movq 0x44c6(%rip), %rax      # 0x7fe0
movq (%rax), %rcx
leaq 0x1a21(%rip), %rdi      # 0x5545
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
callq 0x2370
jmp 0x3b3d
leaq 0x1a1a(%rip), %rdi      # 0x5552
callq 0x2190
pushq $-0x1
popq %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop