// File: /workspace/github_cpp_makefile_star2_O2/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 0x12a8b
movq 0x260(%rbx), %rax
movzbl (%rax), %esi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x11664
cmpl $0x0, 0x14(%r14)
setg 0xdb(%rbx)
cmpl $0x2, 0x50(%rbx)
je 0x12977
movl $0x2, 0x50(%rbx)
leaq 0xe0(%rbx), %rdi
callq 0x13916
movq %rbx, %rdi
callq 0x12324
leaq 0x8(%rbx), %rsi
leaq 0x18(%rsp), %rdi
callq 0x1824e
leaq 0x1c0(%rbx), %rdi
imulq $0xf4240, 0x28(%rbx), %rax # imm = 0xF4240
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
callq 0x13964
leaq 0x8(%rsp), %rdi
movq %rbx, -0x8(%rdi)
leaq 0x18(%rsp), %rsi
callq 0x14dce
movq 0x1c0(%rbx), %r14
movq %rsp, %rsi
movq %rsi, 0x28(%rsp)
pushq $0x70
popq %rdi
xorl %eax, %eax
callq 0x13dbd
movq %rax, %r15
movq %rax, 0x30(%rsp)
andq $0x0, (%rax)
leaq 0x9da(%rip), %rax       # 0x133ba
movq %rax, 0x8(%r15)
andl $0x0, 0x10(%r15)
andl $0x0, 0x18(%r15)
movb $0x0, 0x1c(%r15)
leaq 0x57796(%rip), %rax     # 0x6a190
movq %rax, 0x20(%r15)
movaps (%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq 0x10(%rsp), %rax
andq $0x0, 0x10(%rsp)
movq %rax, 0x38(%r15)
andq $0x0, 0x8(%rsp)
leaq 0x200(%rbx), %rsi
leaq 0x1c8(%rbx), %r12
movq %r15, %rdi
addq $0x40, %rdi
callq 0x14776
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 0x13d28
leaq 0x30(%rsp), %rax
leaq 0x10(%rsp), %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x133aa
movq %r14, %rdi
callq 0x14e02
leaq 0x20(%rsp), %rdi
callq 0x14e02
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
je 0x12bef
cmpb $0x1, 0x23c(%rbx)
jne 0x12b1a
movb $0x0, 0x23c(%rbx)
movq (%rbx), %rax
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq *0x20(%rax)
movq 0x5a514(%rip), %rdi     # 0x6cfd8
movq %r14, %rsi
callq 0xf590
leaq 0x3088a(%rip), %rsi     # 0x4335d
movq %rax, %rdi
callq 0xf610
cmpl $0x2, 0x50(%rbx)
leaq 0x30889(%rip), %rcx     # 0x4336f
leaq 0x32fcd(%rip), %rsi     # 0x45aba
cmoveq %rcx, %rsi
movq %rax, %rdi
callq 0xf610
leaq 0x30879(%rip), %rsi     # 0x43379
movq %rax, %rdi
callq 0xf610
movq %rax, %rdi
callq 0xf310
leaq 0x28(%rsp), %rdi
callq 0xfd68
cmpq $0x0, 0x40(%rbx)
je 0x12bef
leaq 0x30(%rbx), %r14
movl 0x240(%rbx), %esi
cmpl $0x5, %esi
jne 0x12b61
leaq 0x260(%rbx), %rdi
movq 0x260(%rbx), %rsi
movq 0x248(%rbx), %rdx
movq 0x250(%rbx), %rcx
callq 0x13a18
movl 0x240(%rbx), %esi
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x12ba2
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), %r15
movq %r15, %rdi
callq 0x13a38
movq %r14, %rdi
movq %r15, %rsi
callq 0x10f60
leaq 0x28(%rsp), %rdi
callq 0x13aac
movq 0x260(%rbx), %rax
cmpq %rax, 0x268(%rbx)
je 0x12bef
movq %rax, 0x268(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x13aac
jmp 0x12c44
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x133aa
jmp 0x12c1c
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x14e02
jmp 0x12c2b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x14e02
jmp 0x12c44
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xfd68
movq %rbx, %rdi
callq 0xfba0