// File: /workspace/github_cpp_makefile_star2_O1/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 0x13197
movq 0x260(%rbx), %rax
movzbl (%rax), %esi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x118d8
cmpl $0x0, 0x14(%r14)
setg 0xdb(%rbx)
cmpl $0x2, 0x50(%rbx)
je 0x13039
movl $0x2, 0x50(%rbx)
cmpb $0x1, 0xf0(%rbx)
jne 0x13031
movq 0xe0(%rbx), %rsi
movq 0x58(%rsi), %rdi
addq $0x28, %rsi
leaq 0xf8(%rbx), %rdx
movq $-0x1, %rcx
callq 0x15926
movb $0x0, 0xf0(%rbx)
movq %rbx, %rdi
callq 0x12794
leaq 0x8(%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x19994
leaq 0x1c0(%rbx), %rdi
imulq $0xf4240, 0x28(%rbx), %rax # imm = 0xF4240
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
callq 0x14326
movq %rbx, (%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x13095
movq 0x5fef9(%rip), %rcx     # 0x72f80
cmpb $0x0, (%rcx)
je 0x13091
incl 0x8(%rax)
jmp 0x13095
lock
incl 0x8(%rax)
movq 0x1c0(%rbx), %r14
movq %rsp, %rax
movq %rax, 0x28(%rsp)
movq %fs:-0x8, %rax
testq %rax, %rax
je 0x130b8
movq 0x8(%rax), %rdi
jmp 0x130ba
xorl %edi, %edi
movl $0x70, %esi
callq 0x148a2
movq %rax, %r15
leaq 0x1c8(%rbx), %r12
leaq 0x200(%rbx), %rsi
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movq %rax, (%r15)
leaq 0xb53(%rip), %rcx       # 0x13c3e
movq %rcx, 0x8(%r15)
movl %eax, 0x10(%r15)
movl %eax, 0x18(%r15)
movb $0x0, 0x1c(%r15)
leaq 0x5d10d(%rip), %rcx     # 0x70210
movq %rcx, 0x20(%r15)
movq (%rsp), %rcx
movq %rcx, 0x28(%r15)
movq 0x8(%rsp), %rcx
movq %rcx, 0x30(%r15)
movq %rax, 0x38(%r15)
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x38(%r15)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
addq $0x40, %rdi
callq 0x15310
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 0x1472c
leaq 0x30(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x13eae
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x13188
callq 0x1581a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x13197
callq 0x1581a
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x13370
cmpb $0x1, 0x23c(%rbx)
jne 0x13278
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 0x5fdfd(%rip), %rdi     # 0x72fd8
callq 0xf730
movq %rax, %r14
leaq 0x3d0b3(%rip), %rsi     # 0x5029d
movl $0x11, %edx
movq %rax, %rdi
callq 0xf730
xorl %eax, %eax
cmpl $0x2, 0x50(%rbx)
sete %al
leaq 0x3d0a8(%rip), %rcx     # 0x502af
leaq 0x3f7bc(%rip), %rsi     # 0x529ca
cmoveq %rcx, %rsi
leaq 0x5(,%rax,4), %rdx
movq %r14, %rdi
callq 0xf730
leaq 0x3d090(%rip), %rsi     # 0x502b9
movl $0xf, %edx
movq %r14, %rdi
callq 0xf730
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0xf5f0
movsbl %al, %esi
movq %r14, %rdi
callq 0xf040
movq %rax, %rdi
callq 0xf470
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x13278
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xf650
cmpq $0x0, 0x40(%rbx)
je 0x13370
cmpl $0x5, 0x240(%rbx)
jne 0x132b3
leaq 0x260(%rbx), %rdi
movq 0x260(%rbx), %rsi
movq 0x248(%rbx), %rdx
movq 0x250(%rbx), %rcx
callq 0x19bdc
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x132f4
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), %esi
shll $0x8, %esi
orq %rdx, %rsi
movzbl 0x5(%rax), %ecx
orq %rsi, %rcx
movb 0x6(%rax), %al
movl 0x240(%rbx), %esi
movzbl 0xdb(%rbx), %edx
incl %edx
leaq 0x260(%rbx), %r9
movzbl %al, %r8d
leaq 0x28(%rsp), %rdi
callq 0x143c6
cmpq $0x0, 0x40(%rbx)
je 0x1337c
leaq 0x30(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq *0x48(%rbx)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x13342
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0xf650
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x13359
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0xf650
movq 0x260(%rbx), %rax
cmpq %rax, 0x268(%rbx)
je 0x13370
movq %rax, 0x268(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0xf230
jmp 0x13392
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x13eae
jmp 0x1339d
movq %rax, %rdi
callq 0x10886
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x133b1
callq 0x1581a
jmp 0x133b1
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x133ef
callq 0x1581a
jmp 0x133ef
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x14452
jmp 0x133ef
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x133ef
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xf650
movq %rbx, %rdi
callq 0xfb40
nop