// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r14
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, %r13
movq %rsi, 0x20(%rdi)
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x7dba
pushq $0x30
popq %rdi
callq 0x7030
movq $0x1, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x8(%rax), %rcx
leaq 0x1bba5(%rip), %r12     # 0x23330
movq %r12, 0x8(%rax)
movq %rcx, 0x10(%r13)
andq $0x0, 0x18(%rax)
movw $0x2, 0x20(%rax)
movq %r15, %rdi
callq 0x7260
movq 0x10(%r13), %rcx
movl %eax, 0x1c(%rcx)
rolw $0x8, %r14w
movw %r14w, 0x1a(%rcx)
leaq 0x30(%r13), %rsi
pushq $0x2
popq %rdi
leaq -0x60(%rbp), %r14
pushq $0x10
popq %rcx
movq %r14, %rdx
callq 0x7280
movq 0x1d7ec(%rip), %rdi     # 0x24fc0
leaq 0x1098d(%rip), %rsi     # 0x18168
callq 0x7240
movq %rax, %rdi
movq %rbx, %rsi
callq 0x7190
leaq 0x108f7(%rip), %rsi     # 0x180e9
movq %rax, %rdi
callq 0x7240
movq 0x20(%r13), %rax
movq 0x40(%r13), %rcx
leaq -0xa0(%rbp), %rsi
andq $0x0, 0x8(%rsi)
leaq 0x1bb83(%rip), %rdx     # 0x23398
movq %rdx, (%rsi)
movl $0x8, 0x10(%rsi)
movq %rax, 0x18(%rsi)
andq $0x0, 0x20(%rsi)
movq %rcx, 0x28(%rsi)
movq %r14, 0x30(%rsi)
movq %rbx, 0x38(%rsi)
movq (%r13), %rax
movq %r13, %rdi
callq *0x50(%rax)
movq (%r13), %rax
movq %r13, -0x30(%rbp)
movq %r13, %rdi
callq *0x58(%rax)
testq %rax, %rax
je 0x786e
leaq 0x1ba98(%rip), %rsi     # 0x232f0
leaq 0x1baa9(%rip), %rdx     # 0x23308
movq %rax, %rdi
xorl %ecx, %ecx
callq 0x72a0
movq %rax, %r14
jmp 0x7871
xorl %r14d, %r14d
movq 0x30(%r14), %r13
pushq $0x28
popq %rcx
movq %r13, %rax
mulq %rcx
seto %cl
addq $0x8, %rax
pushq $-0x1
popq %rdi
cmovbq %rdi, %rax
movq -0x30(%rbp), %rdx
movq %r13, 0x18(%rdx)
testb %cl, %cl
cmoveq %rax, %rdi
callq 0x7030
movq %rax, %r15
movq %r13, (%rax)
testq %r13, %r13
je 0x78c4
imulq $0x28, %r13, %rax
xorl %ecx, %ecx
andq $0x0, 0x10(%r15,%rcx)
movq %r12, 0x8(%r15,%rcx)
addq $0x28, %rcx
cmpq %rcx, %rax
jne 0x78b0
leaq 0x8(%r15), %rax
movq %rax, -0x38(%rbp)
addq $0x24, %r15
xorl %r12d, %r12d
cmpq %r13, %r12
jae 0x79bf
movq 0x40(%r14), %rax
movq (%rax,%r12,8), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x38(%r14), %rcx
movq (%rcx,%r12,8), %r13
movq %r12, -0xc(%r15)
movw $0x2, -0x4(%r15)
pushq $0x2
popq %rbx
movl %ebx, %edi
movq %rax, %rsi
movq %r15, %rdx
callq 0x73c0
testl %eax, %eax
js 0x79ae
movl %r13d, %eax
rolw $0x8, %ax
movw %ax, -0x2(%r15)
movzwl %r13w, %r13d
movl %ebx, %edi
movq %r15, %rsi
leaq -0x50(%rbp), %rbx
movq %rbx, %rdx
pushq $0x10
popq %rcx
callq 0x7280
movq 0x1d680(%rip), %rdi     # 0x24fc0
leaq 0x10851(%rip), %rsi     # 0x18198
callq 0x7240
movq %rax, %rdi
movq %r12, %rsi
callq 0x7190
movq %rax, %rdi
leaq 0x10848(%rip), %rsi     # 0x181a9
callq 0x7240
movq %rax, %rdi
movq %rbx, %rsi
callq 0x7240
movq %rax, %rdi
leaq 0x10806(%rip), %rsi     # 0x18181
callq 0x7240
movq %rax, %rdi
movl %r13d, %esi
callq 0x7380
movq %rax, %rdi
leaq 0x10754(%rip), %rsi     # 0x180e9
callq 0x7240
incq %r12
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r13
addq $0x28, %r15
jmp 0x78d3
leaq 0x107d5(%rip), %rdi     # 0x1818a
callq 0x71e0
jmp 0x7915
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%rax)
testq %r14, %r14
je 0x79d9
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq