// File: openflightmaps[P]ofm2xplane/main.cpp
// Function: main
int main(int argc, char* argv[])
{
    if(argc<=1)
    {
        cout << "Usage: " << argv[0] << " INPUT.xml" << endl;
        return EXIT_FAILURE;
    }
    cout << "Parsing OfmData..." << endl;
	xml_document<> doc, doc_def;
	xml_node<> * aixm_node;
		
	// Read the xml file into a vector
	ifstream theFile (argv[1]);
	if (!theFile.is_open())
	{
        cout << "Cannot open input file!" << endl;
        return EXIT_FAILURE;
    }
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	// Parse the buffer using the xml file parsing library into doc 
	doc.parse<0>(&buffer[0]);
	
	 ifstream convFile("configuration.xml");
	if(!convFile.is_open())
	{
        cout << "Cannot open configuration file!" << endl;
        return EXIT_FAILURE;
    }
    vector<char> buffer2((istreambuf_iterator<char>(convFile)), istreambuf_iterator<char>());
    buffer2.push_back('\0');
    doc_def.parse<0>(&buffer2[0]); 
	//----------------------------------HIER IST ALLES EINGELESEN
	/* erkannte struktur
	1. Ebene. ofm_webServiceResponse
	2. Ebene: "", "AIXM-Snapshot", "", "OFM-AixmPlugin"
	3. Ebene: "Ahp", "Rwy",...
	*/
	
	ofstream out;
	out.open("apt.dat",ios::trunc);
	out << "I" << endl;
    out << "1000 Version - data cycle 2015.07, build 20150729, metadata AptXP1000.  Copyright � 2015, Open flightmaps Association (info@openflightmaps.org).   This data is covered by the open flightmaps general user license, which can be found on the www.openflightmaps.org" << endl << endl << endl;
    
    cout.precision(10);
    out.precision(10);
    cout << std::setfill('0') << std::setw(2);
    out << std::setfill('0') << std::setw(2);
    
	
	//Searching words
	def=doc_def.first_node("default_values");

	aixm_node = doc.first_node()->first_node("AIXM-Snapshot");

	if(aixm_node == NULL)
	{ 
		cout << "ERROR: ROOT Node 'AIXM-Snapshot' not found." << endl;
		return 1;	
	}
	
	
	// Searching all Ahps
	cout << "Searching all Ahps... " << endl;

	xml_node<> * current_Ahp=aixm_node->first_node("Ahp");
    complete_Ahp(current_Ahp,out);
	while(true)
	{
        if(current_Ahp->next_sibling("Ahp")==NULL)
            break;
        
        current_Ahp=current_Ahp->next_sibling("Ahp");
        complete_Ahp(current_Ahp,out);
    }
	out << "99" << endl;
    out.close();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x208b0, %rsp          # imm = 0x208B0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jg 0x369b
movq 0x12982(%rip), %rdi     # 0x15fd8
leaq 0xd9f7(%rip), %rsi      # 0x11054
callq 0x3200
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3200
movq %rax, %rdi
leaq 0xd9e1(%rip), %rsi      # 0x1105c
callq 0x3200
movq %rax, %rdi
movq 0x12936(%rip), %rsi     # 0x15fc0
callq 0x3240
movl $0x1, -0x4(%rbp)
jmp 0x3ed0
movq 0x12936(%rip), %rdi     # 0x15fd8
leaq 0xd9be(%rip), %rsi      # 0x11067
callq 0x3200
movq %rax, %rdi
movq 0x12908(%rip), %rsi     # 0x15fc0
callq 0x3240
leaq -0x10098(%rbp), %rdi
callq 0xc740
leaq -0x20120(%rbp), %rdi
callq 0xc740
jmp 0x36d7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x20340(%rbp), %rdi
movl $0x8, %edx
callq 0x3470
jmp 0x36f2
leaq -0x20340(%rbp), %rdi
callq 0x33a0
movb %al, -0x207e9(%rbp)
jmp 0x3706
movb -0x207e9(%rbp), %al
testb $0x1, %al
jne 0x37a2
jmp 0x3716
movq 0x128bb(%rip), %rdi     # 0x15fd8
leaq 0xd956(%rip), %rsi      # 0x1107a
callq 0x3200
movq %rax, -0x207f8(%rbp)
jmp 0x3732
movq -0x207f8(%rbp), %rdi
movq 0x12880(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3747
movl $0x1, -0x4(%rbp)
movl $0x1, -0x20344(%rbp)
jmp 0x3e84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3ec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3eb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3eaa
leaq -0x20370(%rbp), %rdi
leaq -0x20340(%rbp), %rsi
callq 0xc770
leaq -0x20380(%rbp), %rdi
callq 0xc7d0
leaq -0x20381(%rbp), %rdi
movq %rdi, -0x20800(%rbp)
callq 0x3450
movq -0x20800(%rbp), %r9
movq -0x20370(%rbp), %rsi
movl -0x20368(%rbp), %edx
movq -0x20380(%rbp), %rcx
movl -0x20378(%rbp), %r8d
leaq -0x20360(%rbp), %rdi
callq 0xc800
jmp 0x3804
leaq -0x20381(%rbp), %rdi
callq 0x3260
movb $0x0, -0x20382(%rbp)
leaq -0x20360(%rbp), %rdi
leaq -0x20382(%rbp), %rsi
callq 0xc890
jmp 0x382c
xorl %eax, %eax
movl %eax, %esi
leaq -0x20360(%rbp), %rdi
callq 0xc9e0
movq %rax, %rsi
leaq -0x10098(%rbp), %rdi
callq 0xc8c0
jmp 0x384d
leaq 0xd83e(%rip), %rsi      # 0x11092
leaq -0x20590(%rbp), %rdi
movl $0x8, %edx
callq 0x3470
jmp 0x3867
leaq -0x20590(%rbp), %rdi
callq 0x33a0
movb %al, -0x20801(%rbp)
jmp 0x387b
movb -0x20801(%rbp), %al
testb $0x1, %al
jne 0x3923
jmp 0x388b
movq 0x12746(%rip), %rdi     # 0x15fd8
leaq 0xd80b(%rip), %rsi      # 0x110a4
callq 0x3200
movq %rax, -0x20810(%rbp)
jmp 0x38a7
movq -0x20810(%rbp), %rdi
movq 0x1270b(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x38bc
movl $0x1, -0x4(%rbp)
movl $0x1, -0x20344(%rbp)
jmp 0x3e50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
leaq -0x20381(%rbp), %rdi
callq 0x3260
jmp 0x3eaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3e76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3e6a
leaq -0x205b8(%rbp), %rdi
leaq -0x20590(%rbp), %rsi
callq 0xc770
leaq -0x205c8(%rbp), %rdi
callq 0xc7d0
leaq -0x205c9(%rbp), %rdi
movq %rdi, -0x20818(%rbp)
callq 0x3450
movq -0x20818(%rbp), %r9
movq -0x205b8(%rbp), %rsi
movl -0x205b0(%rbp), %edx
movq -0x205c8(%rbp), %rcx
movl -0x205c0(%rbp), %r8d
leaq -0x205a8(%rbp), %rdi
callq 0xc800
jmp 0x3985
leaq -0x205c9(%rbp), %rdi
callq 0x3260
movb $0x0, -0x205ca(%rbp)
leaq -0x205a8(%rbp), %rdi
leaq -0x205ca(%rbp), %rsi
callq 0xc890
jmp 0x39ad
xorl %eax, %eax
movl %eax, %esi
leaq -0x205a8(%rbp), %rdi
callq 0xc9e0
movq %rax, %rsi
leaq -0x20120(%rbp), %rdi
callq 0xc8c0
jmp 0x39ce
leaq -0x207d0(%rbp), %rdi
callq 0x3400
jmp 0x39dc
leaq 0xd6e1(%rip), %rsi      # 0x110c4
leaq -0x207d0(%rbp), %rdi
movl $0x20, %edx
callq 0x3060
jmp 0x39f6
leaq 0xd6cf(%rip), %rsi      # 0x110cc
leaq -0x207d0(%rbp), %rdi
callq 0x3200
movq %rax, -0x20820(%rbp)
jmp 0x3a12
movq -0x20820(%rbp), %rdi
movq 0x125a0(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3a27
leaq 0xd6a0(%rip), %rsi      # 0x110ce
leaq -0x207d0(%rbp), %rdi
callq 0x3200
movq %rax, -0x20828(%rbp)
jmp 0x3a43
movq -0x20828(%rbp), %rdi
movq 0x1256f(%rip), %rsi     # 0x15fc0
callq 0x3240
movq %rax, -0x20830(%rbp)
jmp 0x3a5f
movq -0x20830(%rbp), %rdi
movq 0x12553(%rip), %rsi     # 0x15fc0
callq 0x3240
movq %rax, -0x20838(%rbp)
jmp 0x3a7b
movq -0x20838(%rbp), %rdi
movq 0x12537(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3a90
movq 0x12541(%rip), %rdi     # 0x15fd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0xca00
jmp 0x3aad
movq -0x207d0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x207d0(%rbp,%rax), %rdi
movl $0xa, %esi
callq 0xca00
jmp 0x3acc
movl $0x30, %edi
callq 0xca30
movb %al, -0x20839(%rbp)
jmp 0x3ade
movb -0x20839(%rbp), %al
movb %al, -0x207d1(%rbp)
movzbl -0x207d1(%rbp), %esi
movq 0x124e0(%rip), %rdi     # 0x15fd8
callq 0x3390
movq %rax, -0x20848(%rbp)
jmp 0x3b06
movl $0x2, %edi
callq 0xca50
movl %eax, -0x2084c(%rbp)
jmp 0x3b18
movq -0x20848(%rbp), %rdi
movl -0x2084c(%rbp), %eax
movl %eax, -0x207d8(%rbp)
movl -0x207d8(%rbp), %esi
callq 0x3290
jmp 0x3b38
movl $0x30, %edi
callq 0xca30
movb %al, -0x2084d(%rbp)
jmp 0x3b4a
movb -0x2084d(%rbp), %al
movb %al, -0x207d9(%rbp)
movzbl -0x207d9(%rbp), %esi
leaq -0x207d0(%rbp), %rdi
callq 0x3390
movq %rax, -0x20858(%rbp)
jmp 0x3b72
movl $0x2, %edi
callq 0xca50
movl %eax, -0x2085c(%rbp)
jmp 0x3b84
movq -0x20858(%rbp), %rdi
movl -0x2085c(%rbp), %eax
movl %eax, -0x207e0(%rbp)
movl -0x207e0(%rbp), %esi
callq 0x3290
jmp 0x3ba4
leaq 0xd629(%rip), %rsi      # 0x111d4
xorl %eax, %eax
movl %eax, %edx
leaq -0x20120(%rbp), %rdi
movl $0x1, %ecx
callq 0xca70
movq %rax, -0x20868(%rbp)
jmp 0x3bc9
movq -0x20868(%rbp), %rax
movq %rax, 0x126c9(%rip)     # 0x162a0
xorl %eax, %eax
movl %eax, %edx
leaq -0x10098(%rbp), %rdi
movl $0x1, %ecx
movq %rdx, %rsi
callq 0xca70
movq %rax, -0x20870(%rbp)
jmp 0x3bf8
movq -0x20870(%rbp), %rdi
leaq 0xd5dd(%rip), %rsi      # 0x111e3
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0xca70
movq %rax, -0x20878(%rbp)
jmp 0x3c1d
movq -0x20878(%rbp), %rax
movq %rax, -0x20138(%rbp)
cmpq $0x0, -0x20138(%rbp)
jne 0x3cdd
movq 0x12398(%rip), %rdi     # 0x15fd8
leaq 0xd5aa(%rip), %rsi      # 0x111f1
callq 0x3200
movq %rax, -0x20880(%rbp)
jmp 0x3c55
movq -0x20880(%rbp), %rdi
movq 0x1235d(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3c6a
movl $0x1, -0x4(%rbp)
movl $0x1, -0x20344(%rbp)
jmp 0x3e28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
leaq -0x205c9(%rbp), %rdi
callq 0x3260
jmp 0x3e6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
jmp 0x3e42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20128(%rbp)
movl %eax, -0x2012c(%rbp)
leaq -0x207d0(%rbp), %rdi
callq 0x3340
jmp 0x3e42
movq 0x122f4(%rip), %rdi     # 0x15fd8
leaq 0xd532(%rip), %rsi      # 0x1121d
callq 0x3200
movq %rax, -0x20888(%rbp)
jmp 0x3cf9
movq -0x20888(%rbp), %rdi
movq 0x122b9(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3d0e
movq -0x20138(%rbp), %rdi
leaq 0xd518(%rip), %rsi      # 0x11234
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0xca70
movq %rax, -0x20890(%rbp)
jmp 0x3d33
movq -0x20890(%rbp), %rax
movq %rax, -0x207e8(%rbp)
movq -0x207e8(%rbp), %rdi
leaq -0x207d0(%rbp), %rsi
callq 0x3ef0
jmp 0x3d56
jmp 0x3d58
jmp 0x3d5a
movq -0x207e8(%rbp), %rdi
leaq 0xd4cc(%rip), %rsi      # 0x11234
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0xcb50
movq %rax, -0x20898(%rbp)
jmp 0x3d7f
movq -0x20898(%rbp), %rax
cmpq $0x0, %rax
jne 0x3d8e
jmp 0x3dd8
movq -0x207e8(%rbp), %rdi
leaq 0xd498(%rip), %rsi      # 0x11234
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0xcb50
movq %rax, -0x208a0(%rbp)
jmp 0x3db3
movq -0x208a0(%rbp), %rax
movq %rax, -0x207e8(%rbp)
movq -0x207e8(%rbp), %rdi
leaq -0x207d0(%rbp), %rsi
callq 0x3ef0
jmp 0x3dd6
jmp 0x3d58
leaq 0xd459(%rip), %rsi      # 0x11238
leaq -0x207d0(%rbp), %rdi
callq 0x3200
movq %rax, -0x208a8(%rbp)
jmp 0x3df4
movq -0x208a8(%rbp), %rdi
movq 0x121be(%rip), %rsi     # 0x15fc0
callq 0x3240
jmp 0x3e09
leaq -0x207d0(%rbp), %rdi
callq 0x3300
jmp 0x3e17
movl $0x0, -0x4(%rbp)
movl $0x1, -0x20344(%rbp)
leaq -0x207d0(%rbp), %rdi
callq 0x3340
leaq -0x205a8(%rbp), %rdi
callq 0xcc40
jmp 0x3e50
leaq -0x205a8(%rbp), %rdi
callq 0xcc40
jmp 0x3e6a
leaq -0x20590(%rbp), %rdi
callq 0x3080
leaq -0x20360(%rbp), %rdi
callq 0xcc40
jmp 0x3e84
leaq -0x20590(%rbp), %rdi
callq 0x3080
leaq -0x20360(%rbp), %rdi
callq 0xcc40
jmp 0x3eaa
leaq -0x20340(%rbp), %rdi
callq 0x3080
leaq -0x20120(%rbp), %rdi
callq 0xcca0
leaq -0x10098(%rbp), %rdi
callq 0xcca0
jmp 0x3ed0
leaq -0x20340(%rbp), %rdi
callq 0x3080
leaq -0x20120(%rbp), %rdi
callq 0xcca0
leaq -0x10098(%rbp), %rdi
callq 0xcca0
jmp 0x3edc
movl -0x4(%rbp), %eax
addq $0x208b0, %rsp          # imm = 0x208B0
popq %rbp
retq
movq -0x20128(%rbp), %rdi
callq 0x3440
nopl (%rax,%rax)