// File: /workspace/github_cpp_makefile_star2_O3/flightaware[P]beast-splitter/beast_input.cc
// Function: beast::BeastInput::dispatch_message()
void BeastInput::dispatch_message() {
    // monitor status messages for GPS timestamp bit
    // and for radarcape autodetection
    if (messagetype == modes::MessageType::STATUS) {
        receiving_gps_timestamps = Settings(messagedata[0]).gps_timestamps.on();
        if (receiver_type != ReceiverType::RADARCAPE) {
            receiver_type = ReceiverType::RADARCAPE;
            autodetect_timer.cancel();
            send_settings_message(); // for the g/G setting
        }

        auto self(shared_from_this());
        liveness_timer.expires_from_now(radarcape_liveness_interval);
        liveness_timer.async_wait([this, self](const boost::system::error_code &ec) {
            if (!ec) {
                std::cerr << what() << ": no recent status messages received" << std::endl;
                disconnect();
                connection_failed();
            }
        });
    }

    if (!can_dispatch())
        return;

    if (first_message) {
        first_message = false;
        std::cerr << what() << ": connected to a " << (receiver_type == ReceiverType::RADARCAPE ? "Radarcape" : "Beast") << "-style receiver" << std::endl;
    }

    if (!message_notifier)
        return;

    // basic decoding, then pass it on.
    std::uint64_t timestamp = 0;
    std::uint8_t signal = 0;

    if (messagetype == modes::MessageType::POSITION) {
        // position messages are special, they use the metadata area for actual data
        // so glue the metadata bytes onto the start of the data bytes and don't decode
        // timestamp/signal
        messagedata.insert(messagedata.begin(), metadata.cbegin(), metadata.cend());
    } else {
        timestamp = ((std::uint64_t)metadata[0] << 40) | ((std::uint64_t)metadata[1] << 32) | ((std::uint64_t)metadata[2] << 24) | ((std::uint64_t)metadata[3] << 16) | ((std::uint64_t)metadata[4] << 8) | ((std::uint64_t)metadata[5]);

        signal = metadata[6];
    }

    // dispatch it
    message_notifier(modes::Message(messagetype, receiving_gps_timestamps ? modes::TimestampType::GPS : modes::TimestampType::TWELVEMEG, timestamp, signal, std::move(messagedata)));
    messagedata.clear(); // make sure we leave it in a valid state after moving
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
cmpl $0x4, 0x240(%rdi)
jne 0x11fe8
movq 0x260(%rbx), %rax
movzbl (%rax), %esi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x107a8
cmpl $0x0, 0x14(%r14)
setg 0xdb(%rbx)
cmpl $0x2, 0x50(%rbx)
je 0x11e9b
movl $0x2, 0x50(%rbx)
cmpb $0x1, 0xf0(%rbx)
jne 0x11e93
movq 0xe0(%rbx), %rsi
movq 0x58(%rsi), %rdi
addq $0x28, %rsi
leaq 0xf8(%rbx), %rdx
movq $-0x1, %rcx
callq 0x1464a
movb $0x0, 0xf0(%rbx)
movq %rbx, %rdi
callq 0x1165a
leaq 0x8(%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x185ac
leaq 0x1c0(%rbx), %rdi
imulq $0xf4240, 0x28(%rbx), %rax # imm = 0xF4240
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
callq 0x13140
movq %rbx, (%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x11ef7
movq 0x5f097(%rip), %rcx     # 0x70f80
cmpb $0x0, (%rcx)
je 0x11ef3
incl 0x8(%rax)
jmp 0x11ef7
lock
incl 0x8(%rax)
movq 0x1c0(%rbx), %r14
movq %rsp, %rax
movq %rax, 0x28(%rsp)
movq %fs:-0x8, %rax
testq %rax, %rax
je 0x11f1a
movq 0x8(%rax), %rdi
jmp 0x11f1c
xorl %edi, %edi
movl $0x70, %esi
callq 0x136c4
movq %rax, %r15
leaq 0x1c8(%rbx), %r12
leaq 0x200(%rbx), %rsi
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rax, (%r15)
leaq 0xb2c(%rip), %rcx       # 0x12a74
movq %rcx, 0x8(%r15)
movl %eax, 0x10(%r15)
movl %eax, 0x18(%r15)
movb $0x0, 0x1c(%r15)
leaq 0x5c3d0(%rip), %rcx     # 0x6e330
movq %rcx, 0x20(%r15)
movaps (%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x38(%r15)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
addq $0x40, %rdi
callq 0x140a4
movq %r15, 0x38(%rsp)
movb $0x1, 0x1d0(%rbx)
movq 0x58(%r14), %rdi
addq $0x28, %r14
leaq 0x1d8(%rbx), %rcx
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %r8
callq 0x13542
leaq 0x30(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x12ce2
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x11fd9
callq 0x14590
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x11fe8
callq 0x14590
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x121c3
cmpb $0x1, 0x23c(%rbx)
jne 0x120c9
movb $0x0, 0x23c(%rbx)
movq (%rbx), %rax
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq *0x20(%rax)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x5efac(%rip), %rdi     # 0x70fd8
callq 0xe730
movq %rax, %r14
leaq 0x3c302(%rip), %rsi     # 0x4e33d
movl $0x11, %edx
movq %rax, %rdi
callq 0xe730
xorl %eax, %eax
cmpl $0x2, 0x50(%rbx)
sete %al
leaq 0x3c2f7(%rip), %rcx     # 0x4e34f
leaq 0x3e98b(%rip), %rsi     # 0x509ea
cmoveq %rcx, %rsi
leaq 0x5(,%rax,4), %rdx
movq %r14, %rdi
callq 0xe730
leaq 0x3c2df(%rip), %rsi     # 0x4e359
movl $0xf, %edx
movq %r14, %rdi
callq 0xe730
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0xe5f0
movsbl %al, %esi
movq %r14, %rdi
callq 0xe040
movq %rax, %rdi
callq 0xe470
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x120c9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xe650
cmpq $0x0, 0x40(%rbx)
je 0x121c3
movl 0x240(%rbx), %esi
cmpl $0x5, %esi
jne 0x1210c
leaq 0x260(%rbx), %rdi
movq 0x260(%rbx), %rsi
movq 0x248(%rbx), %rdx
movq 0x250(%rbx), %rcx
callq 0x18808
movl 0x240(%rbx), %esi
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x1214d
movq 0x248(%rbx), %rax
movzbl (%rax), %ecx
shlq $0x28, %rcx
movzbl 0x1(%rax), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movzbl 0x2(%rax), %ecx
shll $0x18, %ecx
orq %rdx, %rcx
movzbl 0x3(%rax), %edx
shll $0x10, %edx
orq %rcx, %rdx
movzbl 0x4(%rax), %edi
shll $0x8, %edi
orq %rdx, %rdi
movzbl 0x5(%rax), %ecx
orq %rdi, %rcx
movb 0x6(%rax), %al
movzbl 0xdb(%rbx), %edx
incl %edx
leaq 0x260(%rbx), %r9
movzbl %al, %r8d
leaq 0x28(%rsp), %rdi
callq 0x131e0
cmpq $0x0, 0x40(%rbx)
je 0x121cf
leaq 0x30(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq *0x48(%rbx)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x12195
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0xe650
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x121ac
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0xe650
movq 0x260(%rbx), %rax
cmpq %rax, 0x268(%rbx)
je 0x121c3
movq %rax, 0x268(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0xe230
jmp 0x121e5
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x12ce2
jmp 0x121f0
movq %rax, %rdi
callq 0xf7cb
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x12204
callq 0x14590
jmp 0x12204
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x12242
callq 0x14590
jmp 0x12242
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x13264
jmp 0x12242
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12242
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xe650
movq %rbx, %rdi
callq 0xeb40