// File: flightaware[P]beast-splitter/beast_input_serial.cc
// Function: beast::SerialInput::try_to_connect()
void SerialInput::try_to_connect(void) {
    auto self(shared_from_this());

    std::cerr << what() << ": opening port at " << baud_rate << "bps" << std::endl;

    try {
        if (port.is_open())
            port.cancel();
        else
            port.open(path);

        port.set_option(boost::asio::serial_port_base::character_size(8));
        port.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
        port.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none));
        port.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));

        // not_supported usually means a library build problem, ignore that
        boost::system::error_code ec;
        port.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::hardware), ec);
        if (ec && ec != boost::asio::error::operation_not_supported) {
            throw boost::system::system_error(ec);
        }
    } catch (const boost::system::system_error &err) {
        handle_error(err.code());
        return;
    }

    if (autobaud_rates.size() > 1) {
        autobaud_timer.expires_from_now(autobaud_interval);

        autobaud_timer.async_wait([this, self](const boost::system::error_code &ec) {
            if (!ec) {
                advance_autobaud();
            }
        });
    }

    connection_established();
    start_reading();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0xf8(%rbp)
addq $0x8, %rsi
leaq -0x18(%rbp), %rdi
callq 0x212b0
movq -0xf8(%rbp), %rsi
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq -0x38(%rbp), %rdi
callq *%rax
jmp 0x35cfd
movq 0xd52d4(%rip), %rdi     # 0x10afd8
leaq -0x38(%rbp), %rsi
callq 0x12770
movq %rax, -0x100(%rbp)
jmp 0x35d16
movq -0x100(%rbp), %rdi
leaq 0x7e5d4(%rip), %rsi     # 0xb42f8
callq 0x12800
movq %rax, -0x108(%rbp)
jmp 0x35d32
movq -0x108(%rbp), %rdi
movq -0xf8(%rbp), %rax
movl 0x340(%rax), %esi
callq 0x12b90
movq %rax, -0x110(%rbp)
jmp 0x35d54
movq -0x110(%rbp), %rdi
leaq 0x7e711(%rip), %rsi     # 0xb4473
callq 0x12800
movq %rax, -0x118(%rbp)
jmp 0x35d70
movq -0x118(%rbp), %rdi
movq 0xd519a(%rip), %rsi     # 0x10af18
callq 0x128b0
jmp 0x35d85
leaq -0x38(%rbp), %rdi
callq 0x13198
movq -0xf8(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
callq 0x3a780
movb %al, -0x119(%rbp)
jmp 0x35da9
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x35db5
jmp 0x35e08
movq -0xf8(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
callq 0x3a7c0
jmp 0x35dca
jmp 0x35e29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x361c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x13198
jmp 0x361c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x36029
movq -0xf8(%rbp), %rsi
movq %rsi, %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
addq $0x2b0, %rsi            # imm = 0x2B0
callq 0x3a830
jmp 0x35e27
jmp 0x35e29
movq -0xf8(%rbp), %rax
addq $0x2d0, %rax            # imm = 0x2D0
movq %rax, -0x128(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x8, %esi
callq 0x3a910
jmp 0x35e4d
movq -0x128(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3a8a0
jmp 0x35e5f
movq -0xf8(%rbp), %rax
addq $0x2d0, %rax            # imm = 0x2D0
movq %rax, -0x130(%rbp)
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
callq 0x3a9f0
jmp 0x35e80
movq -0x130(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x3a980
jmp 0x35e92
movq -0xf8(%rbp), %rax
addq $0x2d0, %rax            # imm = 0x2D0
movq %rax, -0x138(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x3aad0
jmp 0x35eb3
movq -0x138(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3aa60
jmp 0x35ec5
movq -0xf8(%rbp), %rax
movq %rax, %rcx
addq $0x2d0, %rcx            # imm = 0x2D0
movq %rcx, -0x140(%rbp)
movl 0x340(%rax), %esi
leaq -0x54(%rbp), %rdi
callq 0x3abb0
jmp 0x35eee
movq -0x140(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x3ab40
jmp 0x35f00
leaq -0x68(%rbp), %rdi
callq 0x26710
movq -0xf8(%rbp), %rax
addq $0x2d0, %rax            # imm = 0x2D0
movq %rax, -0x148(%rbp)
leaq -0x6c(%rbp), %rdi
movl $0x2, %esi
callq 0x3ac40
jmp 0x35f2d
movq -0x148(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3abd0
movq %rdx, -0x158(%rbp)
movq %rax, -0x150(%rbp)
jmp 0x35f51
movq -0x158(%rbp), %rax
movq -0x150(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x262b0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x159(%rbp)
jne 0x35f81
jmp 0x35fac
leaq -0x90(%rbp), %rdi
movl $0x5f, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3ace0
leaq -0x68(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3acb0
movb %al, -0x159(%rbp)
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0x35fbb
jmp 0x36089
movl $0x40, %edi
callq 0x12430
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x168(%rbp)
movups -0x68(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x3ad40
jmp 0x35ff2
movq -0x168(%rbp), %rdi
leaq 0xd1d48(%rip), %rsi     # 0x107d48
leaq -0x140b7(%rip), %rdx    # 0x21f50
callq 0x12ee0
jmp 0x361de
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x12650
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x361c4
movq -0x40(%rbp), %rdi
callq 0x12380
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x3ada0
movq -0xf8(%rbp), %rdi
movq %rax, -0xb8(%rbp)
movq %rdx, -0xb0(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x361e0
jmp 0x36078
movl $0x1, -0xbc(%rbp)
callq 0x12e40
jmp 0x3609e
jmp 0x360a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x12e40
jmp 0x360a3
jmp 0x361b2
jmp 0x361c4
movq -0xf8(%rbp), %rdi
addq $0x320, %rdi            # imm = 0x320
callq 0x3adc0
cmpq $0x1, %rax
jbe 0x36172
movq -0xf8(%rbp), %rsi
movq %rsi, %rax
addq $0x350, %rax            # imm = 0x350
movq %rax, -0x170(%rbp)
addq $0x348, %rsi            # imm = 0x348
leaq -0xc8(%rbp), %rdi
callq 0x213c0
jmp 0x360f1
movq -0x170(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x21350
jmp 0x36106
movq -0xf8(%rbp), %rax
movq %rax, %rcx
addq $0x350, %rcx            # imm = 0x350
movq %rcx, -0x178(%rbp)
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x21400
movq -0x178(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x36410
jmp 0x3614a
leaq -0xe0(%rbp), %rdi
callq 0x36440
jmp 0x36172
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x36440
jmp 0x361c4
movq -0xf8(%rbp), %rdi
callq 0x1ccf0
jmp 0x36180
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x26710
movq -0xf8(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x36460
jmp 0x361a8
movl $0x0, -0xbc(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x21430
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x18(%rbp), %rdi
callq 0x21430
movq -0x40(%rbp), %rdi
callq 0x12f70
movq %rax, %rdi
callq 0x148f0
nop