// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x680, %rsp            # imm = 0x680
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x59b0(%rip), %rdi      # 0x7fd0
movq %rdi, -0x468(%rbp)
leaq 0x2b1d(%rip), %rsi      # 0x514b
callq 0x2170
movq %rax, %rdi
movq 0x5b6b(%rip), %rsi      # 0x81a8
callq 0x2170
movq %rax, %rdi
leaq 0x2b29(%rip), %rsi      # 0x5175
callq 0x2170
movq %rax, %rdi
xorl %esi, %esi
callq 0x22d0
movq %rax, %rdi
movq 0x595b(%rip), %rsi      # 0x7fc0
callq 0x21a0
leaq -0x178(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x3140
movq -0x470(%rbp), %rdi
movq -0x468(%rbp), %rsi
callq 0x3220
jmp 0x2692
movq 0x5b17(%rip), %rsi      # 0x81b0
leaq -0x388(%rbp), %rdi
movl $0x1, %edx
callq 0x21b0
jmp 0x26ac
leaq -0x178(%rbp), %rdi
leaq -0x388(%rbp), %rsi
callq 0x3220
jmp 0x26c1
movl $0x9600, -0x38c(%rbp)   # imm = 0x9600
leaq -0x3f0(%rbp), %rdi
movq 0x5adf(%rip), %rsi      # 0x81b8
movl $0x64, %edx
callq 0x20e0
movl $0x1, -0x3f4(%rbp)
movl -0x3f4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jae 0x27a7
movq -0x10(%rbp), %rax
movl -0x3f4(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x2a66(%rip), %rsi      # 0x5177
callq 0x2210
cmpl $0x0, %eax
je 0x273a
movq -0x10(%rbp), %rax
movl -0x3f4(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x2a4a(%rip), %rsi      # 0x517a
callq 0x2210
cmpl $0x0, %eax
jne 0x2791
callq 0x24b0
jmp 0x2741
movl $0x0, -0x4(%rbp)
movl $0x1, -0x3f8(%rbp)
jmp 0x30f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
jmp 0x311b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
leaq -0x388(%rbp), %rdi
callq 0x2240
jmp 0x311b
jmp 0x2793
movl -0x3f4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3f4(%rbp)
jmp 0x26ed
cmpl $0x1, -0x8(%rbp)
jne 0x27e0
leaq 0x29cc(%rip), %rsi      # 0x5180
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x478(%rbp)
jmp 0x27c9
movq -0x478(%rbp), %rdi
movq 0x57e9(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x27de
jmp 0x27e0
cmpl $0x2, -0x8(%rbp)
jl 0x27ff
leaq -0x3f0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movl $0x64, %edx
callq 0x20e0
cmpl $0x3, -0x8(%rbp)
jl 0x2818
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2270
movl %eax, -0x38c(%rbp)
leaq 0x2997(%rip), %rsi      # 0x51b6
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x480(%rbp)
jmp 0x2834
movq -0x480(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x2170
movq %rax, -0x488(%rbp)
jmp 0x2850
movq -0x488(%rbp), %rdi
leaq 0x2984(%rip), %rsi      # 0x51e2
callq 0x2170
movq %rax, -0x490(%rbp)
jmp 0x286c
movq -0x490(%rbp), %rdi
movl -0x38c(%rbp), %esi
callq 0x2200
movq %rax, -0x498(%rbp)
jmp 0x2887
movq -0x498(%rbp), %rdi
movq 0x572b(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x289c
movzwl -0x38c(%rbp), %esi
leaq -0x3f0(%rbp), %rdi
callq 0x4490
movb %al, -0x499(%rbp)
jmp 0x28b7
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x290a
jmp 0x28c3
leaq 0x2924(%rip), %rsi      # 0x51ee
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x4a8(%rbp)
jmp 0x28df
movq -0x4a8(%rbp), %rdi
movq 0x56d3(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x28f4
movl $0x1, -0x4(%rbp)
movl $0x1, -0x3f8(%rbp)
jmp 0x30f7
leaq 0x2909(%rip), %rsi      # 0x521a
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x4b0(%rbp)
jmp 0x2926
movq -0x4b0(%rbp), %rdi
movq 0x568c(%rip), %rsi      # 0x7fc0
callq 0x21a0
movq %rax, -0x4b8(%rbp)
jmp 0x2942
movq -0x4b8(%rbp), %rdi
movq 0x5670(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x2957
movl $0xc, -0x3fc(%rbp)
movl $0xa, -0x400(%rbp)
movl $0xa, -0x404(%rbp)
leaq 0x28da(%rip), %rsi      # 0x5256
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x4c0(%rbp)
jmp 0x2991
movl $0x20, %edi
callq 0x3270
movb %al, -0x4c1(%rbp)
jmp 0x29a3
movq -0x4c0(%rbp), %rdi
movb -0x4c1(%rbp), %al
movb %al, -0x405(%rbp)
movzbl -0x405(%rbp), %esi
callq 0x2280
movq %rax, -0x4d0(%rbp)
jmp 0x29cb
movl $0xc, %edi
callq 0x3290
movl %eax, -0x4d4(%rbp)
jmp 0x29dd
movq -0x4d0(%rbp), %rdi
movl -0x4d4(%rbp), %eax
movl %eax, -0x40c(%rbp)
movl -0x40c(%rbp), %esi
callq 0x21e0
movq %rax, -0x4e0(%rbp)
jmp 0x2a04
movq -0x4e0(%rbp), %rdi
leaq 0x2826(%rip), %rsi      # 0x5238
callq 0x2170
jmp 0x2a19
leaq 0x2836(%rip), %rsi      # 0x5256
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x4e8(%rbp)
jmp 0x2a35
movl $0x20, %edi
callq 0x3270
movb %al, -0x4e9(%rbp)
jmp 0x2a47
movq -0x4e8(%rbp), %rdi
movb -0x4e9(%rbp), %al
movb %al, -0x40d(%rbp)
movzbl -0x40d(%rbp), %esi
callq 0x2280
movq %rax, -0x4f8(%rbp)
jmp 0x2a6f
movl $0xa, %edi
callq 0x3290
movl %eax, -0x4fc(%rbp)
jmp 0x2a81
movq -0x4f8(%rbp), %rdi
movl -0x4fc(%rbp), %eax
movl %eax, -0x414(%rbp)
movl -0x414(%rbp), %esi
callq 0x21e0
movq %rax, -0x508(%rbp)
jmp 0x2aa8
movq -0x508(%rbp), %rdi
leaq 0x278e(%rip), %rsi      # 0x5244
callq 0x2170
jmp 0x2abd
leaq 0x2792(%rip), %rsi      # 0x5256
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x510(%rbp)
jmp 0x2ad9
movl $0x20, %edi
callq 0x3270
movb %al, -0x511(%rbp)
jmp 0x2aeb
movq -0x510(%rbp), %rdi
movb -0x511(%rbp), %al
movb %al, -0x415(%rbp)
movzbl -0x415(%rbp), %esi
callq 0x2280
movq %rax, -0x520(%rbp)
jmp 0x2b13
movl $0xa, %edi
callq 0x3290
movl %eax, -0x524(%rbp)
jmp 0x2b25
movq -0x520(%rbp), %rdi
movl -0x524(%rbp), %eax
movl %eax, -0x41c(%rbp)
movl -0x41c(%rbp), %esi
callq 0x21e0
movq %rax, -0x530(%rbp)
jmp 0x2b4c
movq -0x530(%rbp), %rdi
leaq 0x26f1(%rip), %rsi      # 0x524b
callq 0x2170
jmp 0x2b61
leaq 0x26ee(%rip), %rsi      # 0x5256
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x538(%rbp)
jmp 0x2b7d
movq -0x538(%rbp), %rdi
movq 0x5435(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x2b92
leaq 0x26b9(%rip), %rsi      # 0x5252
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x540(%rbp)
jmp 0x2bae
movl $0x2d, %edi
callq 0x3270
movb %al, -0x541(%rbp)
jmp 0x2bc0
movq -0x540(%rbp), %rdi
movb -0x541(%rbp), %al
movb %al, -0x41d(%rbp)
movzbl -0x41d(%rbp), %esi
callq 0x2280
movq %rax, -0x550(%rbp)
jmp 0x2be8
movl $0xd, %edi
callq 0x3290
movl %eax, -0x554(%rbp)
jmp 0x2bfa
movq -0x550(%rbp), %rdi
movl -0x554(%rbp), %eax
movl %eax, -0x424(%rbp)
movl -0x424(%rbp), %esi
callq 0x21e0
jmp 0x2c1a
leaq 0x2630(%rip), %rsi      # 0x5251
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x560(%rbp)
jmp 0x2c36
movl $0x2d, %edi
callq 0x3270
movb %al, -0x561(%rbp)
jmp 0x2c48
movq -0x560(%rbp), %rdi
movb -0x561(%rbp), %al
movb %al, -0x425(%rbp)
movzbl -0x425(%rbp), %esi
callq 0x2280
movq %rax, -0x570(%rbp)
jmp 0x2c70
movl $0xb, %edi
callq 0x3290
movl %eax, -0x574(%rbp)
jmp 0x2c82
movq -0x570(%rbp), %rdi
movl -0x574(%rbp), %eax
movl %eax, -0x42c(%rbp)
movl -0x42c(%rbp), %esi
callq 0x21e0
jmp 0x2ca2
leaq 0x25a8(%rip), %rsi      # 0x5251
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x580(%rbp)
jmp 0x2cbe
movl $0x2d, %edi
callq 0x3270
movb %al, -0x581(%rbp)
jmp 0x2cd0
movq -0x580(%rbp), %rdi
movb -0x581(%rbp), %al
movb %al, -0x42d(%rbp)
movzbl -0x42d(%rbp), %esi
callq 0x2280
movq %rax, -0x590(%rbp)
jmp 0x2cf8
movl $0xb, %edi
callq 0x3290
movl %eax, -0x594(%rbp)
jmp 0x2d0a
movq -0x590(%rbp), %rdi
movl -0x594(%rbp), %eax
movl %eax, -0x434(%rbp)
movl -0x434(%rbp), %esi
callq 0x21e0
jmp 0x2d2a
leaq 0x2520(%rip), %rsi      # 0x5251
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x5a0(%rbp)
jmp 0x2d46
movq -0x5a0(%rbp), %rdi
movq 0x526c(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x2d5b
callq 0x4880
jmp 0x2d62
jmp 0x2d64
leaq -0x439(%rbp), %rdi
callq 0x4710
movb %al, -0x5a1(%rbp)
jmp 0x2d78
movb -0x5a1(%rbp), %al
testb $0x1, %al
jne 0x2d87
jmp 0x30f2
callq 0x48a0
movl %eax, -0x5a8(%rbp)
jmp 0x2d94
movl -0x5a8(%rbp), %eax
movl %eax, -0x438(%rbp)
callq 0x4880
jmp 0x2da7
leaq 0x24a8(%rip), %rsi      # 0x5256
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x5b0(%rbp)
jmp 0x2dc3
movl $0x20, %edi
callq 0x3270
movb %al, -0x5b1(%rbp)
jmp 0x2dd5
movq -0x5b0(%rbp), %rdi
movb -0x5b1(%rbp), %al
movb %al, -0x43a(%rbp)
movzbl -0x43a(%rbp), %esi
callq 0x2280
movq %rax, -0x5c0(%rbp)
jmp 0x2dfd
movl $0xb, %edi
callq 0x3290
movl %eax, -0x5c4(%rbp)
jmp 0x2e0f
movq -0x5c0(%rbp), %rdi
movl -0x5c4(%rbp), %eax
movl %eax, -0x440(%rbp)
movl -0x440(%rbp), %esi
callq 0x21e0
movq %rax, -0x5d0(%rbp)
jmp 0x2e36
movq -0x5d0(%rbp), %rdi
leaq 0x46c(%rip), %rsi       # 0x32b0
callq 0x2080
movq %rax, -0x5d8(%rbp)
jmp 0x2e52
movl $0x3, %edi
callq 0x32e0
movl %eax, -0x5dc(%rbp)
jmp 0x2e64
movq -0x5d8(%rbp), %rdi
movl -0x5dc(%rbp), %eax
movl %eax, -0x444(%rbp)
movl -0x444(%rbp), %esi
callq 0x2290
movq %rax, -0x5e8(%rbp)
jmp 0x2e8b
movq -0x5e8(%rbp), %rdi
movl -0x438(%rbp), %eax
cvtsi2ss %rax, %xmm0
movss 0x215f(%rip), %xmm1     # 0x5004
divss %xmm1, %xmm0
callq 0x2130
jmp 0x2eb0
leaq 0x239e(%rip), %rsi      # 0x5255
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x5f0(%rbp)
jmp 0x2ecc
movl $0x20, %edi
callq 0x3270
movb %al, -0x5f1(%rbp)
jmp 0x2ede
movq -0x5f0(%rbp), %rdi
movb -0x5f1(%rbp), %al
movb %al, -0x445(%rbp)
movzbl -0x445(%rbp), %esi
callq 0x2280
movq %rax, -0x600(%rbp)
jmp 0x2f06
movl $0x9, %edi
callq 0x3290
movl %eax, -0x604(%rbp)
jmp 0x2f18
movq -0x600(%rbp), %rdi
movl -0x604(%rbp), %eax
movl %eax, -0x44c(%rbp)
movl -0x44c(%rbp), %esi
callq 0x21e0
movq %rax, -0x610(%rbp)
jmp 0x2f3f
movq -0x610(%rbp), %rdi
movzbl -0x439(%rbp), %esi
callq 0x2250
jmp 0x2f54
leaq 0x22fa(%rip), %rsi      # 0x5255
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x618(%rbp)
jmp 0x2f70
movl $0x20, %edi
callq 0x3270
movb %al, -0x619(%rbp)
jmp 0x2f82
movq -0x618(%rbp), %rdi
movb -0x619(%rbp), %al
movb %al, -0x44d(%rbp)
movzbl -0x44d(%rbp), %esi
callq 0x2280
movq %rax, -0x628(%rbp)
jmp 0x2faa
movl $0x7, %edi
callq 0x3290
movl %eax, -0x62c(%rbp)
jmp 0x2fbc
movq -0x628(%rbp), %rdi
movl -0x62c(%rbp), %eax
movl %eax, -0x454(%rbp)
movl -0x454(%rbp), %esi
callq 0x21e0
movq %rax, -0x638(%rbp)
jmp 0x2fe3
movq -0x638(%rbp), %rdi
leaq 0x2251(%rip), %rsi      # 0x5242
callq 0x2170
movq %rax, -0x640(%rbp)
jmp 0x2fff
movq -0x640(%rbp), %rdi
leaq 0x2f3(%rip), %rsi       # 0x3300
callq 0x2080
movq %rax, -0x648(%rbp)
jmp 0x301b
movl $0x2, %edi
callq 0x3290
movl %eax, -0x64c(%rbp)
jmp 0x302d
movq -0x648(%rbp), %rdi
movl -0x64c(%rbp), %eax
movl %eax, -0x458(%rbp)
movl -0x458(%rbp), %esi
callq 0x21e0
movq %rax, -0x658(%rbp)
jmp 0x3054
movl $0x30, %edi
callq 0x3270
movb %al, -0x659(%rbp)
jmp 0x3066
movq -0x658(%rbp), %rdi
movb -0x659(%rbp), %al
movb %al, -0x459(%rbp)
movzbl -0x459(%rbp), %esi
callq 0x2280
movq %rax, -0x668(%rbp)
jmp 0x308e
movq -0x668(%rbp), %rdi
leaq 0x294(%rip), %rsi       # 0x3330
callq 0x2080
movq %rax, -0x670(%rbp)
jmp 0x30aa
movq -0x670(%rbp), %rdi
movzbl -0x439(%rbp), %esi
callq 0x2250
jmp 0x30bf
leaq 0x218f(%rip), %rsi      # 0x5255
leaq -0x178(%rbp), %rdi
callq 0x2170
movq %rax, -0x678(%rbp)
jmp 0x30db
movq -0x678(%rbp), %rdi
movq 0x4ed7(%rip), %rsi      # 0x7fc0
callq 0x21a0
jmp 0x30f0
jmp 0x30f2
jmp 0x2d64
leaq -0x388(%rbp), %rdi
callq 0x2240
leaq -0x178(%rbp), %rdi
callq 0x3360
movl -0x4(%rbp), %eax
addq $0x680, %rsp            # imm = 0x680
popq %rbp
retq
leaq -0x178(%rbp), %rdi
callq 0x3360
movq -0x180(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)
nopl (%rax)