// File: grisu48[P]geoJson/geoJson.cpp
// Function: processStream(std::istream&, std::ostream&)
static bool processStream(istream &in, ostream &out = cout) {
	out << setprecision(7);
	
    // Read stream to end
    stringstream buf;
    string text;
    while((getline(in, text)))
        buf << text << '\n';
    text = buf.str();
    
    
    // Parse GPX
    try {
        xml_document<> doc;                     // character type defaults to char
        doc.parse<0>((char*)text.c_str());      // 0 means default parse flags
        
        xml_node<> *node = doc.first_node("gpx");
        if(node == NULL) throw "No data";
        
        // Get GPX attributes
        map<string, string> attrs;              // GPX attributes
        for (xml_attribute<> *attr = node->first_attribute(); attr; attr = attr->next_attribute())
            attrs[attr->name()] = attr->value();

        vector<Coords> coords;

        // Read out tracks
        for (xml_node<> *child = node->first_node("trk"); child; child = child->next_sibling("trk"))
        {
            // Scan for track segments
            for (xml_node<> *seg = child->first_node("trkseg"); seg; seg = seg->next_sibling("trkseg")) {
                // And track points
                for (xml_node<> *pt = seg->first_node("trkpt"); pt; pt = pt->next_sibling("trkpt")) {
                    
                    Coords coord;
                    
                    for (xml_attribute<> *attr = pt->first_attribute(); attr; attr = attr->next_attribute()) {
                        string name = attr->name();
                        if(name == "lon")
                            coord.lon = ::atof(attr->value());
                        else if(name == "lat")
                            coord.lat = ::atof(attr->value());
                    }
                    for (xml_node<> *p = pt->first_node(); p; p = p->next_sibling()) {
                        string name = p->name();
                        if(name == "ele")
                            coord.ele = ::atof(p->value());
                        else if (name == "time")
                            coord.time = p->value();
                    }
                    
                    coords.push_back(coord);
                    
                }
            }
        }
        
        printGeoJson(out, coords);
        
    } catch (parse_error &e) {
        cerr << "Parse error: " << e.what() << endl;
        return false;
    } catch (const char* msg) {
        cerr << "Parse error: No GPX data" << endl;
        return false;
    }
    return true;
}

