// File: halsafar[P]libtmx-parser/./src/tmxparser.cpp
// Function: tmxparser::_parseLayerNode(tinyxml2::XMLElement*, std::vector<tmxparser::TmxTileset, std::allocator<tmxparser::TmxTileset>> const&, tmxparser::TmxLayer*)
TmxReturn _parseLayerNode(tinyxml2::XMLElement* element, const TmxTilesetCollection_t& tilesets, TmxLayer* outLayer)
{
	TmxReturn error = TmxReturn::kSuccess;

	outLayer->name = element->Attribute("name");
	if (element->Attribute("opacity"))
		outLayer->opacity = element->FloatAttribute("opacity");
	else
		outLayer->opacity = 1.f;
	if (element->Attribute("visible"))
		outLayer->visible = (element->IntAttribute("visible") == 1 ? true : false);
	else
		outLayer->visible = true;
	outLayer->width = element->UnsignedAttribute("width");
	outLayer->height = element->UnsignedAttribute("height");

	error = _parsePropertyNode(element->FirstChildElement("properties"), &outLayer->propertyMap);
	if (error)
	{
		LOGE("Error parsing layer property node...");
		return error;
	}

	// check data node and type
	tinyxml2::XMLElement* dataElement = element->FirstChildElement("data");
	if (dataElement != NULL)
	{
		error = _parseLayerDataNode(dataElement, tilesets, &outLayer->tiles);
	}
	else
	{
		LOGE("Layer missing data node...");
		return TmxReturn::kMissingDataNode;
	}

	return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1c73b(%rip), %rsi     # 0x22271
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, %rsi
movq -0x20(%rbp), %rdi
callq 0x4360
movq -0x10(%rbp), %rdi
leaq 0x1c877(%rip), %rsi     # 0x223cd
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
cmpq $0x0, %rax
je 0x5b80
movq -0x10(%rbp), %rdi
leaq 0x1c85d(%rip), %rsi     # 0x223cd
callq 0x84d0
movq -0x20(%rbp), %rax
movss %xmm0, 0x28(%rax)
jmp 0x5b91
movq -0x20(%rbp), %rax
movss 0x1c478(%rip), %xmm0    # 0x22004
movss %xmm0, 0x28(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1c839(%rip), %rsi     # 0x223d5
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
cmpq $0x0, %rax
je 0x5bcf
movq -0x10(%rbp), %rdi
leaq 0x1c81f(%rip), %rsi     # 0x223d5
callq 0x8580
subl $0x1, %eax
sete %cl
negb %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x2c(%rax)
jmp 0x5bd7
movq -0x20(%rbp), %rax
movb $0x1, 0x2c(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1c52c(%rip), %rsi     # 0x2210e
callq 0x82f0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1c51d(%rip), %rsi     # 0x22118
callq 0x82f0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1c527(%rip), %rsi     # 0x2213b
callq 0x7b60
movq %rax, %rdi
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
callq 0x55c0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x5c6a
movq 0x2d39f(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c79a(%rip), %rsi     # 0x223dd
movb $0x0, %al
callq 0x43a0
movq 0x2d387(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1ccd5(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5cde
movq -0x10(%rbp), %rdi
leaq 0x1c79f(%rip), %rsi     # 0x22414
callq 0x7b60
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5c9f
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x68, %rdx
callq 0x6ac0
movl %eax, -0x24(%rbp)
jmp 0x5cd8
movq 0x2d332(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c769(%rip), %rsi     # 0x22419
movb $0x0, %al
callq 0x43a0
movq 0x2d31a(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1cc68(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x4, -0x4(%rbp)
jmp 0x5cde
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)