// File: /workspace/github_c_makefile_star2_O2/patriciogonzalezvivo[P]tprint/src/main.cpp
// Function: main
int main(int argc, char **argv){

    //  Get a list of ports
#ifdef PLATFORM_RPI
    std::string port = "/dev/ttyAMA0";
#else
    std::string port = "NONE";
#endif

    std::vector<serial::PortInfo> ports = serial::list_ports();
    for (uint i = 0; i < ports.size(); i++){
        // std::cout << ports[i].port << " - " << ports[i].description << " - " << ports[i].hardware_id << std::endl;
        std::string::size_type found = ports[i].description.find("Prolific Technology Inc. USB-Serial Controller");
        if (found != std::string::npos){
            port = ports[i].port;
            break;
        }
    }

    // Contect the printer to the port
    std::cout << "Connecting to port [" << port << "] ";
    if (printer.open(port)){
        printer.setControlParameter(7, 100, 2);
        printer.setAlign(LEFT);
        std::cout << "successfully."<< std::endl;
    } else {
        std::cout << "error."<< std::endl;
        return 0;
    }

    // Load files to watch

    if (argc == 1) {
        std::string line;
        while (std::getline(std::cin, line)){
            printer.print(line+"\n");
        }
    } else {
        for (int i = 1; i < argc ; i++){
            std::string argument = std::string(argv[i]);
            if (    haveExt(argument,"png") || haveExt(argument,"PNG") ||
                    haveExt(argument,"jpg") || haveExt(argument,"JPG") || 
                    haveExt(argument,"jpeg") || haveExt(argument,"JPEG") ){
                // Load Image and print it
                printer.printImg(argument);
            } else if ( haveExt(argument,"txt") || haveExt(argument,"TXT") ||
                        haveExt(argument,"md") || haveExt(argument,"MD") ){
                // Load Text to print
                std::string text = "";
                loadFromPath(argument,&text);
                printer.print(text+"\n");
            } else if (argument == "-s") {
                std::string text = "";
                for (int j = i+1; j < argc ; j++){
                    text += std::string(argv[j]) + " ";
                }
                printer.print(text+"\n");
                break;
            }
        }
    }

    // printer.close();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movq %rsi, 0x38(%rsp)
movl %edi, %ebp
leaq 0xb3ba(%rip), %rsi      # 0x18829
leaq 0xa0(%rsp), %rdi
leaq 0x120(%rsp), %rdx
callq 0x95bc
leaq 0x88(%rsp), %rdi
callq 0x883c
xorl %ecx, %ecx
pushq $0x60
popq %rbx
leaq 0xb391(%rip), %r14      # 0x1882e
movl %ecx, %r12d
movq 0x88(%rsp), %rcx
movq 0x90(%rsp), %rax
subq %rcx, %rax
cqto
idivq %rbx
cmpq %r12, %rax
jbe 0xd4f6
imulq $0x60, %r12, %r15
leaq (%rcx,%r15), %rdi
addq $0x20, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x8670
leal 0x1(%r12), %ecx
cmpq $-0x1, %rax
je 0xd49d
addq 0x88(%rsp), %r15
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x81c0
movl %ebp, 0x2c(%rsp)
movq 0x12abf(%rip), %rdi     # 0x1ffc0
leaq 0xb355(%rip), %rsi      # 0x1885d
callq 0x82e0
leaq 0xa0(%rsp), %rsi
movq %rax, %rdi
callq 0x82b0
leaq 0xb34e(%rip), %rsi      # 0x18872
movq %rax, %rdi
callq 0x82e0
leaq 0x12ead(%rip), %rdi     # 0x203e0
leaq 0xa0(%rsp), %rsi
callq 0xf400
testb %al, %al
je 0xd609
leaq 0x12e91(%rip), %rdi     # 0x203e0
pushq $0x7
popq %rsi
pushq $0x64
popq %rdx
pushq $0x2
popq %rcx
callq 0xf556
leaq 0x12e7c(%rip), %rdi     # 0x203e0
xorl %esi, %esi
callq 0xf766
movq 0x12a4e(%rip), %rdi     # 0x1ffc0
leaq 0xb2fc(%rip), %rsi      # 0x18875
callq 0x82e0
movq %rax, %rdi
callq 0x8190
movl 0x2c(%rsp), %eax
cmpl $0x1, %eax
jne 0xd629
leaq 0x130(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x12a32(%rip), %rbx     # 0x1ffe0
leaq 0x120(%rsp), %r14
leaq 0xc0ee(%rip), %r15      # 0x196ab
leaq 0x8(%rsp), %r12
leaq 0x12e17(%rip), %r13     # 0x203e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8070
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xda7a
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x96c3
movq %r13, %rdi
movq %r12, %rsi
callq 0xf94c
movq %r12, %rdi
callq 0x8170
jmp 0xd5c9
movq 0x129b0(%rip), %rdi     # 0x1ffc0
leaq 0xb26c(%rip), %rsi      # 0x18883
callq 0x82e0
movq %rax, %rdi
callq 0x8190
jmp 0xda87
cltq
movq %rax, 0x80(%rsp)
pushq $0x1
popq %rbp
pushq $0x2
popq %rax
movq %rax, 0x30(%rsp)
leaq 0xe0(%rsp), %r15
leaq 0x120(%rsp), %r12
leaq 0x100(%rsp), %r13
cmpq 0x80(%rsp), %rbp
jge 0xda87
movq 0x38(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x95bc
movq %r12, %rdi
leaq 0xb208(%rip), %rsi      # 0x1888a
leaq 0x3(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %r12, %rsi
callq 0xdc80
testb %al, %al
jne 0xd6ff
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0xb1e4(%rip), %rsi      # 0x1888e
leaq 0x2(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %r14, %rsi
callq 0xdc80
testb %al, %al
jne 0xd6f5
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0xb1c0(%rip), %rsi      # 0x18892
leaq 0x7(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %rbx, %rsi
callq 0xdc80
testb %al, %al
je 0xd72e
leaq 0x40(%rsp), %rdi
callq 0x8170
leaq 0x8(%rsp), %rdi
callq 0x8170
movq %r12, %rdi
callq 0x8170
leaq 0x12cd2(%rip), %rdi     # 0x203e0
movq %r15, %rsi
pushq $0x7f
popq %rdx
callq 0xfa68
movq %r15, %rdi
callq 0x8170
incq %rbp
incq 0x30(%rsp)
jmp 0xd656
leaq 0x60(%rsp), %r14
movq %r14, %rdi
leaq 0xb159(%rip), %rsi      # 0x18896
leaq 0x6(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %r14, %rsi
callq 0xdc80
movb $0x1, %r14b
testb %al, %al
jne 0xd7c1
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0xb12f(%rip), %rsi      # 0x1889a
leaq 0x5(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %r14, %rsi
callq 0xdc80
movb $0x1, %r14b
testb %al, %al
jne 0xd7b4
movq %r13, %rbx
movq %r13, %rdi
leaq 0xb10b(%rip), %rsi      # 0x1889f
leaq 0x4(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %rbx, %rsi
callq 0xdc80
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8170
leaq 0xc0(%rsp), %rdi
callq 0x8170
leaq 0x60(%rsp), %rdi
callq 0x8170
leaq 0x40(%rsp), %rdi
callq 0x8170
leaq 0x8(%rsp), %rdi
callq 0x8170
movq %r12, %rdi
callq 0x8170
testb %r14b, %r14b
jne 0xd707
movq %r12, %rdi
leaq 0xb0aa(%rip), %rsi      # 0x188a4
leaq 0xc0(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %r12, %rsi
callq 0xdc80
testb %al, %al
jne 0xd87c
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0xb083(%rip), %rsi      # 0x188a8
movq %r13, %rdx
callq 0x95bc
movq %r15, %rdi
movq %r14, %rsi
callq 0xdc80
testb %al, %al
jne 0xd872
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0xb061(%rip), %rsi      # 0x188ac
leaq 0x3(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %rbx, %rsi
callq 0xdc80
testb %al, %al
je 0xd981
leaq 0x40(%rsp), %rdi
callq 0x8170
leaq 0x8(%rsp), %rdi
callq 0x8170
movq %r12, %rdi
callq 0x8170
leaq 0x60(%rsp), %rdi
leaq 0xbe1c(%rip), %rsi      # 0x196ac
movq %r12, %rdx
callq 0x95bc
movq %r12, %rdi
callq 0x83a0
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq 0xe0(%rsp), %rsi
movq %r12, %rdi
pushq $0x8
popq %rdx
callq 0x8200
leaq 0x198(%rsp), %rdi
callq 0x80b0
testb %al, %al
je 0xd935
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x140(%rsp,%rax)
jne 0xd92d
movq %r12, %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x8070
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xbd9a(%rip), %rdx      # 0x196ab
callq 0x96c3
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x8650
movq %rbx, %rdi
callq 0x8170
jmp 0xd8d9
movq %r12, %rdi
callq 0x8090
leaq 0x8(%rsp), %rdi
callq 0x8170
movq %r12, %rdi
callq 0x80c0
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
leaq 0xbd55(%rip), %rdx      # 0x196ab
callq 0x96c3
leaq 0x12a7e(%rip), %rdi     # 0x203e0
movq %r12, %rsi
callq 0xf94c
movq %r12, %rdi
callq 0x8170
leaq 0x60(%rsp), %rdi
callq 0x8170
jmp 0xd719
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0xaf1f(%rip), %rsi      # 0x188af
leaq 0x2(%rsp), %rdx
callq 0x95bc
movq %r15, %rdi
movq %rbx, %rsi
callq 0xdc80
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8170
leaq 0x40(%rsp), %rdi
callq 0x8170
leaq 0x8(%rsp), %rdi
callq 0x8170
movq %r12, %rdi
callq 0x8170
testb %r14b, %r14b
jne 0xd884
movq %r15, %rdi
leaq 0xaed3(%rip), %rsi      # 0x188b2
callq 0xdcc7
testb %al, %al
je 0xd719
leaq 0xbcb9(%rip), %rsi      # 0x196ac
leaq 0x120(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x95bc
leaq 0x40(%rsp), %r14
leaq 0x60(%rsp), %r15
leaq 0xac3e(%rip), %r12      # 0x18654
leaq 0x8(%rsp), %r13
leaq 0x120(%rsp), %rbp
movq 0x30(%rsp), %rcx
cmpl 0x2c(%rsp), %ecx
jge 0xdab5
movq 0x38(%rsp), %rax
movq %rcx, %rbx
movq (%rax,%rcx,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x95bc
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xdcd4
movq %rbp, %rdi
movq %r13, %rsi
callq 0x8650
movq %r13, %rdi
callq 0x8170
movq %r14, %rdi
callq 0x8170
movq %rbx, %rcx
incq %rcx
jmp 0xda28
leaq 0x120(%rsp), %rdi
callq 0x8170
leaq 0x88(%rsp), %rdi
callq 0x968a
leaq 0xa0(%rsp), %rdi
callq 0x8170
xorl %eax, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbbef(%rip), %rdx      # 0x196ab
leaq 0x8(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x96c3
leaq 0x1290b(%rip), %rdi     # 0x203e0
leaq 0x8(%rsp), %rsi
callq 0xf94c
leaq 0x8(%rsp), %rdi
callq 0x8170
leaq 0x120(%rsp), %rdi
callq 0x8170
leaq 0xe0(%rsp), %rdi
jmp 0xda82
jmp 0xdbd2
jmp 0xdc1e
jmp 0xdc19
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8170
jmp 0xdb21
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0xdbda
jmp 0xdc1e
jmp 0xdba8
jmp 0xdbc1
jmp 0xdbc1
jmp 0xdbd2
jmp 0xdbd2
jmp 0xdc1e
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x8170
jmp 0xdb90
jmp 0xdb8d
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x8170
jmp 0xdc10
jmp 0xdb76
movq %rax, %rbx
jmp 0xdc10
jmp 0xdc19
jmp 0xdc1e
jmp 0xdc19
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x8170
jmp 0xdbab
jmp 0xdba8
jmp 0xdc38
jmp 0xdbf6
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x8170
jmp 0xdbc4
jmp 0xdbc1
movq %rax, %rbx
jmp 0xdc6b
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x8170
jmp 0xdbd5
jmp 0xdbd2
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8170
jmp 0xdc21
jmp 0xdc1e
jmp 0xdc38
jmp 0xdbf6
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x8170
jmp 0xdbf9
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8170
leaq 0x120(%rsp), %rdi
callq 0x80c0
leaq 0x60(%rsp), %rdi
jmp 0xdc29
jmp 0xdc19
movq %rax, %rbx
jmp 0xdc2e
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x8170
leaq 0xe0(%rsp), %rdi
jmp 0xdc59
movq %rax, %rbx
jmp 0xdc5e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8170
jmp 0xdc51
jmp 0xdc4e
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x8170
leaq 0x88(%rsp), %rdi
callq 0x968a
leaq 0xa0(%rsp), %rdi
callq 0x8170
movq %rbx, %rdi
callq 0x85c0