// File: /workspace/github_c_makefile_star2_O3/chipkin[P]Linux-HighSpeedSerialMonitor/main.cpp
// Function: main
int main(int argc, char** argv)
{
    std::cout << "FYI: High speed serail monitor. Version: " << APPLICATION_VERSION << "." << CI_PIPELINE_IID << std::endl;

    // Set up the output stream.
    ComposeStream outputStream;
    outputStream.linkStream(std::cout);

    // Open a log file
    std::ofstream outfile(CONFIGURATION_LOG_FILE, std::ios_base::app);
    outputStream.linkStream(outfile);

    // Check for command line parmeters
    uint32_t baudRate = DEFAULT_SERIAL_BAUDRATE;
    static const uint32_t MAX_COMPORT_STRING_LENGTH = 100;
    char comport[MAX_COMPORT_STRING_LENGTH];
    strncpy(comport, DEFAULT_SERIAL_PORT, MAX_COMPORT_STRING_LENGTH);

    // Check for help flag.
    for (uint32_t i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
            printHelp();
            return EXIT_SUCCESS;
        }
    }

    // Extract the command line paramters.
    if (argc == 1) {
        outputStream << "FYI: No command line parameters set. Using defaults. " << std::endl;
    }
    if (argc >= 2) {
        strncpy(comport, argv[1], 100);
    }
    if (argc >= 3) {
        baudRate = atoi(argv[2]);
    }

    // Open the serial port
    outputStream
        << "FYI: Connecting to serial port. SerialPort=" << comport << ", BaudRate=" << baudRate << std::endl;
    if (!serialConnect(comport, baudRate)) {
        outputStream << "Error: Could not connect to the serial port" << std::endl;
        return EXIT_FAILURE;
    }
    outputStream << "FYI: Connected to serial port" << std::endl
                 << std::endl;

    const uint32_t PRINT_WIDTH_TIME = 12;
    const uint32_t PRINT_WIDTH_CHAR = 10;
    const uint32_t PRINT_WIDTH_HEX = 10;

    // Print the headers
    outputStream << "|" << std::setfill(' ') << std::setw(PRINT_WIDTH_TIME) << " Time (ms) ";
    outputStream << "|" << std::setfill(' ') << std::setw(PRINT_WIDTH_CHAR) << " CHAR ";
    outputStream << "|" << std::setfill(' ') << std::setw(PRINT_WIDTH_HEX) << " HEX ";
    outputStream << "|" << std::endl;
    outputStream << "* " << std::setfill('-') << std::setw(PRINT_WIDTH_TIME + 1);
    outputStream << " * " << std::setfill('-') << std::setw(PRINT_WIDTH_CHAR + 1);
    outputStream << " * " << std::setfill('-') << std::setw(PRINT_WIDTH_HEX + 1);
    outputStream << " * " << std::endl;

    mstp_TimerReset();
    uint32_t microsecond;
    uint8_t buffer;
    for (;;) {
        if (mstp_RecvByte(&buffer)) {
            microsecond = mstp_TimerDifference();
            mstp_TimerReset();

            outputStream << "|" << std::setfill(' ') << std::setw(PRINT_WIDTH_TIME - 1) << std::fixed << std::setprecision(3) << (float)microsecond / 1000;
            outputStream << " |" << std::setfill(' ') << std::setw(PRINT_WIDTH_CHAR - 1) << buffer;
            outputStream << " |" << std::setfill(' ') << std::setw(PRINT_WIDTH_HEX - 3) << " " << std::hex << std::setw(2) << std::setfill('0') << std::uppercase << buffer;
            outputStream << " |" << std::endl;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rsi, %rbx
movl %edi, %ebp
movq 0x3911(%rip), %r14      # 0x5fd0
leaq 0x1a9d(%rip), %rsi      # 0x4163
movl $0x29, %edx
movq %r14, %rdi
callq 0x21d0
leaq 0x1b93(%rip), %rsi      # 0x426d
movl $0x5, %edx
movq %r14, %rdi
callq 0x21d0
leaq 0x1a9f(%rip), %rsi      # 0x418d
movl $0x1, %edx
movq %r14, %rdi
callq 0x21d0
movq %r14, %rdi
xorl %esi, %esi
callq 0x22a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x8(%rsp), %rdi
callq 0x2f68
movq %r14, %rdi
callq 0x2110
leaq 0x10(%rsp), %r15
movq (%r14), %rax
movq -0x18(%rax), %rax
movq 0xe8(%r14,%rax), %rsi
movq %r15, %rdi
callq 0x32fe
leaq 0x1b29(%rip), %rsi      # 0x428d
leaq 0x1d8(%rsp), %rdi
movl $0x1, %edx
callq 0x21a0
leaq 0x1d8(%rsp), %rdi
callq 0x2110
movq 0x1d8(%rsp), %rax
movq -0x18(%rax), %rax
movq 0x2c0(%rsp,%rax), %rsi
movq %r15, %rdi
callq 0x32fe
leaq 0x1b20(%rip), %rsi      # 0x42c6
leaq 0x170(%rsp), %rdi
movl $0x64, %edx
callq 0x2140
cmpl $0x2, %ebp
jb 0x27fe
movl %ebp, %r15d
movl $0x1, %r12d
leaq 0x19c2(%rip), %r14      # 0x418f
movq (%rbx,%r12,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x27e6
cmpb $0x68, 0x1(%rdi)
jne 0x27e6
cmpb $0x0, 0x2(%rdi)
je 0x2965
movq %r14, %rsi
callq 0x2200
testl %eax, %eax
je 0x2965
incq %r12
cmpq %r12, %r15
jne 0x27cd
cmpl $0x1, %ebp
jne 0x284f
leaq 0x198b(%rip), %rsi      # 0x4195
leaq 0x8(%rsp), %rbx
movl $0x35, %edx
movq %rbx, %rdi
callq 0x21d0
movq 0x8(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
leaq 0x8(%rsp), %rdi
callq 0x2030
movl $0x9600, %r14d          # imm = 0x9600
movq %rax, %rdi
callq 0x2110
jmp 0x287e
movl $0x9600, %r14d          # imm = 0x9600
jle 0x287e
movq 0x8(%rbx), %rsi
leaq 0x170(%rsp), %rdi
movl $0x64, %edx
callq 0x20d0
cmpl $0x2, %ebp
je 0x287e
movq 0x10(%rbx), %rdi
callq 0x2250
movl %eax, %r14d
leaq 0x1946(%rip), %rsi      # 0x41cb
leaq 0x8(%rsp), %rdi
movl $0x2b, %edx
callq 0x21d0
leaq 0x170(%rsp), %rbx
movq %rbx, %rdi
callq 0x20b0
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21d0
leaq 0x193c(%rip), %rsi      # 0x41f7
leaq 0x8(%rsp), %rdi
movl $0xb, %edx
callq 0x21d0
movl %r14d, %esi
leaq 0x8(%rsp), %rdi
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movzwl %r14w, %esi
leaq 0x170(%rsp), %rdi
callq 0x3464
testb %al, %al
jne 0x2a14
leaq 0x18e2(%rip), %rsi      # 0x4203
leaq 0x8(%rsp), %rbx
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x21d0
movq 0x8(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
leaq 0x8(%rsp), %rdi
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2110
jmp 0x296c
xorl %ebx, %ebx
callq 0x244c
movq 0x3655(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1e0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1d8(%rsp,%rcx)
callq 0x2150
leaq 0x2d0(%rsp), %rdi
callq 0x2070
leaq 0x32bd(%rip), %rax      # 0x5c68
leaq 0x68(%rsp), %r14
movq %rax, -0x60(%r14)
leaq 0x32d5(%rip), %rax      # 0x5c90
movq %rax, (%r14)
leaq 0x3353(%rip), %rax      # 0x5d18
movq %rax, -0x58(%r14)
movq -0x18(%r14), %rdi
testq %rdi, %rdi
je 0x29df
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x35d2(%rip), %rax      # 0x5fb8
addq $0x10, %rax
leaq 0x48(%rsp), %rdi
movq %rax, -0x38(%rdi)
callq 0x2210
movq %r14, %rdi
callq 0x2070
movl %ebx, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1814(%rip), %rsi      # 0x422f
leaq 0x8(%rsp), %rdi
movl $0x1d, %edx
callq 0x21d0
leaq 0x8(%rsp), %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x20c0
leaq 0x1828(%rip), %rsi      # 0x426b
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2a85
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xc, 0x18(%rsp,%rax)
leaq 0x17ad(%rip), %rsi      # 0x424d
leaq 0x8(%rsp), %rdi
movl $0xb, %edx
callq 0x21d0
leaq 0x17b5(%rip), %rsi      # 0x426b
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2af8
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xa, 0x18(%rsp,%rax)
leaq 0x1746(%rip), %rsi      # 0x4259
leaq 0x8(%rsp), %rdi
movl $0x6, %edx
callq 0x21d0
leaq 0x1742(%rip), %rsi      # 0x426b
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2b6b
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xa, 0x18(%rsp,%rax)
leaq 0x16da(%rip), %rsi      # 0x4260
leaq 0x8(%rsp), %rdi
movl $0x5, %edx
callq 0x21d0
leaq 0x16cf(%rip), %rsi      # 0x426b
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x21d0
leaq 0x8(%rsp), %rdi
callq 0x20c0
leaq 0x16ab(%rip), %rsi      # 0x4267
leaq 0x8(%rsp), %rdi
movl $0x2, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2bfe
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x2d, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xd, 0x18(%rsp,%rax)
leaq 0x164d(%rip), %rsi      # 0x4266
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2c5b
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x2d, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xb, 0x18(%rsp,%rax)
leaq 0x15f0(%rip), %rsi      # 0x4266
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbx
addq $0x8, %rbx
cmpb $0x0, 0xe1(%rbx)
jne 0x2cb8
movq %rbx, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbx)
movq 0x8(%rsp), %rax
movb $0x2d, 0xe0(%rbx)
movq -0x18(%rax), %rax
movq $0xb, 0x18(%rsp,%rax)
leaq 0x1593(%rip), %rsi      # 0x4266
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
callq 0x21d0
leaq 0x8(%rsp), %rdi
callq 0x20c0
callq 0x38ef
leaq 0x6(%rsp), %rbx
leaq 0x8(%rsp), %r15
leaq 0x1568(%rip), %r12      # 0x426a
leaq 0x7(%rsp), %r13
movq %rbx, %rdi
callq 0x37c4
testb %al, %al
je 0x2d07
callq 0x38fd
movl %eax, %r14d
callq 0x38ef
movl $0x1, %edx
movq %r15, %rdi
leaq 0x153c(%rip), %rsi      # 0x426b
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %rbp
addq $0x8, %rbp
cmpb $0x0, 0xe1(%rbp)
jne 0x2d67
movq %rbp, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%rbp)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%rbp)
movq -0x18(%rax), %rcx
movq $0xb, 0x18(%rsp,%rcx)
movq -0x18(%rax), %rcx
movl 0x20(%rsp,%rcx), %edx
movl $0xfffffefb, %esi       # imm = 0xFFFFFEFB
andl %esi, %edx
orl $0x4, %edx
movl %edx, 0x20(%rsp,%rcx)
movl %r14d, %ecx
cvtsi2ss %rcx, %xmm0
movq -0x18(%rax), %rax
movq $0x3, 0x10(%rsp,%rax)
divss 0x1256(%rip), %xmm0     # 0x4004
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
callq 0x2260
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %r14
addq $0x8, %r14
cmpb $0x0, 0xe1(%r14)
jne 0x2dff
movq %r14, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%r14)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x9, 0x18(%rsp,%rax)
movb 0x6(%rsp), %al
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x21d0
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %r14
addq $0x8, %r14
cmpb $0x0, 0xe1(%r14)
jne 0x2e71
movq %r14, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%r14)
movq 0x8(%rsp), %rax
movb $0x20, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x7, 0x18(%rsp,%rax)
movl $0x1, %edx
movq %r15, %rdi
leaq 0x13c2(%rip), %rsi      # 0x4257
callq 0x21d0
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rcx
movl 0x20(%rsp,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x20(%rsp,%rcx)
movq -0x18(%rax), %rcx
movq $0x2, 0x18(%rsp,%rcx)
movq -0x18(%rax), %rcx
leaq (%rsp,%rcx), %r14
addq $0x8, %r14
cmpb $0x0, 0xe1(%r14)
jne 0x2eee
movq %r14, %rdi
movl $0x20, %esi
callq 0x2170
movb $0x1, 0xe1(%r14)
movq 0x8(%rsp), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
orl $0x4000, 0x20(%rsp,%rax) # imm = 0x4000
movb 0x6(%rsp), %al
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x21d0
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x20c0
jmp 0x2d07
jmp 0x2f46
jmp 0x2f46
jmp 0x2f46
jmp 0x2f41
jmp 0x2f46
movq %rax, %rbx
jmp 0x2f56
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x2230
leaq 0x8(%rsp), %rdi
callq 0x305a
movq %rbx, %rdi
callq 0x22c0