// File: /workspace/github_cpp_makefile_star2_O1/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 $0x478, %rsp            # imm = 0x478
cmpl $0x1, %edi
jg 0x2507
xorl %edi, %edi
callq 0x2300
testl %eax, %eax
je 0x24ef
movq 0x6b3c(%rip), %rbx      # 0x8ff0
leaq 0x3b65(%rip), %rsi      # 0x6020
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x6ada(%rip), %rdi      # 0x8fd0
movq 0x6ac3(%rip), %rsi      # 0x8fc0
callq 0x2cb6
jmp 0x2c31
movq %rsi, %rbx
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x6a93(%rip), %rax      # 0x8fb8
movq (%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x58(%rsp)
leal -0x1(%rdi), %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
movl $0x1, %r14d
leaq 0x30(%rsp), %r12
movq 0x6a6f(%rip), %r15      # 0x8fc0
movq %rdi, 0x68(%rsp)
movslq %r14d, %r13
movq (%rbx,%r13,8), %rsi
movq %r12, %rdi
leaq 0x270(%rsp), %rdx
callq 0x20e0
movq %r12, %rdi
leaq 0x4142(%rip), %rsi      # 0x66b9
callq 0x20b0
testl %eax, %eax
je 0x2646
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x2c47
movq 0x30(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x2651
movq %r12, %rdi
leaq 0x3a93(%rip), %rsi      # 0x603d
callq 0x20b0
testl %eax, %eax
je 0x26d5
movq %r12, %rdi
leaq 0x3a7f(%rip), %rsi      # 0x6040
callq 0x20b0
testl %eax, %eax
je 0x26d5
movq %r12, %rdi
leaq 0x3c42(%rip), %rsi      # 0x621a
callq 0x20b0
testl %eax, %eax
je 0x2b03
movq %r12, %rdi
leaq 0x3c39(%rip), %rsi      # 0x6228
callq 0x20b0
testl %eax, %eax
je 0x2b4f
movl $0x12, %edx
movq 0x69e8(%rip), %rdi      # 0x8ff0
leaq 0x3c3a(%rip), %rsi      # 0x6249
callq 0x2210
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x69cb(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
jmp 0x2bc6
movl $0x4, %r12d
jmp 0x2be4
movq (%rbx,%r13,8), %rsi
leaq 0x270(%rsp), %rdi
movl $0x8, %edx
callq 0x2320
leaq 0x2e8(%rsp), %rdi
callq 0x2080
testb %al, %al
je 0x276e
cmpq $0x0, 0x18(%rsp)
je 0x29d5
movq 0x10(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movl $0x11, %edx
callq 0x2200
leaq 0xe0(%rsp), %rdi
callq 0x2080
movl %eax, %r13d
testb %al, %al
je 0x2a4a
leaq 0x270(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2cb6
leaq 0x70(%rsp), %rdi
callq 0x2250
jmp 0x2aa7
movl $0x29, %edx
movq %r15, %rdi
leaq 0x3963(%rip), %rsi      # 0x6047
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x7, %edx
movq %r15, %rdi
leaq 0x3928(%rip), %rsi      # 0x6071
callq 0x2210
movq (%rbx), %r13
testq %r13, %r13
je 0x27b2
movq %r13, %rdi
callq 0x2100
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x27ca
movl $0xe, %edx
movq 0x6876(%rip), %rdi      # 0x8ff0
leaq 0x3af6(%rip), %rsi      # 0x6277
callq 0x2210
movq (%rbx,%r13,8), %r13
testq %r13, %r13
je 0x29ea
movq %r13, %rdi
callq 0x2100
movq 0x684e(%rip), %rdi      # 0x8ff0
movq %r13, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x2a08
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x22e0
movl $0x12, %edx
movq %r15, %rdi
leaq 0x38a0(%rip), %rsi      # 0x6079
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x8, %edx
movq %r15, %rdi
leaq 0x3878(%rip), %rsi      # 0x608c
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x2d, %edx
movq %r15, %rdi
leaq 0x3846(%rip), %rsi      # 0x6095
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x2b, %edx
movq %r15, %rdi
leaq 0x3839(%rip), %rsi      # 0x60c3
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x2a, %edx
movq %r15, %rdi
leaq 0x382a(%rip), %rsi      # 0x60ef
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x53, %edx
movq %r15, %rdi
leaq 0x381a(%rip), %rsi      # 0x611a
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x76, %edx
movq %r15, %rdi
leaq 0x3833(%rip), %rsi      # 0x616e
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x16, %edx
movq %r15, %rdi
leaq 0x3d2d(%rip), %rsi      # 0x66a3
callq 0x2210
movq (%rbx), %rbp
testq %rbp, %rbp
je 0x29ab
movq %rbp, %rdi
callq 0x2100
movl $0x34, %r13d
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x2210
leaq 0x383f(%rip), %rsi      # 0x61e5
jmp 0x2b10
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
movl $0x34, %r13d
callq 0x22e0
leaq 0x3815(%rip), %rsi      # 0x61e5
jmp 0x2b10
leaq 0x270(%rsp), %rdi
movq %r15, %rsi
callq 0x2cb6
jmp 0x2ae1
movq 0x65ff(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x22e0
movq 0x65e1(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x65c3(%rip), %rdi      # 0x8ff0
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2150
movl $0x1, %r12d
jmp 0x2af1
movl $0x1a, %edx
movq 0x659a(%rip), %rdi      # 0x8ff0
leaq 0x37ff(%rip), %rsi      # 0x625c
callq 0x2210
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x657d(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2150
movq 0x60(%rsp), %rax
movq %rax, 0x70(%rsp)
movq -0x18(%rax), %rax
movq 0x58(%rsp), %rcx
movq %rcx, 0x70(%rsp,%rax)
leaq 0x78(%rsp), %rdi
callq 0x21a0
leaq 0x168(%rsp), %rdi
callq 0x20c0
movl $0x1, %r12d
testb %r13b, %r13b
je 0x2af1
xorl %r12d, %r12d
leaq 0x270(%rsp), %rdi
callq 0x2070
leaq 0x270(%rsp), %rdi
callq 0x2090
jmp 0x2be4
movl $0x3, %r13d
leaq 0x3714(%rip), %rsi      # 0x6224
movq %r15, %rdi
movq %r13, %rdx
callq 0x2210
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movl $0x1, %r12d
xorl %ebp, %ebp
jmp 0x2be4
cmpl 0xc(%rsp), %r14d
jge 0x2b8c
movq 0x8(%rbx,%r13,8), %r13
movq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r13, %rdi
callq 0x2100
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x50(%rsp), %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x22a0
incl %r14d
jmp 0x2be4
movl $0x1d, %edx
movq 0x6458(%rip), %rdi      # 0x8ff0
leaq 0x368c(%rip), %rsi      # 0x622b
callq 0x2210
movq 0x6445(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movq 0x642a(%rip), %r13      # 0x8ff0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2150
movl $0x1, %r12d
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2bf8
callq 0x21c0
testb $0x3, %r12b
jne 0x2c17
incl %r14d
cmpl 0x68(%rsp), %r14d
leaq 0x30(%rsp), %r12
jl 0x2556
movl $0x2, %r12d
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2c2b
callq 0x21c0
testb $0x5, %r12b
jne 0x2c33
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a90(%rip), %rdi      # 0x66de
xorl %esi, %esi
xorl %eax, %eax
callq 0x2280
jmp 0x2c6c
jmp 0x2c83
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2270
jmp 0x2c6f
jmp 0x2c83
movq %rax, %rbx
leaq 0x270(%rsp), %rdi
callq 0x2090
jmp 0x2c86
movq %rax, %rbx
jmp 0x2c9a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2c9a
callq 0x21c0
leaq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdi
cmpq %rax, %rdi
je 0x2cae
callq 0x21c0
movq %rbx, %rdi
callq 0x2310