// File: /workspace/github_c_makefile_star2_O0/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
subq $0x150, %rsp            # imm = 0x150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
je 0x44a3
movq 0x4b5a(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
leaq 0x30be(%rip), %rsi      # 0x754e
movb $0x0, %al
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4716
movl $0x1, %edi
callq 0x2370
movl %eax, -0xa4(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2310
movl %eax, -0x150(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2310
movl -0x150(%rbp), %esi
movl %eax, %edx
movl -0xa4(%rbp), %ecx
leaq -0xa0(%rbp), %rdi
callq 0x3d00
movl %eax, -0xa8(%rbp)
cmpl $-0x1, -0xa8(%rbp)
jne 0x4508
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4716
leaq -0xa0(%rbp), %rdi
callq 0x3f50
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2080
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl -0xac(%rbp), %esi
callq 0x24d0
movl %eax, -0xa8(%rbp)
cmpl $-0x1, -0xa8(%rbp)
jne 0x4565
leaq 0x3007(%rip), %rdi      # 0x755b
callq 0x2190
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4716
movl -0xa4(%rbp), %edi
movl -0xac(%rbp), %esi
movl $0x1, %edx
callq 0x2490
movl -0xac(%rbp), %edi
movl $0xa, %esi
callq 0x2210
movl -0xa4(%rbp), %edi
leaq -0x130(%rbp), %rsi
movl $0xa, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x2100
movl %eax, -0x138(%rbp)
movl $0x0, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
cmpl -0x138(%rbp), %eax
jge 0x4711
movslq -0x13c(%rbp), %rcx
leaq -0x130(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0xac(%rbp), %eax
jne 0x462b
movl -0xac(%rbp), %edi
movq $0x0, -0x148(%rbp)
movq -0x148(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x20a0
movl %eax, -0x140(%rbp)
movl -0xa4(%rbp), %edi
movl -0x140(%rbp), %esi
movl $0x1, %edx
callq 0x2490
jmp 0x46fb
movslq -0x13c(%rbp), %rcx
leaq -0x130(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x14c(%rbp)
movl -0x14c(%rbp), %edi
leaq -0x134(%rbp), %rsi
movl $0x4, %edx
movl $0x100, %ecx            # imm = 0x100
callq 0x20b0
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xa8(%rbp)
jne 0x4695
movl -0x14c(%rbp), %esi
leaq 0x2ee3(%rip), %rdi      # 0x7564
movb $0x0, %al
callq 0x2040
movl -0x14c(%rbp), %edi
callq 0x2380
jmp 0x46fd
leaq -0xa0(%rbp), %rdi
addq $0x38, %rdi
callq 0x22c0
leaq -0xa0(%rbp), %rdi
addq $0x20, %rdi
movl -0x14c(%rbp), %esi
movl -0x134(%rbp), %edx
callq 0x5b00
movl -0xa4(%rbp), %edi
movl -0x14c(%rbp), %edx
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x2280
leaq -0xa0(%rbp), %rdi
addq $0x38, %rdi
callq 0x2170
leaq -0xa0(%rbp), %rdi
addq $0x60, %rdi
callq 0x2030
jmp 0x46fd
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x45b7
jmp 0x458b
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)