// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./src/actions/chat.cpp
// Function: websocket::broadcast(mg_connection*)
void broadcast(mg_connection *conn){
        struct ChatData *d = (struct ChatData *) conn->connection_param;
        struct mg_connection *c;

        time_t rawtime;
        time(&rawtime);

        struct History *h = new History();
        strcpy(h->ssid, d->ssid);

        int len = conn->content_len - 4;
        len = len > 1023 ? 1023 : len;
        strncpy(h->message, conn->content + 4, len);
        h->message[len] = 0;

        h->timestamp = rawtime;

        history.push_front(h);
        while(history.size() > configs.global().get<int>("chat::max_histories")){
            struct History *h2 = history.back();
            delete h2;
            history.pop_back();
        }

        for (c = mg_next(server, NULL); c != NULL; c = mg_next(server, c)) {
            struct ChatData *d2 = (struct ChatData *) c->connection_param;
            if (!c->is_websocket || d2->roomID != d->roomID) continue;

            if(strcmp(d->ssid, admin_cookie.c_str()) == 0)
                mg_websocket_printf(c, WEBSOCKET_OPCODE_TEXT, "msg %c Admin %d %.*s",
                          (char) d->roomID, rawtime, conn->content_len - 4, conn->content + 4);
            else
                mg_websocket_printf(c, WEBSOCKET_OPCODE_TEXT, "msg %c %.9s %d %.*s",
                          (char) d->roomID, d->ssid, rawtime, len, h->message);
        }

        //delete [] bufMessage;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r13
movq 0x290(%rdi), %rbp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0xc850
movl $0x448, %edi            # imm = 0x448
callq 0xc1f0
movq %rax, %r15
leaq 0x40(%rax), %r14
movl $0x448, %edx            # imm = 0x448
movq %rax, %rdi
xorl %esi, %esi
callq 0xc370
leaq 0x28(%rsp), %r12
movq %r15, (%r12)
movq %rbp, 0x20(%rsp)
leaq 0x4(%rbp), %rsi
movq %r15, %rdi
movq %rsi, 0x18(%rsp)
callq 0xc490
movl 0x270(%r13), %ecx
addl $-0x4, %ecx
movl $0x3ff, %eax            # imm = 0x3FF
cmpl %eax, %ecx
cmovgel %eax, %ecx
movq %r13, 0x8(%rsp)
movq 0x268(%r13), %rsi
addq $0x4, %rsi
movq %rcx, 0x10(%rsp)
movslq %ecx, %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0xc1e0
movb $0x0, 0x40(%r15,%r13)
movq (%rbx), %rax
movq %rax, 0x440(%r15)
leaq 0x636e6(%rip), %r15     # 0x87db0
movq %r15, %rdi
movq %r12, %rsi
callq 0x24b4a
leaq 0x3dae0(%rip), %r13     # 0x621bc
leaq 0x38(%rsp), %rbp
leaq 0x7(%rsp), %rbx
movq %r15, %rdi
callq 0x24b66
movq %rax, %r14
leaq 0x63708(%rip), %rdi     # 0x87e00
callq 0x1008c
movq %rax, %r12
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xcb10
movq %r12, %rdi
movq %rbp, %rsi
callq 0x100e4
movslq %eax, %r12
movq %rbp, %rdi
callq 0xcd88
cmpq %r12, %r14
jbe 0x2475f
movq 0x636b0(%rip), %rax     # 0x87de0
cmpq 0x636b1(%rip), %rax     # 0x87de8
jne 0x2474c
movq 0x636b8(%rip), %rax     # 0x87df8
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
callq 0xc660
movq %r15, %rdi
callq 0x24b76
jmp 0x246e6
leaq 0x635da(%rip), %rbx     # 0x87d40
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x5c0e2
movq %rax, %r12
leaq 0x634ce(%rip), %r14     # 0x87c48
pushq $0x1
popq %rbp
movq 0x18(%rsp), %r13
testq %r12, %r12
je 0x24838
cmpl $0x0, 0x278(%r12)
je 0x24825
movq 0x290(%r12), %rax
movl (%rax), %r15d
movq 0x20(%rsp), %rax
cmpl (%rax), %r15d
jne 0x24825
movq (%r14), %rsi
movq %r13, %rdi
callq 0xc970
movsbl %r15b, %ecx
movq 0x30(%rsp), %r9
testl %eax, %eax
je 0x247e9
movq 0x28(%rsp), %r10
addq $0x40, %r10
movq %r12, %rdi
movl %ebp, %esi
leaq 0x3da09(%rip), %rdx     # 0x621e5
movq %r13, %r8
xorl %eax, %eax
pushq %r10
pushq 0x18(%rsp)
jmp 0x2481e
movq 0x8(%rsp), %rax
movq 0x268(%rax), %r10
movq 0x270(%rax), %rax
addq $-0x4, %rax
addq $0x4, %r10
subq $0x8, %rsp
movq %r12, %rdi
movl %ebp, %esi
leaq 0x3d9bc(%rip), %rdx     # 0x621d0
movq %r9, %r8
movq %rax, %r9
xorl %eax, %eax
pushq %r10
callq 0x59874
popq %rcx
popq %rdx
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x5c0e2
movq %rax, %r12
jmp 0x24782
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xcd88
movq %rbx, %rdi
callq 0xc790