// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x50726
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
callq 0x1b300
testb $0x1, %al
jne 0x50726
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
addq $0x14, %rdi
callq 0x1c790
testb $0x1, %al
jne 0x506d0
jmp 0x50726
imulq $0x3e8, -0x18(%rbp), %rax # imm = 0x3E8
movl $0xc, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
xorl %edx, %edx
divq %rcx
movl $0x15180, %ecx          # imm = 0x15180
xorl %edx, %edx
divq %rcx
movq %rdx, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
xorl %edx, %edx
divq %rcx
movq %rdx, -0x40(%rbp)
movq -0x38(%rbp), %rax
shlq $0x1e, %rax
orq -0x40(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x50799
cmpl $0x2, -0x10(%rbp)
jne 0x50797
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
callq 0x1b300
testb $0x1, %al
jne 0x5075a
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
addq $0x14, %rdi
callq 0x1b850
testb $0x1, %al
jne 0x5075a
jmp 0x50797
movq -0x18(%rbp), %rax
shrq $0x1e, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movq %rax, -0x50(%rbp)
imulq $0x3b9aca00, -0x48(%rbp), %rax # imm = 0x3B9ACA00
addq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
imulq $0xc, -0x58(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, -0x18(%rbp)
jmp 0x50799
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
addq $0x4, %rdi
callq 0x1b5d0
testb $0x1, %al
jne 0x507b3
jmp 0x507cf
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
movb -0x19(%rbp), %al
movq -0x28(%rbp), %r8
movzbl %al, %ecx
callq 0x50830
jmp 0x50825
movq -0x60(%rbp), %rdi
addq $0x90, %rdi
addq $0xc, %rdi
callq 0x1b650
testb $0x1, %al
jne 0x507e9
jmp 0x50808
cmpl $0x4, -0xc(%rbp)
je 0x50806
cmpl $0x5, -0xc(%rbp)
je 0x50806
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x50a40
jmp 0x50823
cmpl $0x4, -0xc(%rbp)
je 0x50821
cmpl $0x5, -0xc(%rbp)
je 0x50821
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x50c30
jmp 0x50823
jmp 0x50825
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)