// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %rsi
leaq 0x40(%rsp), %rdi
callq 0x1824e
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
callq *0x20(%rax)
movq 0x545bf(%rip), %rdi     # 0x6cfd8
movq %rsp, %rsi
callq 0xf590
leaq 0x2b6e0(%rip), %rsi     # 0x44108
movq %rax, %rdi
callq 0xf610
movl 0x340(%rbx), %esi
movq %rax, %rdi
callq 0xf480
leaq 0x2b83e(%rip), %rsi     # 0x44283
movq %rax, %rdi
callq 0xf610
movq %rax, %rdi
callq 0xf310
movq %rsp, %rdi
callq 0xfd68
leaq 0x2d0(%rbx), %r14
cmpl $-0x1, 0x2d8(%rbx)
je 0x18a77
movq %r14, %rdi
callq 0x1a430
jmp 0x18a86
leaq 0x2b0(%rbx), %rsi
movq %r14, %rdi
callq 0x1a476
movq %rsp, %rsi
movl $0x8, (%rsi)
movq %r14, %rdi
callq 0x1a4ba
movq %rsp, %rsi
andl $0x0, (%rsi)
movq %r14, %rdi
callq 0x1a4fe
movq %rsp, %rsi
andl $0x0, (%rsi)
movq %r14, %rdi
callq 0x1a542
movl 0x340(%rbx), %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movq %r14, %rdi
callq 0x1a586
movq %rsp, %rdx
andl $0x0, (%rdx)
movb $0x0, 0x4(%rdx)
leaq 0x516b9(%rip), %r13     # 0x6a190
movq %r13, 0x8(%rdx)
leaq 0x20(%rsp), %r15
movl $0x2, (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1a5ca
cmpb $0x1, 0x4(%rsp)
jne 0x18b1d
pushq $0x5f
popq %rdi
callq 0x15246
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq %rsp, %rdi
callq 0x1a5ec
testb %al, %al
jne 0x18c5f
movq 0x328(%rbx), %rax
subq 0x320(%rbx), %rax
cmpq $0x4, %rax
jbe 0x18c29
leaq 0x350(%rbx), %rdi
imulq $0xf4240, 0x348(%rbx), %rax # imm = 0xF4240
movq %rsp, %rsi
movq %rax, (%rsi)
callq 0x13964
leaq 0x28(%rsp), %rdi
movq %rbx, -0x8(%rdi)
leaq 0x40(%rsp), %rsi
callq 0x14dce
movq 0x350(%rbx), %r14
movq %r15, (%rsp)
pushq $0x70
popq %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x13dbd
movq %rax, %r15
movq %rax, 0x8(%rsp)
andq $0x0, (%rax)
leaq 0xa22(%rip), %rax       # 0x195b2
movq %rax, 0x8(%r15)
andl $0x0, 0x10(%r15)
andl $0x0, 0x18(%r15)
movb $0x0, 0x1c(%r15)
movq %r13, 0x20(%r15)
movaps 0x20(%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq 0x30(%rsp), %rax
andq $0x0, 0x30(%rsp)
movq %rax, 0x38(%r15)
andq $0x0, 0x28(%rsp)
leaq 0x390(%rbx), %rsi
leaq 0x358(%rbx), %r12
movq %r15, %rdi
addq $0x40, %rdi
callq 0x14776
movq %r15, 0x10(%rsp)
movb $0x1, 0x360(%rbx)
movq 0x58(%r14), %rdi
addq $0x28, %r14
leaq 0x368(%rbx), %rcx
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %r8
callq 0x13d28
leaq 0x8(%rsp), %rax
leaq 0x30(%rsp), %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rsp, %rdi
callq 0x195a2
movq %r14, %rdi
callq 0x14e02
movq %rbx, %rdi
callq 0x12132
movq %rsp, %rsi
andl $0x0, (%rsi)
movb $0x0, 0x4(%rsi)
movq %r13, 0x8(%rsi)
movq %rbx, %rdi
callq 0x18e7c
leaq 0x48(%rsp), %rdi
callq 0x14e02
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
pushq $0x40
popq %rdi
callq 0xf320
movq %rax, %r12
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rax, %rdi
callq 0x1a5f6
leaq 0x514e6(%rip), %rsi     # 0x6a168
leaq -0x512d(%rip), %rdx     # 0x13b5c
movq %r12, %rdi
callq 0xfb50
jmp 0x18ccf
movq %rdx, %r15
movq %rax, %r14
movq %r12, %rdi
callq 0xf4c0
jmp 0x18cd5
movq %rax, %r14
movq %rsp, %rdi
callq 0x195a2
jmp 0x18cb3
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x14e02
jmp 0x18d23
jmp 0x18d13
jmp 0x18d13
jmp 0x18d13
jmp 0x18ccf
jmp 0x18ccf
jmp 0x18ccf
jmp 0x18ccf
jmp 0x18ccf
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0x18d23
movq %r14, %rdi
callq 0xf2a0
movups 0x10(%rax), %xmm0
movq %rsp, %rsi
movups %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x18d36
callq 0xfad0
jmp 0x18c47
jmp 0x18d13
movq %rax, %r14
callq 0xfad0
jmp 0x18d23
movq %rax, %rdi
callq 0x104eb
movq %rax, %r14
jmp 0x18d23
movq %rax, %r14
movq %rsp, %rdi
callq 0xfd68
leaq 0x48(%rsp), %rdi
callq 0x14e02
movq %r14, %rdi
callq 0xfba0
nop