// File: 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 %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpl $0x4, 0x240(%rax)
jne 0x1da31
movq -0x128(%rbp), %rdi
addq $0x260, %rdi            # imm = 0x260
xorl %eax, %eax
movl %eax, %esi
callq 0x144d0
leaq -0x38(%rbp), %rdi
movzbl (%rax), %esi
callq 0x19910
leaq -0x38(%rbp), %rdi
addq $0x14, %rdi
callq 0x1c790
movb %al, %cl
movq -0x128(%rbp), %rax
andb $0x1, %cl
movb %cl, 0xdb(%rax)
cmpl $0x2, 0x50(%rax)
je 0x1d965
movq -0x128(%rbp), %rdi
movl $0x2, 0x50(%rdi)
addq $0xe0, %rdi
callq 0x212e0
movq -0x128(%rbp), %rdi
callq 0x1cf20
movq -0x128(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %rdi
callq 0x212b0
movq -0x128(%rbp), %rsi
movq %rsi, %rax
addq $0x1c0, %rax            # imm = 0x1C0
movq %rax, -0x130(%rbp)
addq $0x28, %rsi
leaq -0x50(%rbp), %rdi
callq 0x213c0
jmp 0x1d99f
movq -0x130(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x21350
jmp 0x1d9b1
movq -0x128(%rbp), %rax
movq %rax, %rcx
addq $0x1c0, %rcx            # imm = 0x1C0
movq %rcx, -0x138(%rbp)
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x21400
movq -0x138(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1de70
jmp 0x1d9ec
leaq -0x78(%rbp), %rdi
callq 0x1dea0
leaq -0x48(%rbp), %rdi
callq 0x21430
jmp 0x1da31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1da23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x1dea0
leaq -0x48(%rbp), %rdi
callq 0x21430
jmp 0x1de0c
movq -0x128(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0x1da47
jmp 0x1ddeb
movq -0x128(%rbp), %rax
testb $0x1, 0x23c(%rax)
je 0x1db48
movq -0x128(%rbp), %rsi
movb $0x0, 0x23c(%rsi)
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq -0x98(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq *%rax
movq -0x148(%rbp), %rsi
movq 0xed54a(%rip), %rdi     # 0x10afd8
callq 0x12770
movq %rax, -0x140(%rbp)
jmp 0x1da9c
movq -0x140(%rbp), %rdi
leaq 0x95840(%rip), %rsi     # 0xb32ea
callq 0x12800
movq %rax, -0x150(%rbp)
jmp 0x1dab8
movq -0x150(%rbp), %rdi
movq -0x128(%rbp), %rax
movl 0x50(%rax), %eax
subl $0x2, %eax
leaq 0x95829(%rip), %rax     # 0xb32fc
leaq 0x98490(%rip), %rsi     # 0xb5f6a
cmoveq %rax, %rsi
callq 0x12800
movq %rax, -0x158(%rbp)
jmp 0x1daec
movq -0x158(%rbp), %rdi
leaq 0x9580c(%rip), %rsi     # 0xb3306
callq 0x12800
movq %rax, -0x160(%rbp)
jmp 0x1db08
movq -0x160(%rbp), %rdi
movq 0xed402(%rip), %rsi     # 0x10af18
callq 0x128b0
jmp 0x1db1d
leaq -0x98(%rbp), %rdi
callq 0x13198
jmp 0x1db48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x13198
jmp 0x1de0c
movq -0x128(%rbp), %rdi
addq $0x30, %rdi
callq 0x17b10
testb $0x1, %al
jne 0x1db61
jmp 0x1ddeb
movq -0x128(%rbp), %rax
movq $0x0, -0xa0(%rbp)
movb $0x0, -0xa1(%rbp)
cmpl $0x5, 0x240(%rax)
jne 0x1dc25
movq -0x128(%rbp), %rdi
movq %rdi, %rax
addq $0x260, %rax            # imm = 0x260
movq %rax, -0x168(%rbp)
addq $0x260, %rdi            # imm = 0x260
callq 0x1c410
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x21830
movq -0x128(%rbp), %rdi
addq $0x248, %rdi            # imm = 0x248
callq 0x21870
movq -0x128(%rbp), %rdi
movq %rax, -0xc0(%rbp)
addq $0x248, %rdi            # imm = 0x248
callq 0x218a0
movq -0x168(%rbp), %rdi
movq %rax, -0xc8(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
callq 0x21780
movq %rax, -0xd0(%rbp)
jmp 0x1dd65
movq -0x128(%rbp), %rdi
addq $0x248, %rdi            # imm = 0x248
xorl %eax, %eax
movl %eax, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movzbl (%rax), %eax
shlq $0x28, %rax
movq %rax, -0x190(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x1, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x190(%rbp), %rax
movzbl (%rcx), %ecx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, -0x188(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x2, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x188(%rbp), %rax
movzbl (%rcx), %ecx
shlq $0x18, %rcx
orq %rcx, %rax
movq %rax, -0x180(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x3, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x180(%rbp), %rax
movzbl (%rcx), %ecx
shlq $0x10, %rcx
orq %rcx, %rax
movq %rax, -0x178(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x4, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x178(%rbp), %rax
movzbl (%rcx), %ecx
shlq $0x8, %rcx
orq %rcx, %rax
movq %rax, -0x170(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x5, %esi
callq 0x144d0
movq -0x128(%rbp), %rdi
movq %rax, %rcx
movq -0x170(%rbp), %rax
movzbl (%rcx), %ecx
orq %rcx, %rax
movq %rax, -0xa0(%rbp)
addq $0x248, %rdi            # imm = 0x248
movl $0x6, %esi
callq 0x144d0
movb (%rax), %al
movb %al, -0xa1(%rbp)
movq -0x128(%rbp), %r9
movq %r9, %rax
addq $0x30, %rax
movq %rax, -0x1a0(%rbp)
movl 0x240(%r9), %esi
movzbl 0xdb(%r9), %edx
andl $0x1, %edx
incl %edx
movq -0xa0(%rbp), %rcx
movzbl -0xa1(%rbp), %r8d
addq $0x260, %r9             # imm = 0x260
leaq -0x120(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x218d0
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rsi
callq 0x17710
jmp 0x1ddcc
leaq -0x120(%rbp), %rdi
callq 0x21990
movq -0x128(%rbp), %rdi
addq $0x260, %rdi            # imm = 0x260
callq 0x21600
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x21990
movq -0x58(%rbp), %rdi
callq 0x12f70
nopw %cs:(%rax,%rax)