// Assembly:
subq $0x104f8, %rsp          # imm = 0x104F8
movq %rdi, 0x104e8(%rsp)
movq %rsi, 0x104e0(%rsp)
movq 0x104e0(%rsp), %rax
movq %rax, 0x130(%rsp)
movl $0x7, %edi
callq 0x3e80
movq 0x130(%rsp), %rdi
movl %eax, 0x104dc(%rsp)
movl 0x104dc(%rsp), %esi
callq 0x2320
leaq 0x10350(%rsp), %rdi
callq 0x2160
leaq 0x10330(%rsp), %rdi
callq 0x22d0
movq 0x104e8(%rsp), %rdi
leaq 0x10330(%rsp), %rsi
callq 0x2070
movq %rax, 0x128(%rsp)
jmp 0x2ec5
movq 0x128(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2290
movb %al, 0x127(%rsp)
jmp 0x2ee5
movb 0x127(%rsp), %al
testb $0x1, %al
jne 0x2ef2
jmp 0x2f43
leaq 0x10360(%rsp), %rdi
leaq 0x10330(%rsp), %rsi
callq 0x21d0
movq %rax, 0x118(%rsp)
jmp 0x2f11
movq 0x118(%rsp), %rdi
movl $0xa, %esi
callq 0x2260
jmp 0x2f25
jmp 0x2ea6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x3985
leaq 0x10300(%rsp), %rdi
leaq 0x10350(%rsp), %rsi
callq 0x21f0
jmp 0x2f5a
leaq 0x10330(%rsp), %rdi
leaq 0x10300(%rsp), %rsi
movq %rsi, 0x110(%rsp)
callq 0x2270
movq 0x110(%rsp), %rdi
callq 0x2120
leaq 0x278(%rsp), %rdi
callq 0x3ea0
jmp 0x2f93
leaq 0x10330(%rsp), %rdi
callq 0x20e0
movq %rax, %rsi
leaq 0x278(%rsp), %rdi
callq 0x3ed0
jmp 0x2fb2
leaq 0x72b1(%rip), %rsi      # 0xa26a
xorl %eax, %eax
movl %eax, %edx
leaq 0x278(%rsp), %rdi
movl $0x1, %ecx
callq 0x4010
movq %rax, 0x108(%rsp)
jmp 0x2fd9
movq 0x108(%rsp), %rax
movq %rax, 0x270(%rsp)
cmpq $0x0, 0x270(%rsp)
jne 0x3052
movl $0x8, %edi
callq 0x20f0
movq %rax, %rdi
leaq 0x7266(%rip), %rax      # 0xa26e
movq %rax, (%rdi)
movq 0xbf9e(%rip), %rsi      # 0xefb0
xorl %eax, %eax
movl %eax, %edx
callq 0x2350
jmp 0x39b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x3804
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x37f7
leaq 0x240(%rsp), %rdi
callq 0x4100
movq 0x270(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x4110
movq %rax, 0x100(%rsp)
jmp 0x3082
movq 0x100(%rsp), %rax
movq %rax, 0x238(%rsp)
cmpq $0x0, 0x238(%rsp)
je 0x31ed
movq 0x238(%rsp), %rdi
callq 0x41f0
movq %rax, 0xf8(%rsp)
jmp 0x30b8
movq 0x238(%rsp), %rdi
callq 0x4320
movq %rax, 0xf0(%rsp)
jmp 0x30cf
leaq 0x217(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x2380
movq 0xf0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
leaq 0x218(%rsp), %rdi
callq 0x22c0
jmp 0x3103
leaq 0x240(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x4230
movq %rax, 0xe0(%rsp)
jmp 0x3122
movq 0xf8(%rsp), %rsi
movq 0xe0(%rsp), %rdi
callq 0x22b0
jmp 0x3139
leaq 0x218(%rsp), %rdi
callq 0x2120
leaq 0x217(%rsp), %rdi
callq 0x2240
movq 0x238(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x4360
movq %rax, 0xd8(%rsp)
jmp 0x3176
movq 0xd8(%rsp), %rax
movq %rax, 0x238(%rsp)
jmp 0x3092
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x37ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x31db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x2120
leaq 0x217(%rsp), %rdi
callq 0x2240
jmp 0x37ea
leaq 0x1f8(%rsp), %rdi
callq 0x4460
movq 0x270(%rsp), %rdi
leaq 0x706d(%rip), %rsi      # 0xa276
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x4010
movq %rax, 0xd0(%rsp)
jmp 0x3221
movq 0xd0(%rsp), %rax
movq %rax, 0x1f0(%rsp)
cmpq $0x0, 0x1f0(%rsp)
je 0x379a
movq 0x1f0(%rsp), %rdi
leaq 0x702b(%rip), %rsi      # 0xa27a
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x4010
movq %rax, 0xc8(%rsp)
jmp 0x3267
movq 0xc8(%rsp), %rax
movq %rax, 0x1e8(%rsp)
cmpq $0x0, 0x1e8(%rsp)
je 0x3762
movq 0x1e8(%rsp), %rdi
leaq 0x6fec(%rip), %rsi      # 0xa281
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x4010
movq %rax, 0xc0(%rsp)
jmp 0x32ad
movq 0xc0(%rsp), %rax
movq %rax, 0x1e0(%rsp)
cmpq $0x0, 0x1e0(%rsp)
je 0x372a
leaq 0x1b0(%rsp), %rdi
callq 0x4470
jmp 0x32db
movq 0x1e0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x4110
movq %rax, 0xb8(%rsp)
jmp 0x32fe
movq 0xb8(%rsp), %rax
movq %rax, 0x1a8(%rsp)
cmpq $0x0, 0x1a8(%rsp)
je 0x3500
movq 0x1a8(%rsp), %rdi
callq 0x4320
movq %rax, 0xb0(%rsp)
jmp 0x3334
leaq 0x187(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x2380
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x188(%rsp), %rdi
callq 0x22c0
jmp 0x3368
leaq 0x187(%rsp), %rdi
callq 0x2240
leaq 0x6f0b(%rip), %rsi      # 0xa287
leaq 0x188(%rsp), %rdi
callq 0x3e30
movb %al, 0xa7(%rsp)
jmp 0x3392
movb 0xa7(%rsp), %al
testb $0x1, %al
jne 0x33a2
jmp 0x345a
movq 0x1a8(%rsp), %rdi
callq 0x41f0
movq %rax, 0x98(%rsp)
jmp 0x33b9
movq 0x98(%rsp), %rdi
callq 0x2280
vmovaps %xmm0, %xmm1
vcvtsd2ss %xmm1, %xmm0, %xmm0
vmovss %xmm0, 0x1b0(%rsp)
jmp 0x34bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x37dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
jmp 0x3718
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
leaq 0x187(%rsp), %rdi
callq 0x2240
jmp 0x3718
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x2120
jmp 0x3718
leaq 0x6e2a(%rip), %rsi      # 0xa28b
leaq 0x188(%rsp), %rdi
callq 0x3e30
movb %al, 0x97(%rsp)
jmp 0x3477
movb 0x97(%rsp), %al
testb $0x1, %al
jne 0x3484
jmp 0x34b9
movq 0x1a8(%rsp), %rdi
callq 0x41f0
movq %rax, 0x88(%rsp)
jmp 0x349b
movq 0x88(%rsp), %rdi
callq 0x2280
vmovaps %xmm0, %xmm1
vcvtsd2ss %xmm1, %xmm0, %xmm0
vmovss %xmm0, 0x1b4(%rsp)
jmp 0x34bb
leaq 0x188(%rsp), %rdi
callq 0x2120
movq 0x1a8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x4360
movq %rax, 0x80(%rsp)
jmp 0x34eb
movq 0x80(%rsp), %rax
movq %rax, 0x1a8(%rsp)
jmp 0x330e
movq 0x1e0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x4010
movq %rax, 0x78(%rsp)
jmp 0x3520
movq 0x78(%rsp), %rax
movq %rax, 0x178(%rsp)
cmpq $0x0, 0x178(%rsp)
je 0x36be
movq 0x178(%rsp), %rdi
callq 0x4320
movq %rax, 0x70(%rsp)
jmp 0x3550
leaq 0x157(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x2380
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
leaq 0x158(%rsp), %rdi
callq 0x22c0
jmp 0x357b
leaq 0x157(%rsp), %rdi
callq 0x2240
leaq 0x6d00(%rip), %rsi      # 0xa28f
leaq 0x158(%rsp), %rdi
callq 0x3e30
movb %al, 0x67(%rsp)
jmp 0x35a2
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x35af
jmp 0x362f
movq 0x178(%rsp), %rdi
callq 0x41f0
movq %rax, 0x58(%rsp)
jmp 0x35c3
movq 0x58(%rsp), %rdi
callq 0x2280
vmovaps %xmm0, %xmm1
vcvtsd2ss %xmm1, %xmm0, %xmm0
vmovss %xmm0, 0x1b8(%rsp)
jmp 0x367f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
leaq 0x157(%rsp), %rdi
callq 0x2240
jmp 0x3718
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x2120
jmp 0x3718
leaq 0x6c5d(%rip), %rsi      # 0xa293
leaq 0x158(%rsp), %rdi
callq 0x3e30
movb %al, 0x57(%rsp)
jmp 0x3649
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x3653
jmp 0x367d
movq 0x178(%rsp), %rdi
callq 0x41f0
movq %rax, 0x48(%rsp)
jmp 0x3667
movq 0x48(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x22b0
jmp 0x367b
jmp 0x367d
jmp 0x367f
leaq 0x158(%rsp), %rdi
callq 0x2120
movq 0x178(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
movq %rdx, %rsi
callq 0x44a0
movq %rax, 0x40(%rsp)
jmp 0x36ac
movq 0x40(%rsp), %rax
movq %rax, 0x178(%rsp)
jmp 0x352d
leaq 0x1f8(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x45b0
jmp 0x36d5
leaq 0x1b0(%rsp), %rdi
callq 0x4620
movq 0x1e0(%rsp), %rdi
leaq 0x6b90(%rip), %rsi      # 0xa281
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x44a0
movq %rax, 0x38(%rsp)
jmp 0x3706
movq 0x38(%rsp), %rax
movq %rax, 0x1e0(%rsp)
jmp 0x32bd
leaq 0x1b0(%rsp), %rdi
callq 0x4620
jmp 0x37dd
jmp 0x372c
movq 0x1e8(%rsp), %rdi
leaq 0x6b3f(%rip), %rsi      # 0xa27a
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x44a0
movq %rax, 0x30(%rsp)
jmp 0x3750
movq 0x30(%rsp), %rax
movq %rax, 0x1e8(%rsp)
jmp 0x3277
jmp 0x3764
movq 0x1f0(%rsp), %rdi
leaq 0x6b03(%rip), %rsi      # 0xa276
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x44a0
movq %rax, 0x28(%rsp)
jmp 0x3788
movq 0x28(%rsp), %rax
movq %rax, 0x1f0(%rsp)
jmp 0x3231
movq 0x104e0(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x39c0
jmp 0x37b1
leaq 0x1f8(%rsp), %rdi
callq 0x4640
leaq 0x240(%rsp), %rdi
callq 0x46a0
leaq 0x278(%rsp), %rdi
callq 0x46b0
jmp 0x3947
leaq 0x1f8(%rsp), %rdi
callq 0x4640
leaq 0x240(%rsp), %rdi
callq 0x46a0
leaq 0x278(%rsp), %rdi
callq 0x46b0
movl 0x10324(%rsp), %eax
movl %eax, 0x24(%rsp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x38a0
movq 0x10328(%rsp), %rdi
callq 0x20d0
movq %rax, 0x138(%rsp)
movq 0xb7b8(%rip), %rdi      # 0xeff0
leaq 0x6a72(%rip), %rsi      # 0xa2b1
callq 0x2200
movq %rax, 0x18(%rsp)
jmp 0x384b
movq 0x138(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x2200
movq %rax, 0x10(%rsp)
jmp 0x3870
movq 0x10(%rsp), %rdi
movq 0xb72c(%rip), %rsi      # 0xefa8
callq 0x2230
jmp 0x3883
movb $0x0, 0x104f7(%rsp)
movl $0x1, 0x144(%rsp)
callq 0x2340
jmp 0x3943
movl 0x24(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3985
movq 0x10328(%rsp), %rdi
callq 0x20d0
movq %rax, 0x148(%rsp)
movq 0xb723(%rip), %rdi      # 0xeff0
leaq 0x69c4(%rip), %rsi      # 0xa298
callq 0x2200
movq %rax, 0x8(%rsp)
jmp 0x38e0
movq 0x8(%rsp), %rdi
movq 0xb6bc(%rip), %rsi      # 0xefa8
callq 0x2230
jmp 0x38f3
movb $0x0, 0x104f7(%rsp)
movl $0x1, 0x144(%rsp)
callq 0x2340
jmp 0x395a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
callq 0x2340
jmp 0x3985
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10328(%rsp)
movl %eax, 0x10324(%rsp)
callq 0x2340
jmp 0x3945
jmp 0x395a
jmp 0x3985
movb $0x1, 0x104f7(%rsp)
movl $0x1, 0x144(%rsp)
leaq 0x10330(%rsp), %rdi
callq 0x2120
leaq 0x10350(%rsp), %rdi
callq 0x2190
movb 0x104f7(%rsp), %al
andb $0x1, %al
addq $0x104f8, %rsp          # imm = 0x104F8
retq
leaq 0x10330(%rsp), %rdi
callq 0x2120
leaq 0x10350(%rsp), %rdi
callq 0x2190
movq 0x10328(%rsp), %rdi
callq 0x2370
movq %rax, %rdi
callq 0x46d0
nopw %cs:(%rax,%rax)