// File: halsafar[P]libtmx-parser/./src/tmxparser.cpp
// Function: tmxparser::_parseMapNode(tinyxml2::XMLElement*, tmxparser::TmxMap*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
TmxReturn _parseMapNode(tinyxml2::XMLElement* element, TmxMap* outMap, std::string tilesetPath)
{
	if (element == NULL)
	{
		return TmxReturn::kMissingMapNode;
	}

	outMap->version = element->Attribute("version");
	const char* orientation = element->Attribute("orientation");
	if (orientation != NULL)
	{
		if (strcmp(orientation, "orthogonal") == 0)
		{
			outMap->orientation = TmxOrientation::kOrthogonal;
		}
		else if (strcmp(orientation, "isometric") == 0)
		{
			outMap->orientation = TmxOrientation::kIsometric;
		}
		else if (strcmp(orientation, "staggered") == 0)
		{
			outMap->orientation = TmxOrientation::kStaggered;
		}
	}
	else
	{
		LOGW("Missing orientation attribute");
	}

	CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "width", &outMap->width);
	CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "height", &outMap->height);
	CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "tilewidth", &outMap->tileWidth);
	CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "tileheight", &outMap->tileHeight);

	CHECK_AND_RETRIEVE_OPT_ATTRIBUTE_STRING(element, "backgroundcolor", outMap->backgroundColor);
	CHECK_AND_RETRIEVE_OPT_ATTRIBUTE_STRING(element, "renderorder", outMap->renderOrder);


	TmxReturn error = _parsePropertyNode(element->FirstChildElement("properties"), &outMap->propertyMap);
	if (error)
	{
		LOGE("Error processing map properties...");
		return error;
	}

	for (tinyxml2::XMLElement* child = element->FirstChildElement("tileset"); child != NULL; child = child->NextSiblingElement("tileset"))
	{
		TmxTileset set;
		error = _parseTilesetNode(child, &set, tilesetPath);
		if (error)
		{
			LOGE("Error processing tileset node...");
			return error;
		}

		outMap->tilesetCollection.push_back(set);
	}

	for (tinyxml2::XMLElement* child = element->FirstChildElement("layer"); child != NULL; child = child->NextSiblingElement("layer"))
	{
		TmxLayer layer;
		error = _parseLayerNode(child, outMap->tilesetCollection, &layer);
		if (error)
		{
			LOGE("Error processing layer node...");
			return error;
		}

		outMap->layerCollection.push_back(layer);
	}

	for (tinyxml2::XMLElement* child = element->FirstChildElement("objectgroup"); child != NULL; child = child->NextSiblingElement("objectgroup"))
	{
		TmxObjectGroup group;
		error = _parseObjectGroupNode(child, &group);
		if (error)
		{
			LOGE("Error processing objectgroup node...");
			return error;
		}

		outMap->objectGroupCollection.push_back(group);
	}

	for (tinyxml2::XMLElement* child = element->FirstChildElement("imagelayer"); child != NULL; child = child->NextSiblingElement("imagelayer"))
	{
		TmxImageLayer imageLayer;
		error = _parseImageLayerNode(child, &imageLayer);
		if (error)
		{
			LOGE("Error parsing imagelayer node...");
			return error;
		}

		outMap->imageLayerCollection.push_back(imageLayer);
	}

	return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rdx, -0x380(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4a31
movl $0x3, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
leaq 0x1d639(%rip), %rsi     # 0x22075
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, %rsi
movq -0x18(%rbp), %rdi
callq 0x4360
movq -0x10(%rbp), %rdi
leaq 0x1d621(%rip), %rsi     # 0x2207d
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x4ada
movq -0x28(%rbp), %rdi
leaq 0x1d60e(%rip), %rsi     # 0x22089
callq 0x4390
cmpl $0x0, %eax
jne 0x4a92
movq -0x18(%rbp), %rax
movl $0x0, 0x20(%rax)
jmp 0x4ad8
movq -0x28(%rbp), %rdi
leaq 0x1d5f7(%rip), %rsi     # 0x22094
callq 0x4390
cmpl $0x0, %eax
jne 0x4ab4
movq -0x18(%rbp), %rax
movl $0x1, 0x20(%rax)
jmp 0x4ad6
movq -0x28(%rbp), %rdi
leaq 0x1d5df(%rip), %rsi     # 0x2209e
callq 0x4390
cmpl $0x0, %eax
jne 0x4ad4
movq -0x18(%rbp), %rax
movl $0x2, 0x20(%rax)
jmp 0x4ad6
jmp 0x4ad8
jmp 0x4b0a
movq 0x2e4f7(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d5bd(%rip), %rsi     # 0x220a8
movb $0x0, %al
callq 0x43a0
movq 0x2e4df(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1de2d(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x24, %rdx
leaq 0x1d5f1(%rip), %rsi     # 0x2210e
callq 0x7e20
cmpl $0x1, %eax
jne 0x4b6a
movq 0x2e4aa(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d5a0(%rip), %rsi     # 0x220d8
leaq 0x1d5cf(%rip), %rdx     # 0x2210e
movb $0x0, %al
callq 0x43a0
movq 0x2e48b(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1ddd9(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x28, %rdx
leaq 0x1d59b(%rip), %rsi     # 0x22118
callq 0x7e20
cmpl $0x1, %eax
jne 0x4bca
movq 0x2e44a(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d540(%rip), %rsi     # 0x220d8
leaq 0x1d579(%rip), %rdx     # 0x22118
movb $0x0, %al
callq 0x43a0
movq 0x2e42b(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1dd79(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x2c, %rdx
leaq 0x1d52d(%rip), %rsi     # 0x2210a
callq 0x7e20
cmpl $0x1, %eax
jne 0x4c2a
movq 0x2e3ea(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d4e0(%rip), %rsi     # 0x220d8
leaq 0x1d50b(%rip), %rdx     # 0x2210a
movb $0x0, %al
callq 0x43a0
movq 0x2e3cb(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1dd19(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x30, %rdx
leaq 0x1d4d7(%rip), %rsi     # 0x22114
callq 0x7e20
cmpl $0x1, %eax
jne 0x4c8a
movq 0x2e38a(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d480(%rip), %rsi     # 0x220d8
leaq 0x1d4b5(%rip), %rdx     # 0x22114
movb $0x0, %al
callq 0x43a0
movq 0x2e36b(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1dcb9(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
leaq 0x1d48a(%rip), %rsi     # 0x2211f
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
cmpq $0x0, %rax
je 0x4cca
movq -0x10(%rbp), %rdi
leaq 0x1d470(%rip), %rsi     # 0x2211f
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0x4360
jmp 0x4cd9
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
xorl %esi, %esi
callq 0x4450
movq -0x10(%rbp), %rdi
leaq 0x1d44b(%rip), %rsi     # 0x2212f
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
cmpq $0x0, %rax
je 0x4d19
movq -0x10(%rbp), %rdi
leaq 0x1d431(%rip), %rsi     # 0x2212f
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, %rsi
movq -0x18(%rbp), %rdi
addq $0x58, %rdi
callq 0x4360
jmp 0x4d28
movq -0x18(%rbp), %rdi
addq $0x58, %rdi
xorl %esi, %esi
callq 0x4450
movq -0x10(%rbp), %rdi
leaq 0x1d408(%rip), %rsi     # 0x2213b
callq 0x7b60
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x78, %rsi
callq 0x55c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4d8c
movq 0x2e280(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d3e4(%rip), %rsi     # 0x22146
movb $0x0, %al
callq 0x43a0
movq 0x2e268(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1dbb6(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5279
movq -0x10(%rbp), %rdi
leaq 0x1d3e4(%rip), %rsi     # 0x2217b
callq 0x7b60
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x4ef6
leaq -0x140(%rbp), %rdi
callq 0x7e70
movq -0x380(%rbp), %rsi
movq -0x38(%rbp), %rax
movq %rax, -0x388(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x4110
jmp 0x4dd7
movq -0x388(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x5770
movl %eax, -0x38c(%rbp)
jmp 0x4df9
movl -0x38c(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x4508
cmpl $0x0, -0x2c(%rbp)
je 0x4e8a
movq 0x2e1bd(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d35e(%rip), %rsi     # 0x22183
movb $0x0, %al
callq 0x43a0
movq 0x2e1a5(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1daf3(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x170(%rbp)
jmp 0x4ead
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
jmp 0x4ee5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x4508
jmp 0x4ee5
movq -0x18(%rbp), %rdi
addq $0xb0, %rdi
leaq -0x140(%rbp), %rsi
callq 0x7ec0
jmp 0x4ea3
movl $0x0, -0x170(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x7f30
movl -0x170(%rbp), %eax
testl %eax, %eax
je 0x4eca
jmp 0x4ec5
jmp 0x5279
jmp 0x4ecc
movq -0x38(%rbp), %rdi
leaq 0x1d2a4(%rip), %rsi     # 0x2217b
callq 0x7f80
movq %rax, -0x38(%rbp)
jmp 0x4da0
leaq -0x140(%rbp), %rdi
callq 0x7f30
jmp 0x5285
movq -0x10(%rbp), %rdi
leaq 0x1d32e(%rip), %rsi     # 0x2222f
callq 0x7b60
movq %rax, -0x178(%rbp)
cmpq $0x0, -0x178(%rbp)
je 0x5029
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x7fb0
movq -0x398(%rbp), %rdx
movq -0x178(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xb0, %rsi
callq 0x5b10
movl %eax, -0x390(%rbp)
jmp 0x4f54
movl -0x390(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4fc8
movq 0x2e06e(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d242(%rip), %rsi     # 0x221b6
movb $0x0, %al
callq 0x43a0
movq 0x2e056(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d9a4(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x170(%rbp)
jmp 0x4feb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x8060
jmp 0x5285
movq -0x18(%rbp), %rdi
addq $0xc8, %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x7ff0
jmp 0x4fe1
movl $0x0, -0x170(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x8060
movl -0x170(%rbp), %eax
testl %eax, %eax
je 0x5008
jmp 0x5003
jmp 0x5279
jmp 0x500a
movq -0x178(%rbp), %rdi
leaq 0x1d217(%rip), %rsi     # 0x2222f
callq 0x7f80
movq %rax, -0x178(%rbp)
jmp 0x4f0d
movq -0x10(%rbp), %rdi
leaq 0x1d1b3(%rip), %rsi     # 0x221e7
callq 0x7b60
movq %rax, -0x200(%rbp)
cmpq $0x0, -0x200(%rbp)
je 0x5151
leaq -0x298(%rbp), %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x80a0
movq -0x3a8(%rbp), %rsi
movq -0x200(%rbp), %rdi
callq 0x5cf0
movl %eax, -0x39c(%rbp)
jmp 0x507c
movl -0x39c(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x50f0
movq 0x2df46(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d157(%rip), %rsi     # 0x221f3
movb $0x0, %al
callq 0x43a0
movq 0x2df2e(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d87c(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x170(%rbp)
jmp 0x5113
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x8160
jmp 0x5285
movq -0x18(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x298(%rbp), %rsi
callq 0x80f0
jmp 0x5109
movl $0x0, -0x170(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x8160
movl -0x170(%rbp), %eax
testl %eax, %eax
je 0x5130
jmp 0x512b
jmp 0x5279
jmp 0x5132
movq -0x200(%rbp), %rdi
leaq 0x1d0a7(%rip), %rsi     # 0x221e7
callq 0x7f80
movq %rax, -0x200(%rbp)
jmp 0x5040
movq -0x10(%rbp), %rdi
leaq 0x1d0ce(%rip), %rsi     # 0x2222a
callq 0x7b60
movq %rax, -0x2a0(%rbp)
cmpq $0x0, -0x2a0(%rbp)
je 0x5273
leaq -0x378(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x81b0
movq -0x3b8(%rbp), %rsi
movq -0x2a0(%rbp), %rdi
callq 0x5f40
movl %eax, -0x3ac(%rbp)
jmp 0x51a4
movl -0x3ac(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x5215
movq 0x2de1e(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d071(%rip), %rsi     # 0x22235
movb $0x0, %al
callq 0x43a0
movq 0x2de06(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d754(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x170(%rbp)
jmp 0x5238
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x8260
jmp 0x5285
movq -0x18(%rbp), %rdi
addq $0xf8, %rdi
leaq -0x378(%rbp), %rsi
callq 0x81f0
jmp 0x522e
movl $0x0, -0x170(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x8260
movl -0x170(%rbp), %eax
testl %eax, %eax
je 0x5252
jmp 0x5250
jmp 0x5279
jmp 0x5254
movq -0x2a0(%rbp), %rdi
leaq 0x1cfc8(%rip), %rsi     # 0x2222a
callq 0x7f80
movq %rax, -0x2a0(%rbp)
jmp 0x5168
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
movq -0x168(%rbp), %rdi
callq 0x4470
nopw %cs:(%rax,%rax)