// File: /workspace/github_cpp_makefile_star2_O1/roberty65[P]bServer/frame/testServer/src/otEchod.cpp
// Function: main
int main(int argc, char **argv)
{
        int fd, efd;

        if (argc < 2) {
                fprintf(stderr, "Usage: %s address\n", argv[0]);
                return 0;
        }

        if ((fd = beyondy::XbsServer(argv[1], 1024, O_NONBLOCK)) < 0) {
                fprintf(stderr, "xbsServer failed: %m\n");
                return 1;
        }

        if ((efd = epoll_create(1024)) < 0) {
                fprintf(stderr, "epoll_create failed: %m\n");
                return 2;
        }

        int epoll_size = 1024;
        struct epoll_event *epoll_events = (struct epoll_event *)malloc(epoll_size * sizeof(struct epoll_event));
        if (epoll_events == NULL) {
                fprintf(stderr, "new epoll events failed: %m\n");
                return 3;
        }

        if (events_watch_add(efd, fd, EPOLLIN) < 0)
			return 4;

        while (true) {
                long wtime = 1000; /* 1s */
                int cnt = epoll_wait(efd, epoll_events, epoll_size, wtime);
                if (cnt > 0) for (int i = 0; i < cnt; ++i) {
                        struct epoll_event *ee = &epoll_events[i];
                        if (ee->data.fd == fd) {
                                int cfd = accept(fd, NULL, NULL);
                                if (cfd >= 0) events_watch_add(efd, cfd, EPOLLIN);
                        }
                        else if (handle_events(ee->data.fd, ee->events) < 0) {
							events_watch_del(efd, ee->data.fd);
							close(ee->data.fd);
                        }
                }
        }

        return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
cmpl $0x1, %edi
jle 0x154f
movq 0x8(%rsi), %rdi
movl $0x400, %esi            # imm = 0x400
movl $0x800, %edx            # imm = 0x800
movl $0x3, %ecx
callq 0x1a52
testl %eax, %eax
js 0x155b
movl %eax, %ebx
movl $0x400, %edi            # imm = 0x400
callq 0x1200
movl %eax, 0xc(%rsp)
testl %eax, %eax
js 0x1567
movl $0x3000, %edi           # imm = 0x3000
callq 0x1180
testq %rax, %rax
je 0x1573
movq %rax, %r14
movl 0xc(%rsp), %edi
movl %ebx, %esi
callq 0x157f
testl %eax, %eax
js 0x1538
leaq 0x10(%rsp), %r12
movl 0xc(%rsp), %edi
movq %r14, %rsi
movl $0x400, %edx            # imm = 0x400
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x10a0
testl %eax, %eax
jle 0x140c
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rbp
xorl %r15d, %r15d
movl 0x4(%r14,%r15), %r13d
cmpl %ebx, %r13d
jne 0x1459
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1060
testl %eax, %eax
js 0x1489
movl 0xc(%rsp), %edi
movl %eax, %esi
callq 0x157f
jmp 0x1489
movl $0x2000, %edx           # imm = 0x2000
movl %r13d, %edi
movq %r12, %rsi
callq 0x11b0
testq %rax, %rax
jle 0x1497
movq %r12, %rsi
movq %rax, %r12
movl %r13d, %edi
movq %rax, %rdx
callq 0x1070
cmpq %r12, %rax
jne 0x14bf
leaq 0x10(%rsp), %r12
addq $0xc, %r15
cmpq %r15, %rbp
jne 0x1433
jmp 0x140c
movq 0x3b42(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1c24(%rip), %rsi      # 0x30cc
leaq 0x1c00(%rip), %rax      # 0x30af
cmoveq %rax, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x11a0
jmp 0x14e0
movq 0x3b1a(%rip), %rcx      # 0x4fe0
movq (%rcx), %rdi
leaq 0x1bb2(%rip), %rsi      # 0x3082
movl %r13d, %edx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x11a0
movl 0x4(%r14,%r15), %r12d
movl $0x0, 0x10(%rsp)
movl %r12d, 0x14(%rsp)
movl 0xc(%rsp), %edi
movl $0x2, %esi
movl %r12d, %edx
leaq 0x10(%rsp), %rcx
callq 0x1190
testl %eax, %eax
js 0x151b
movl 0x4(%r14,%r15), %edi
callq 0x1210
jmp 0x1484
movq 0x3abe(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1bba(%rip), %rsi      # 0x30e6
movl %r12d, %edx
xorl %eax, %eax
callq 0x11a0
jmp 0x150c
movl $0x4, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rdi
callq 0x1278
xorl %eax, %eax
jmp 0x153d
callq 0x1260
movl $0x1, %eax
jmp 0x153d
callq 0x1248
movl $0x2, %eax
jmp 0x153d
callq 0x1230
movl $0x3, %eax
jmp 0x153d