// File: lega911[P]ijson/src/connect.cpp
// Function: Connect::on_send()
void Connect::on_send() {
    if(send_buffer.size()) {
        int sent = this->raw_send(send_buffer.ptr(), send_buffer.size());
        if(sent < 0) THROW("Not implemented: sent < 0");
        send_buffer.remove_left(sent);
    } else if(!direct_message.empty()) {
        if(server->log & 32) this->start_time = get_time();
        auto *dm = direct_message.front();
        direct_message.pop_front();
        GC gc(dm, GC::DirectMessage);

        int sent = this->raw_send(dm->data.ptr(), dm->data.size());
        if(sent < 0) THROW("Not implemented: sent < 0");

        if(sent != dm->data.size()) send_buffer.add(&dm->data.ptr()[sent], dm->data.size() - sent);
    }

    if(send_buffer.size() == 0) {
        if(this->keep_alive) {
            this->write_mode(false);
        } else {
            this->close();
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
addq $0x20, %rdi
callq 0x1e6d0
cmpl $0x0, %eax
je 0x19c4a
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x1e6f0
movq -0x50(%rbp), %rdi
movq %rax, -0x58(%rbp)
addq $0x20, %rdi
callq 0x1e6d0
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl %eax, %edx
callq 0x19b10
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x19c35
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0x1e486(%rip), %rsi     # 0x38070
leaq 0x1e458(%rip), %rdx     # 0x38049
leaq 0x1e492(%rip), %r8      # 0x3808a
movl $0x2e, %ecx
callq 0x22ba0
jmp 0x19c04
movq -0x60(%rbp), %rdi
leaq 0x2d0f1(%rip), %rsi     # 0x46d00
leaq 0x94fa(%rip), %rdx      # 0x23110
callq 0x19480
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x19210
jmp 0x19e74
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
movl -0xc(%rbp), %esi
callq 0x1e710
jmp 0x19e37
movq -0x50(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x1e780
testb $0x1, %al
jne 0x19e35
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x20(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x19c88
callq 0x36910
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x1e0(%rax)
movq -0x50(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
movq %rdi, -0x70(%rbp)
callq 0x1e7b0
movq -0x70(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x28(%rbp)
callq 0x1e7e0
movq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movl $0x2, %edx
callq 0x1e850
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x1e6f0
movq %rax, -0x68(%rbp)
jmp 0x19cd1
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x1e6d0
movl %eax, -0x74(%rbp)
jmp 0x19ce3
movl -0x74(%rbp), %edx
movq -0x68(%rbp), %rsi
movq -0x50(%rbp), %rdi
callq 0x19b10
movl %eax, -0x78(%rbp)
jmp 0x19cf8
movl -0x78(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x19d80
movl $0x30, %edi
callq 0x19180
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0x1e351(%rip), %rsi     # 0x38070
leaq 0x1e323(%rip), %rdx     # 0x38049
leaq 0x1e35d(%rip), %r8      # 0x3808a
movl $0x37, %ecx
callq 0x22ba0
jmp 0x19d39
movq -0x80(%rbp), %rdi
leaq 0x2cfbc(%rip), %rsi     # 0x46d00
leaq 0x93c5(%rip), %rdx      # 0x23110
callq 0x19480
jmp 0x19e7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x19e2a
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x19210
jmp 0x19e2a
movl -0x44(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x1e6d0
movl %eax, -0x84(%rbp)
jmp 0x19d9e
movl -0x88(%rbp), %eax
movl -0x84(%rbp), %ecx
cmpl %ecx, %eax
je 0x19e1f
movq -0x50(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x1e6f0
movq %rax, -0x90(%rbp)
jmp 0x19dd3
movq -0x90(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x1e6d0
movl %eax, -0x9c(%rbp)
jmp 0x19dfd
movq -0xa8(%rbp), %rsi
movq -0x98(%rbp), %rdi
movl -0x9c(%rbp), %edx
movl -0x44(%rbp), %eax
subl %eax, %edx
callq 0x1e8b0
jmp 0x19e1d
jmp 0x19e1f
leaq -0x40(%rbp), %rdi
callq 0x1e970
jmp 0x19e35
leaq -0x40(%rbp), %rdi
callq 0x1e970
jmp 0x19e74
jmp 0x19e37
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x1e6d0
cmpl $0x0, %eax
jne 0x19e6b
movq -0x50(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x19e60
movq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x19a10
jmp 0x19e69
movq -0x50(%rbp), %rdi
callq 0x1e9b0
jmp 0x19e6b
addq $0xb0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x194a0
nopl (%rax)