// File: lega911[P]ijson/src/server.cpp
// Function: Server::_listen()
int Server::_listen() {
    _fd = socket(AF_INET, SOCK_STREAM, 0);
    if(_fd < 0) THROW("Error opening socket");

    int opt = 1;
    if(setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) THROW("setsockopt");

    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr(host.as_string().c_str());
    serv_addr.sin_port = htons(port);
    int r = bind(_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    if(r < 0) {
        if(this->log & 1) std::cout << "Port is busy\n";
        return -1;
    }

    if(listen(_fd, 64) < 0) THROW("ERROR on listen");
    if(this->log & 8) std::cout << ltime() << "Inverted Json " << ijson_version << " started on " << host.as_string() << ":" << port << std::endl;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x190b0
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, (%rax)
jge 0x27734
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
leaq 0x11ba4(%rip), %rsi     # 0x39287
leaq 0x11b5c(%rip), %rdx     # 0x39246
leaq 0x11bab(%rip), %r8      # 0x3929c
movl $0x24, %ecx
callq 0x22ba0
jmp 0x276fd
movq -0x88(%rbp), %rdi
leaq 0x1f5f5(%rip), %rsi     # 0x46d00
leaq -0x4602(%rip), %rdx     # 0x23110
callq 0x19480
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x19210
jmp 0x27a12
movq -0x80(%rbp), %rax
movl $0x1, -0x20(%rbp)
movl (%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x20(%rbp), %rcx
movl $0x4, %r8d
callq 0x194b0
cmpl $0x0, %eax
jge 0x277ce
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x90(%rbp)
leaq 0x11b35(%rip), %rsi     # 0x392b2
leaq 0x11ac2(%rip), %rdx     # 0x39246
leaq 0x11b11(%rip), %r8      # 0x3929c
movl $0x27, %ecx
callq 0x22ba0
jmp 0x27797
movq -0x90(%rbp), %rdi
leaq 0x1f55b(%rip), %rsi     # 0x46d00
leaq -0x469c(%rip), %rdx     # 0x23110
callq 0x19480
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x19210
jmp 0x27a12
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x191b0
movq -0x80(%rbp), %rsi
movw $0x2, -0x30(%rbp)
addq $0x10, %rsi
leaq -0x50(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f340
leaq -0x50(%rbp), %rdi
callq 0x19130
movq %rax, %rdi
callq 0x192f0
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x191e0
movq -0x80(%rbp), %rax
movl 0x24(%rax), %eax
movzwl %ax, %edi
callq 0x19060
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, -0x2e(%rbp)
movl (%rax), %edi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x19080
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0x27878
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2786c
movq 0x1f770(%rip), %rdi     # 0x46fd0
leaq 0x11a56(%rip), %rsi     # 0x392bd
callq 0x192e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x27a06
movq -0x80(%rbp), %rax
movl (%rax), %edi
movl $0x40, %esi
callq 0x19330
cmpl $0x0, %eax
jge 0x278fc
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x98(%rbp)
leaq 0x11a20(%rip), %rsi     # 0x392cb
leaq 0x11994(%rip), %rdx     # 0x39246
leaq 0x119e3(%rip), %r8      # 0x3929c
movl $0x34, %ecx
callq 0x22ba0
jmp 0x278c5
movq -0x98(%rbp), %rdi
leaq 0x1f42d(%rip), %rsi     # 0x46d00
leaq -0x47ca(%rip), %rdx     # 0x23110
callq 0x19480
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x19210
jmp 0x27a12
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x279ff
callq 0x36960
movq %rax, %rsi
movq 0x1f6b2(%rip), %rdi     # 0x46fd0
callq 0x192e0
movq %rax, %rdi
leaq 0x119ae(%rip), %rsi     # 0x392db
callq 0x192e0
movq %rax, %rdi
movq 0x1f99c(%rip), %rsi     # 0x472d8
callq 0x192e0
movq %rax, %rdi
leaq 0x1199f(%rip), %rsi     # 0x392ea
callq 0x192e0
movq -0x80(%rbp), %rsi
movq %rax, -0xb0(%rbp)
addq $0x10, %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f340
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x19290
movq %rax, -0xa0(%rbp)
jmp 0x27990
movq -0xa0(%rbp), %rdi
leaq 0x10a4d(%rip), %rsi     # 0x383eb
callq 0x192e0
movq %rax, -0xb8(%rbp)
jmp 0x279ac
movq -0xb8(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x24(%rax), %esi
callq 0x19490
movq %rax, -0xc0(%rbp)
jmp 0x279c8
movq -0xc0(%rbp), %rdi
movq 0x1f5da(%rip), %rsi     # 0x46fb0
callq 0x19320
jmp 0x279dd
leaq -0x78(%rbp), %rdi
callq 0x191e0
jmp 0x279ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x191e0
jmp 0x27a12
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x194a0
nopl (%rax,%rax)