// File: /workspace/github_cpp_makefile_star2_O2/grisu48[P]geoJson/geoJson.cpp
// Function: main
int main(int argc, char** argv) {
    if(argc < 2) {
#ifdef __linux__ 
	// Print message only if terminal, not if pipe or file
	if (::isatty(STDIN_FILENO))
        	cerr << "Reading from stdin until eof" << endl;
#endif
        processStream(cin, cout);
    } else {
        string o_filename;      // Output filename, if empty stdout
        
        for(int i=1;i<argc;i++) {
            string arg = argv[i];
            if(arg == "") continue;
            if(arg.at(0) == '-') {
                if(arg == "-h" || arg == "--help") {
                    cout << "GPX to GeoJson converter || 2017, phoenix" << endl << endl;
                    
                    cout << "Usage: " << argv[0] << " [OPTIONS] [FILES]" << endl;
                    cout << "OPTIONS:" << endl;
                    cout << "  -h   --help         Print this help message" << endl;
                    cout << "       --version      Print program version" << endl;
                    cout << "  -o FILE             Write output to FILE" << endl;
                    cout << "                      -o must be before a FILE and matches for all successive files" << endl;
                    cout << "                      It's possible to write different input files to different output files by chaining the commands:" << endl;
                    cout << "                      " << argv[0] << " -o FILE1.json FILE1.gpx -o FILE2.json FILE2.gpx ..." << endl;
                    return EXIT_SUCCESS;
                } else if(arg == "--version") {
                    cout << "1.0" << endl;
                    return EXIT_SUCCESS;
                } else if(arg == "-o") {
                    if(i >= argc-1) {
                        cerr << "Missing argument: Output file" << endl;
                        return EXIT_FAILURE;
                    }
                    o_filename = argv[++i];
                } else {
                    cerr << "Illegal argument: " << arg << endl;
                    return EXIT_FAILURE;
                }
            } else {
                ifstream f_in(argv[i]);
                if(f_in.is_open()) {
                    
                    if (o_filename.size() > 0) {
                        ofstream f_out(o_filename.c_str(), ofstream::out | ofstream::app);
                        if (!f_out.is_open()) {
                            cerr << "Error opening output file " << o_filename << endl;
                            return EXIT_FAILURE;
                        }
                        processStream(f_in, f_out);
                        f_out.close();

                    } else {
                         processStream(f_in, cout);
                    }

                    f_in.close();
                    
                } else {
                    cerr << "Error opening " << argv[i] << endl;
                    return EXIT_FAILURE;
                }   
            }
        }

    }
    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
cmpl $0x1, %edi
jg 0x24a0
xorl %edi, %edi
callq 0x22d0
testl %eax, %eax
je 0x2488
movq 0x6b7c(%rip), %rdi      # 0x8ff0
leaq 0x2ba5(%rip), %rsi      # 0x5020
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x6b41(%rip), %rdi      # 0x8fd0
movq 0x6b2a(%rip), %rsi      # 0x8fc0
callq 0x28d0
jmp 0x286d
leaq 0x30(%rsp), %rax
movl %edi, %ebx
movq %rsi, %r14
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leal -0x1(%rbx), %eax
movl %eax, 0x14(%rsp)
pushq $0x1
popq %r13
movq 0x6af8(%rip), %rax      # 0x8fc0
leaq 0x40(%rsp), %rbp
leaq 0x260(%rsp), %r12
movq $0x0, 0x8(%rsp)
movq %rax, 0x18(%rsp)
cmpl %ebx, %r13d
jge 0x26be
movslq %r13d, %r15
movq (%r14,%r15,8), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x20d0
leaq 0x31cc(%rip), %rsi      # 0x56d1
movq %rbp, %rdi
callq 0x31a8
testb %al, %al
jne 0x26ae
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2310
cmpb $0x2d, (%rax)
jne 0x25a2
leaq 0x2b12(%rip), %rsi      # 0x503d
movq %rbp, %rdi
callq 0x31a8
testb %al, %al
jne 0x26c8
leaq 0x2afe(%rip), %rsi      # 0x5040
movq %rbp, %rdi
callq 0x31a8
testb %al, %al
jne 0x26c8
leaq 0x2cc1(%rip), %rsi      # 0x521a
movq %rbp, %rdi
callq 0x31a8
testb %al, %al
jne 0x27f5
leaq 0x2cb8(%rip), %rsi      # 0x5228
movq %rbp, %rdi
callq 0x31a8
testb %al, %al
je 0x2813
cmpl 0x14(%rsp), %r13d
jge 0x2835
movq 0x8(%r14,%r15,8), %rsi
leaq 0x20(%rsp), %rdi
callq 0x2300
incl %r13d
jmp 0x26ae
movq (%r14,%r15,8), %rsi
movq %r12, %rdi
pushq $0x8
popq %rdx
callq 0x22f0
leaq 0x2d8(%rsp), %rdi
callq 0x2080
testb %al, %al
je 0x2609
cmpq $0x0, 0x28(%rsp)
je 0x263d
movq 0x20(%rsp), %rsi
leaq 0x60(%rsp), %rdi
pushq $0x11
popq %rdx
callq 0x2200
leaq 0xd0(%rsp), %rdi
callq 0x2080
movl %eax, %r15d
testb %al, %al
je 0x264e
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
callq 0x28d0
leaq 0x60(%rsp), %rdi
callq 0x2260
jmp 0x267e
movq 0x69e0(%rip), %rdi      # 0x8ff0
leaq 0x2c60(%rip), %rsi      # 0x5277
callq 0x21d0
movq (%r14,%r15,8), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
xorl %r15d, %r15d
pushq $0x1
popq %rax
movq %rax, 0x8(%rsp)
jmp 0x269d
movq 0x697c(%rip), %rsi      # 0x8fc0
movq %r12, %rdi
callq 0x28d0
jmp 0x268d
movq 0x699b(%rip), %rdi      # 0x8ff0
leaq 0x2c00(%rip), %rsi      # 0x525c
callq 0x21d0
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x2280
testb %r15b, %r15b
je 0x269a
movb $0x1, %r15b
movq %r12, %rdi
callq 0x2070
jmp 0x269d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x2090
testb %r15b, %r15b
je 0x27ee
movq %rbp, %rdi
callq 0x20f0
incl %r13d
jmp 0x24e3
movq 0x8(%rsp), %r14
jmp 0x285e
movq 0x68f1(%rip), %rdi      # 0x8fc0
leaq 0x2971(%rip), %rsi      # 0x5047
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
movq 0x68ce(%rip), %rdi      # 0x8fc0
leaq 0x2978(%rip), %rsi      # 0x5071
callq 0x21d0
movq (%r14), %rsi
movq %rax, %rdi
callq 0x21d0
leaq 0x2969(%rip), %rsi      # 0x5079
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x6899(%rip), %rdi      # 0x8fc0
leaq 0x295e(%rip), %rsi      # 0x508c
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x687e(%rip), %rdi      # 0x8fc0
leaq 0x294c(%rip), %rsi      # 0x5095
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x6863(%rip), %rdi      # 0x8fc0
leaq 0x295f(%rip), %rsi      # 0x50c3
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x6848(%rip), %rdi      # 0x8fc0
leaq 0x2970(%rip), %rsi      # 0x50ef
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x682d(%rip), %rdi      # 0x8fc0
leaq 0x2980(%rip), %rsi      # 0x511a
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x6812(%rip), %rdi      # 0x8fc0
leaq 0x29b9(%rip), %rsi      # 0x516e
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x67f7(%rip), %rdi      # 0x8fc0
leaq 0x2eeb(%rip), %rsi      # 0x56bb
callq 0x21d0
movq (%r14), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, 0x18(%rsp)
leaq 0x29f9(%rip), %rsi      # 0x51e5
jmp 0x27fc
movq 0x8(%rsp), %r14
jmp 0x2854
leaq 0x2a28(%rip), %rsi      # 0x5224
movq 0x18(%rsp), %rdi
callq 0x21d0
xorl %r14d, %r14d
movq %rax, %rdi
callq 0x2100
jmp 0x2854
movq 0x67d6(%rip), %rdi      # 0x8ff0
leaq 0x2a28(%rip), %rsi      # 0x5249
callq 0x21d0
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x21b0
jmp 0x2848
movq 0x67b4(%rip), %rdi      # 0x8ff0
leaq 0x29e8(%rip), %rsi      # 0x522b
callq 0x21d0
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %r14
leaq 0x40(%rsp), %rdi
callq 0x20f0
leaq 0x20(%rsp), %rdi
callq 0x20f0
cmpl %ebx, %r13d
jl 0x2870
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x289a
leaq 0x60(%rsp), %rdi
movq %rax, %rbx
callq 0x2280
jmp 0x289d
jmp 0x28ac
jmp 0x28ac
movq %rax, %rbx
leaq 0x260(%rsp), %rdi
callq 0x2090
jmp 0x28af
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x20f0
jmp 0x28be
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x22e0