// File: yasz24[P]eau2/src/network/./network_ip.h
// Function: NetworkIP::client_init(unsigned long, char*, unsigned long, char*, unsigned long)
void client_init(size_t idx, char* ip, size_t port, char* server_adr, size_t server_port) {
        this_node_ = idx;
        init_sock_(ip, port);
        nodes_ = new NodeInfo[1];
        nodes_[0].id = 0;
        nodes_[0].address.sin_family = AF_INET;

        nodes_[0].address.sin_addr.s_addr = inet_addr(ip);
        nodes_[0].address.sin_port = htons(server_port);
        
        char client_ip[INET_ADDRSTRLEN];
        inet_ntop(AF_INET, &ip_.sin_addr, client_ip, INET_ADDRSTRLEN);
        std::cout << "creating registration msg, port: " << port <<"\n";
        Register reg(this_node_, 0, msg_id, client_ip, port);

        send_msg(&reg);

        Directory* ipd = dynamic_cast<Directory*>(recv_msg());
        num_nodes_ = ipd->clients;
        NodeInfo * nodes = new NodeInfo[num_nodes_];
        for (size_t i = 0; i < num_nodes_; i++) {
            char* node_ip = ipd->addresses[i]->c_str();
            size_t node_port = ipd->ports[i];
            nodes[i].id = i;
            nodes[i].address.sin_family = AF_INET;
            if (inet_pton(AF_INET, node_ip, &nodes[i].address.sin_addr) < 0) {
                perror("Node storage:");
            }
            nodes[i].address.sin_port = htons(node_port);
            int decoded_port = ntohs(nodes[i].address.sin_port);
            char decoded_ip[INET_ADDRSTRLEN];
            inet_ntop(AF_INET, &nodes[i].address.sin_addr, decoded_ip, INET_ADDRSTRLEN);
            std::cout << "Directory: node " << i << ", ip: " <<  decoded_ip << ", port: " << decoded_port << "\n";
            //nodes[i].address.sin_addr.s_addr = inet_addr(node_ip);
        }
        nodes_ = nodes;
        delete ipd;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, 0x20(%rdi)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x98a0
movl $0x30, %edi
callq 0x8030
movq %rax, -0xf0(%rbp)
movq $0x1, (%rax)
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
movq %rax, %rcx
addq $0x28, %rcx
movq %rcx, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x99d0
jmp 0x8ac0
movq -0xe0(%rbp), %rcx
movq -0x100(%rbp), %rax
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0xd8(%rbp)
jne 0x8aab
movq -0xf8(%rbp), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rcx
movq $0x0, 0x10(%rcx)
movq 0x10(%rax), %rax
movw $0x2, 0x18(%rax)
movq -0x18(%rbp), %rdi
callq 0x82a0
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x1c(%rax)
movzwl -0x30(%rbp), %edi
callq 0x8060
movq -0xf8(%rbp), %rsi
movw %ax, %cx
movq 0x10(%rsi), %rax
movw %cx, 0x1a(%rax)
addq $0x30, %rsi
movl $0x2, %edi
leaq -0x50(%rbp), %rdx
movq %rdx, -0x110(%rbp)
movl $0x10, %ecx
callq 0x82c0
movq 0x33461(%rip), %rdi     # 0x3bfc0
leaq 0x2367f(%rip), %rsi     # 0x2c1e5
callq 0x8280
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x80a0
movq %rax, %rdi
leaq 0x235ac(%rip), %rsi     # 0x2c12d
callq 0x8280
movq -0x110(%rbp), %r8
movq -0xf8(%rbp), %rax
movq 0x20(%rax), %rsi
movq 0x40(%rax), %rcx
movq -0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x9a30
movq -0xf8(%rbp), %rdi
movq -0x108(%rbp), %rsi
movq (%rdi), %rax
movq 0x50(%rax), %rax
callq *%rax
jmp 0x8bd0
movq -0xf8(%rbp), %rdi
movq (%rdi), %rax
movq 0x58(%rax), %rax
callq *%rax
movq %rax, -0x118(%rbp)
jmp 0x8be9
movq -0x118(%rbp), %rax
cmpq $0x0, %rax
je 0x8c9b
movq -0x118(%rbp), %rdi
leaq 0x315c0(%rip), %rsi     # 0x3a1c8
leaq 0x315d1(%rip), %rdx     # 0x3a1e0
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
movq %rax, -0x120(%rbp)
jmp 0x8ca6
movq -0xe8(%rbp), %rcx
movq %rax, %rsi
movq -0x100(%rbp), %rax
movq %rsi, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x128(%rbp)
je 0x8c79
movq -0x128(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x130(%rbp)
callq 0x9a10
movq -0xe8(%rbp), %rcx
movq -0x130(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x128(%rbp)
jne 0x8c48
movq -0xf0(%rbp), %rdi
callq 0x8300
jmp 0x9081
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x9075
xorl %eax, %eax
movq %rax, -0x120(%rbp)
jmp 0x8ca6
movq -0xf8(%rbp), %rax
movq -0x120(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq -0x98(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq 0x18(%rax), %rax
movq %rax, -0x140(%rbp)
movl $0x28, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
callq 0x8030
movq %rax, -0x138(%rbp)
jmp 0x8d06
movq -0x140(%rbp), %rax
movq -0x138(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x148(%rbp)
cmpq $0x0, %rax
je 0x8d81
movq -0x148(%rbp), %rax
movq -0x140(%rbp), %rcx
imulq $0x28, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x158(%rbp)
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x99d0
jmp 0x8d63
movq -0x158(%rbp), %rcx
movq -0x160(%rbp), %rax
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0x150(%rbp)
jne 0x8d4e
movq -0x148(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0xf8(%rbp), %rcx
movq -0xa8(%rbp), %rax
cmpq 0x18(%rcx), %rax
jae 0x902d
movq -0x98(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xa8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq %rax, -0x168(%rbp)
jmp 0x8dda
movq -0x168(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
movq 0x38(%rax), %rax
movq -0xa8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rcx
movq -0xa0(%rbp), %rax
imulq $0x28, -0xa8(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0xa0(%rbp), %rax
imulq $0x28, -0xa8(%rbp), %rcx
addq %rcx, %rax
movw $0x2, 0x18(%rax)
movq -0xb0(%rbp), %rsi
movq -0xa0(%rbp), %rdx
imulq $0x28, -0xa8(%rbp), %rax
addq %rax, %rdx
addq $0x18, %rdx
addq $0x4, %rdx
movl $0x2, %edi
callq 0x8450
cmpl $0x0, %eax
jge 0x8ee0
leaq 0x23396(%rip), %rdi     # 0x2c207
callq 0x8220
jmp 0x8e78
jmp 0x8ee0
movq -0x148(%rbp), %rcx
movq %rax, %rsi
movq -0x160(%rbp), %rax
movq %rsi, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x170(%rbp)
je 0x8ecf
movq -0x170(%rbp), %rdi
addq $-0x28, %rdi
movq %rdi, -0x178(%rbp)
callq 0x9a10
movq -0x148(%rbp), %rcx
movq -0x178(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x170(%rbp)
jne 0x8e9e
movq -0x138(%rbp), %rdi
callq 0x8300
jmp 0x9075
movzwl -0xb8(%rbp), %edi
callq 0x8060
movw %ax, %dx
movq -0xa0(%rbp), %rax
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movw %dx, 0x1a(%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movzwl 0x1a(%rax,%rcx,8), %edi
callq 0x8440
movzwl %ax, %eax
movl %eax, -0xbc(%rbp)
movq -0xa0(%rbp), %rax
movq -0xa8(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq 0x1c(%rax,%rcx,8), %rsi
movl $0x2, %edi
leaq -0xd0(%rbp), %rdx
movl $0x10, %ecx
callq 0x82c0
movq 0x33061(%rip), %rdi     # 0x3bfc0
leaq 0x232af(%rip), %rsi     # 0x2c215
callq 0x8280
movq %rax, -0x180(%rbp)
jmp 0x8f74
movq -0x180(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x80a0
movq %rax, -0x188(%rbp)
jmp 0x8f90
movq -0x188(%rbp), %rdi
leaq 0x23288(%rip), %rsi     # 0x2c226
callq 0x8280
movq %rax, -0x190(%rbp)
jmp 0x8fac
movq -0x190(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x8280
movq %rax, -0x198(%rbp)
jmp 0x8fc8
movq -0x198(%rbp), %rdi
leaq 0x23228(%rip), %rsi     # 0x2c1fe
callq 0x8280
movq %rax, -0x1a0(%rbp)
jmp 0x8fe4
movq -0x1a0(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x83f0
movq %rax, -0x1a8(%rbp)
jmp 0x8fff
movq -0x1a8(%rbp), %rdi
leaq 0x23120(%rip), %rsi     # 0x2c12d
callq 0x8280
jmp 0x9014
jmp 0x9016
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x8d9a
movq -0xf8(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, %rax
je 0x9060
movq -0x1b0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
leaq -0x90(%rbp), %rdi
callq 0x9ab0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x9ab0
movq -0x38(%rbp), %rdi
callq 0x8400
nopw (%rax,%rax)