// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, 0x8(%rsp)
cmpl $0x1, %edi
jg 0x250c
xorl %edi, %edi
callq 0x2300
testl %eax, %eax
je 0x24f4
movq 0x6b37(%rip), %rbx      # 0x8ff0
leaq 0x3b60(%rip), %rsi      # 0x6020
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movl $0xa, %esi
movq -0x18(%rax), %rdi
addq %rbx, %rdi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x6ad5(%rip), %rdi      # 0x8fd0
movq 0x6abe(%rip), %rsi      # 0x8fc0
callq 0x2ce1
jmp 0x2c5a
movq 0x6aa5(%rip), %rdx      # 0x8fb8
leaq 0x28(%rsp), %rax
movq 0x6aa1(%rip), %r15      # 0x8fc0
movl %edi, %r12d
movl $0x1, %r14d
leaq 0x38(%rsp), %rbx
xorl %ebp, %ebp
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rdx), %rcx
movq 0x18(%rdx), %rax
movq %rcx, 0x68(%rsp)
leal -0x1(%r12), %ecx
movq %rax, 0x60(%rsp)
movl %ecx, 0x14(%rsp)
movq 0x8(%rsp), %rcx
movslq %r14d, %r13
movq (%rcx,%r13,8), %rsi
leaq 0x270(%rsp), %rdx
movq %rbx, %rdi
callq 0x20e0
leaq 0x413e(%rip), %rsi      # 0x66b9
movq %rbx, %rdi
callq 0x20b0
testl %eax, %eax
je 0x2650
cmpq $0x0, 0x40(%rsp)
je 0x2c70
movq 0x38(%rsp), %rax
cmpb $0x2d, (%rax)
jne 0x265b
leaq 0x38(%rsp), %rbx
leaq 0x3a8c(%rip), %rsi      # 0x603d
movq %rbx, %rdi
callq 0x20b0
testl %eax, %eax
je 0x26e4
leaq 0x3a78(%rip), %rsi      # 0x6040
movq %rbx, %rdi
callq 0x20b0
testl %eax, %eax
je 0x26e4
leaq 0x3c3b(%rip), %rsi      # 0x621a
movq %rbx, %rdi
callq 0x20b0
testl %eax, %eax
je 0x2b2d
leaq 0x3c32(%rip), %rsi      # 0x6228
movq %rbx, %rdi
callq 0x20b0
testl %eax, %eax
je 0x2b79
movq 0x69e3(%rip), %rdi      # 0x8ff0
movl $0x12, %edx
leaq 0x3c30(%rip), %rsi      # 0x6249
callq 0x2210
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
movq 0x69c1(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
jmp 0x2bf5
movl $0x4, %r13d
jmp 0x2c13
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %rsi
leaq 0x270(%rsp), %rdi
movl $0x8, %edx
callq 0x2320
leaq 0x2e8(%rsp), %rdi
callq 0x2080
testb %al, %al
je 0x2782
cmpq $0x0, 0x20(%rsp)
je 0x29f3
movq 0x18(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movl $0x11, %edx
callq 0x2200
leaq 0xe0(%rsp), %rdi
callq 0x2080
movl %eax, %r13d
testb %al, %al
je 0x2a62
leaq 0x270(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2ce1
leaq 0x70(%rsp), %rdi
callq 0x2250
jmp 0x2abf
movl $0x29, %edx
leaq 0x3957(%rip), %rsi      # 0x6047
movq %r15, %rdi
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
leaq 0x391c(%rip), %rsi      # 0x6071
movq %r15, %rdi
callq 0x2210
movq 0x8(%rsp), %rax
movq (%rax), %r13
testq %r13, %r13
je 0x27cb
movq %r13, %rdi
callq 0x2100
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x27e3
movq 0x6867(%rip), %rdi      # 0x8ff0
movl $0xe, %edx
leaq 0x3ae2(%rip), %rsi      # 0x6277
callq 0x2210
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %r13
testq %r13, %r13
je 0x2a08
movq %r13, %rdi
callq 0x2100
movq 0x6835(%rip), %rdi      # 0x8ff0
movq %r13, %rsi
movq %rax, %rdx
callq 0x2210
jmp 0x2a26
movq (%r15), %rax
movq -0x18(%rax), %rax
movl 0x20(%r15,%rax), %esi
leaq (%r15,%rax), %rdi
orl $0x1, %esi
callq 0x22e0
movl $0x12, %edx
leaq 0x388a(%rip), %rsi      # 0x6079
movq %r15, %rdi
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
leaq 0x3862(%rip), %rsi      # 0x608c
movq %r15, %rdi
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
leaq 0x3830(%rip), %rsi      # 0x6095
movq %r15, %rdi
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
leaq 0x3823(%rip), %rsi      # 0x60c3
movq %r15, %rdi
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
leaq 0x3814(%rip), %rsi      # 0x60ef
movq %r15, %rdi
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
leaq 0x3804(%rip), %rsi      # 0x611a
movq %r15, %rdi
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
leaq 0x381d(%rip), %rsi      # 0x616e
movq %r15, %rdi
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
leaq 0x3d17(%rip), %rsi      # 0x66a3
movq %r15, %rdi
callq 0x2210
movq 0x8(%rsp), %rax
movq (%rax), %rbp
testq %rbp, %rbp
je 0x29c9
movq %rbp, %rdi
callq 0x2100
movl $0x34, %r13d
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x2210
leaq 0x3821(%rip), %rsi      # 0x61e5
jmp 0x2b3a
movq (%r15), %rax
movl $0x34, %r13d
movq -0x18(%rax), %rax
movl 0x20(%r15,%rax), %esi
leaq (%r15,%rax), %rdi
orl $0x1, %esi
callq 0x22e0
leaq 0x37f7(%rip), %rsi      # 0x61e5
jmp 0x2b3a
leaq 0x270(%rsp), %rdi
movq %r15, %rsi
callq 0x2ce1
jmp 0x2af3
movq 0x65e1(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rax
movl 0x20(%rcx,%rax), %esi
leaq (%rcx,%rax), %rdi
orl $0x1, %esi
callq 0x22e0
movq 0x65c3(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movq 0x65a8(%rip), %rdi      # 0x8ff0
movsbl %al, %esi
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2150
jmp 0x2b15
movq 0x6587(%rip), %rdi      # 0x8ff0
movl $0x1a, %edx
leaq 0x37e7(%rip), %rsi      # 0x625c
callq 0x2210
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x6565(%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 0x68(%rsp), %rax
movq 0x60(%rsp), %rcx
leaq 0x78(%rsp), %rdi
movq %rax, 0x70(%rsp)
movq -0x18(%rax), %rax
movq %rcx, 0x70(%rsp,%rax)
callq 0x21a0
leaq 0x168(%rsp), %rdi
callq 0x20c0
testb %r13b, %r13b
je 0x2b15
leaq 0x270(%rsp), %rdi
callq 0x2070
leaq 0x270(%rsp), %rdi
callq 0x2090
xorl %r13d, %r13d
jmp 0x2c13
leaq 0x270(%rsp), %rdi
callq 0x2090
movl $0x1, %r13d
jmp 0x2c13
movl $0x3, %r13d
leaq 0x36ea(%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, %r13d
xorl %ebp, %ebp
jmp 0x2c13
cmpl 0x14(%rsp), %r14d
jge 0x2bbb
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x8(%rax,%r13,8), %rbx
movq %rcx, 0x58(%rsp)
movq %rbx, %rdi
callq 0x2100
xorl %r13d, %r13d
movq 0x58(%rsp), %rdx
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
movq %rax, %r8
callq 0x22a0
incl %r14d
jmp 0x2c13
movq 0x642e(%rip), %rdi      # 0x8ff0
movl $0x1d, %edx
leaq 0x365d(%rip), %rsi      # 0x622b
callq 0x2210
movq 0x6416(%rip), %rcx      # 0x8ff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21d0
movq 0x63fb(%rip), %r13      # 0x8ff0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2150
movl $0x1, %r13d
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c27
callq 0x21c0
testb $0x3, %r13b
jne 0x2c41
incl %r14d
leaq 0x38(%rsp), %rbx
cmpl %r12d, %r14d
jl 0x2558
xorl %r13d, %r13d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2c55
callq 0x21c0
testl %r13d, %r13d
jne 0x2c5c
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 0x3a67(%rip), %rdi      # 0x66de
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
jmp 0x2c97
jmp 0x2cae
leaq 0x70(%rsp), %rdi
movq %rax, %rbx
callq 0x2270
jmp 0x2c9a
jmp 0x2cae
movq %rax, %rbx
leaq 0x270(%rsp), %rdi
callq 0x2090
jmp 0x2cb1
movq %rax, %rbx
jmp 0x2cc5
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2cc5
callq 0x21c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2cd9
callq 0x21c0
movq %rbx, %rdi
callq 0x2310