// File: /workspace/github_cpp_makefile_star2_O3/flightaware[P]beast-splitter/beast_output.cc
// Function: beast::SocketOutput::write_message(modes::MessageType, modes::TimestampType, unsigned long, unsigned char, std::vector<unsigned char, std::allocator<unsigned char>> const&)
void SocketOutput::write_message(modes::MessageType type, modes::TimestampType timestamp_type, std::uint64_t timestamp, std::uint8_t signal, const helpers::bytebuf &data) {
        if (timestamp_type == modes::TimestampType::TWELVEMEG && !settings.radarcape.off() && settings.gps_timestamps.on()) {
            // GPS timestamps were explicitly requested
            // scale 12MHz to pseudo-GPS
            std::uint64_t ns = timestamp * 1000ULL / 12ULL;
            std::uint64_t seconds = (ns / 1000000000ULL) % 86400;
            std::uint64_t nanos = ns % 1000000000ULL;
            timestamp = (seconds << 30) | nanos;
        } else if (timestamp_type == modes::TimestampType::GPS && (settings.radarcape.off() || settings.gps_timestamps.off())) {
            // beast output or 12MHz timestamps were explicitly requested
            // scale GPS to 12MHz
            std::uint64_t seconds = timestamp >> 30;
            std::uint64_t nanos = timestamp & 0x3FFFFFFF;
            std::uint64_t ns = seconds * 1000000000ULL + nanos;
            timestamp = ns * 12ULL / 1000ULL;
        }

        // if gps_timestamps is DONTCARE, we just use whatever is provided

        if (settings.binary_format) {
            write_binary(type, timestamp, signal, data);
        } else if (settings.avrmlat) {
            if (type != modes::MessageType::STATUS && type != modes::MessageType::POSITION)
                write_avrmlat(timestamp, data);
        } else {
            if (type != modes::MessageType::STATUS && type != modes::MessageType::POSITION)
                write_avr(data);
        }
    }

// Assembly:
cmpl $0x2, %edx
je 0x2460f
cmpl $0x1, %edx
jne 0x24652
cmpl $0x0, 0x90(%rdi)
js 0x24652
cmpl $0x0, 0xa4(%rdi)
jle 0x24652
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
movq %rcx, %rax
mulq %rdx
movq %rdx, %r10
shrq $0x3, %r10
movabsq $-0x48bf80fe61b9cde1, %rdx # imm = 0xB7407F019E46321F
movq %rcx, %rax
mulq %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
movl $0xc22e4507, %eax       # imm = 0xC22E4507
imulq %rcx, %rax
shrq $0x30, %rax
imull $0x15180, %eax, %eax    # imm = 0x15180
subl %eax, %ecx
movabsq $0x112e0be826d694b3, %rdx # imm = 0x112E0BE826D694B3
movq %r10, %rax
mulq %rdx
shrq $0x1a, %rdx
imulq $0x3b9aca00, %rdx, %rax # imm = 0x3B9ACA00
subq %rax, %r10
shlq $0x1e, %rcx
orq %r10, %rcx
jmp 0x24652
cmpl $0x0, 0x90(%rdi)
js 0x24621
cmpl $0x0, 0xa4(%rdi)
jns 0x24652
movq %rcx, %rax
shrq $0x1e, %rax
imulq $-0x4653600, %rax, %rax # imm = 0xFB9ACA00
addq %rcx, %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
shrq $0x4, %rcx
cmpl $0x0, 0x94(%rdi)
js 0x2466c
movzbl %r8b, %eax
movq %rcx, %rdx
movl %eax, %ecx
movq %r9, %r8
jmp 0x24696
addl $-0x6, %esi
cmpl $0x0, 0x9c(%rdi)
js 0x24688
cmpl $-0x3, %esi
ja 0x24695
movq %rcx, %rsi
movq %r9, %rdx
jmp 0x2497c
cmpl $-0x3, %esi
ja 0x24695
movq %r9, %rsi
jmp 0x24c20
retq