// File: /workspace/github_cpp_makefile_star2_O2/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 0x14da
movq 0x8(%rsi), %rdi
pushq $0x3
popq %r15
movl $0x400, %esi            # imm = 0x400
movl $0x800, %edx            # imm = 0x800
movl %r15d, %ecx
callq 0x195a
testl %eax, %eax
js 0x14fa
movl %eax, %ebx
movl $0x400, %edi            # imm = 0x400
callq 0x1200
movl %eax, 0xc(%rsp)
testl %eax, %eax
js 0x1516
movl $0x3000, %edi           # imm = 0x3000
callq 0x1180
testq %rax, %rax
je 0x1532
movq %rax, %r14
movl 0xc(%rsp), %edi
movl %ebx, %esi
callq 0x154f
testl %eax, %eax
js 0x14c1
leaq 0x10(%rsp), %r13
movl 0xc(%rsp), %edi
movq %r14, %rsi
movl $0x400, %edx            # imm = 0x400
movl $0x3e8, %ecx            # imm = 0x3E8
callq 0x10a0
testl %eax, %eax
jle 0x139e
movl %eax, %eax
imulq $0xc, %rax, %rbp
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x139e
movl 0x4(%r14,%r15), %r12d
cmpl %ebx, %r12d
jne 0x13ec
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1060
testl %eax, %eax
js 0x141c
movl 0xc(%rsp), %edi
movl %eax, %esi
callq 0x154f
jmp 0x141c
movl $0x2000, %edx           # imm = 0x2000
movl %r12d, %edi
movq %r13, %rsi
callq 0x11b0
testq %rax, %rax
jle 0x1422
movq %r13, %rsi
movq %rax, %r13
movl %r12d, %edi
movq %rax, %rdx
callq 0x1070
cmpq %r13, %rax
jne 0x144a
leaq 0x10(%rsp), %r13
addq $0xc, %r15
jmp 0x13c1
movq 0x3bb7(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1c99(%rip), %rsi      # 0x30cc
leaq 0x1c75(%rip), %rax      # 0x30af
cmoveq %rax, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x11a0
jmp 0x146b
movq 0x3b8f(%rip), %rcx      # 0x4fe0
movq (%rcx), %rdi
leaq 0x1c27(%rip), %rsi      # 0x3082
movl %r12d, %edx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x11a0
movl 0x4(%r14,%r15), %r12d
andl $0x0, 0x10(%rsp)
movl %r12d, 0x14(%rsp)
movl 0xc(%rsp), %edi
pushq $0x2
popq %rsi
movl %r12d, %edx
leaq 0x10(%rsp), %r13
movq %r13, %rcx
callq 0x1190
testl %eax, %eax
js 0x14a4
movl 0x4(%r14,%r15), %edi
callq 0x1210
jmp 0x141c
movq 0x3b35(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1c31(%rip), %rsi      # 0x30e6
movl %r12d, %edx
xorl %eax, %eax
callq 0x11a0
jmp 0x1495
pushq $0x4
popq %r15
movl %r15d, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3aff(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0x1b16(%rip), %rsi      # 0x3004
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x11a0
jmp 0x14c5
movq 0x3adf(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1b0c(%rip), %rsi      # 0x3017
xorl %eax, %eax
callq 0x11a0
pushq $0x1
jmp 0x14c3
movq 0x3ac3(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1b06(%rip), %rsi      # 0x302d
xorl %eax, %eax
callq 0x11a0
pushq $0x2
jmp 0x14c3
movq 0x3aa7(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
leaq 0x1b03(%rip), %rsi      # 0x3046
xorl %eax, %eax
callq 0x11a0
jmp 0x14c5