// File: /workspace/github_cpp_makefile_star2_O2/davidcairuz[P]network-internet-relay-chat/server.cpp
// Function: spread_message(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void spread_message(string message, int speaker) {
    pthread_mutex_lock(&lock);
    
    int pos = active->find(speaker);
    string name = active->clients[pos].name + "#" + to_string(active->clients[pos].id) + ": ";
    
    if (active->clients[pos].channel_name == "$") {
        send_message("Please, join a channel", speaker);
        pthread_mutex_unlock(&lock);
        return;
    }

    if (active->clients[pos].is_muted) {
        send_message("You have the right to remain silent!", speaker);
        pthread_mutex_unlock(&lock);
        return;
    }

    int max_len = Socket::buffer_size - name.size();
    vector<int> to_be_removed;

    for (Client client : active->clients) {
        int conn = client.conn;

        int receiver = active->find(conn);

        // checa canal do destinatário
        if (active->clients[receiver].channel_name != active->clients[pos].channel_name) continue;

        // envia batches da mensagem
        for (int i = 0; (unsigned int)i < message.size(); i += max_len) {
            string actual_message = name + message.substr(i, max_len);
            
            int status = -1, retries = Socket::max_retries;
            while (status == -1 && retries--)
                status = socket_server->Write(actual_message, conn);

            if (status == -1) to_be_removed.push_back(conn);
        }
    }

    for (int client : to_be_removed) active->remove(client);
    pthread_mutex_unlock(&lock);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl %esi, %r14d
movq %rdi, %r15
leaq 0x72ba(%rip), %rdi      # 0xa218
callq 0x22e0
movq 0x7336(%rip), %rdi      # 0xa2a0
movl %r14d, %esi
callq 0x4746
movq 0x7327(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rbx
leaq (%rcx,%rbx), %rsi
addq $0x28, %rsi
leaq 0x3199(%rip), %rdx      # 0x612a
leaq -0xb8(%rbp), %rdi
callq 0x4821
movq 0x72fc(%rip), %rax      # 0xa2a0
movq (%rax), %rax
movl (%rax,%rbx), %esi
leaq -0x98(%rbp), %rdi
callq 0x4859
leaq -0x190(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x47b0
leaq 0x33c8(%rip), %rdx      # 0x639f
leaq -0xd8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x4787
leaq -0x190(%rbp), %rdi
callq 0x2110
leaq -0x98(%rbp), %rdi
callq 0x2110
leaq -0xb8(%rbp), %rdi
callq 0x2110
movq 0x728b(%rip), %rax      # 0xa2a0
movq (%rax), %rax
leaq (%rax,%rbx), %rdi
addq $0x50, %rdi
leaq 0x3105(%rip), %rsi      # 0x612c
callq 0x48b9
testb %al, %al
je 0x3062
leaq 0x30f7(%rip), %rsi      # 0x612e
leaq -0x118(%rbp), %rdi
leaq -0x190(%rbp), %rdx
callq 0x271a
leaq -0x118(%rbp), %rdi
movl %r14d, %esi
callq 0x2e64
leaq -0x118(%rbp), %rdi
jmp 0x30a3
movq 0x7237(%rip), %rax      # 0xa2a0
movq (%rax), %rcx
cmpb $0x1, 0x71(%rcx,%rbx)
jne 0x30b9
leaq 0x30cb(%rip), %rsi      # 0x6145
leaq -0xf8(%rbp), %rdi
leaq -0x190(%rbp), %rdx
callq 0x271a
leaq -0xf8(%rbp), %rdi
movl %r14d, %esi
callq 0x2e64
leaq -0xf8(%rbp), %rdi
callq 0x2110
leaq 0x7169(%rip), %rdi      # 0xa218
callq 0x2190
jmp 0x3251
movq %rbx, -0x58(%rbp)
movl $0x1000, %ecx           # imm = 0x1000
leaq -0xd8(%rbp), %rdx
subl 0x8(%rdx), %ecx
leaq -0x50(%rbp), %rdx
andq $0x0, 0x10(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movslq %ecx, %r13
leaq -0xb8(%rbp), %r12
leaq -0x1b0(%rbp), %r14
movq %r15, %rbx
movq %r15, -0x70(%rbp)
cmpq -0x60(%rbp), %rsi
je 0x321b
leaq -0x190(%rbp), %rdi
movq %rsi, -0x68(%rbp)
callq 0x48ca
movl -0x18c(%rbp), %esi
movl %esi, -0x2c(%rbp)
movq 0x7178(%rip), %rdi      # 0xa2a0
callq 0x4746
movq 0x716c(%rip), %rcx      # 0xa2a0
cltq
movq (%rcx), %rcx
imulq $0x78, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x50, %rdi
movq -0x58(%rbp), %rax
leaq (%rcx,%rax), %rsi
addq $0x50, %rsi
callq 0x4949
testb %al, %al
je 0x3170
leaq -0x190(%rbp), %rdi
callq 0x49aa
movq -0x68(%rbp), %rsi
addq $0x78, %rsi
jmp 0x30fe
xorl %edx, %edx
movl %edx, %eax
cmpq %rax, 0x8(%rbx)
jbe 0x315a
leaq -0x98(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %rdx, -0x78(%rbp)
movq %r13, %rcx
callq 0x2240
movq %r13, %rbx
movq %r12, %rdi
leaq -0xd8(%rbp), %rsi
movq %r15, %rdx
callq 0x4956
movq %r15, %rdi
callq 0x2110
pushq $-0x5
popq %r13
pushq $-0x1
popq %r15
cmpl $-0x1, %r15d
jne 0x3200
testl %r13d, %r13d
je 0x31f3
movq 0x7046(%rip), %r15      # 0xa210
movq %r14, %rdi
movq %r12, %rsi
callq 0x22b0
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2c8e
movl %eax, %r15d
movq %r14, %rdi
callq 0x2110
incl %r13d
jmp 0x31b8
leaq -0x50(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4984
movq %r12, %rdi
callq 0x2110
movq %rbx, %r13
movq -0x78(%rbp), %rdx
addq %rbx, %rdx
movq -0x70(%rbp), %rbx
jmp 0x3172
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r14
cmpq %r14, %rbx
je 0x323c
movl (%rbx), %esi
movq 0x706f(%rip), %rdi      # 0xa2a0
callq 0x46fa
addq $0x4, %rbx
jmp 0x3223
leaq 0x6fd5(%rip), %rdi      # 0xa218
callq 0x2190
leaq -0x50(%rbp), %rdi
callq 0x542e
leaq -0xd8(%rbp), %rdi
callq 0x2110
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
jmp 0x3287
jmp 0x3291
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x2110
jmp 0x3313
movq %rax, %rbx
jmp 0x3313
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x2110
jmp 0x32aa
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x2110
jmp 0x32bb
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
jmp 0x331a
jmp 0x32c6
movq %rax, %rbx
jmp 0x330a
jmp 0x32de
movq %rax, %rbx
jmp 0x32fe
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
jmp 0x32f9
movq %rax, %rbx
jmp 0x32f2
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
callq 0x2110
leaq -0xb8(%rbp), %rdi
callq 0x2110
leaq -0x190(%rbp), %rdi
callq 0x49aa
leaq -0x50(%rbp), %rdi
callq 0x542e
leaq -0xd8(%rbp), %rdi
callq 0x2110
movq %rbx, %rdi
callq 0x2350