// File: halsafar[P]libtmx-parser/./src/tmxparser.cpp
// Function: tmxparser::_parseImageLayerNode(tinyxml2::XMLElement*, tmxparser::TmxImageLayer*)
tmxparser::TmxReturn _parseImageLayerNode(tinyxml2::XMLElement* element, TmxImageLayer* outImageLayer)
{
	TmxReturn error = TmxReturn::kSuccess;

	CHECK_AND_RETRIEVE_REQ_ATTRIBUTE_STRING(element, "name", outImageLayer->name);
	
	// x : optional , default 0
	if (element->QueryUnsignedAttribute("x", &outImageLayer->x) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->x = 0U;

	// y : optional , default 0
	if (element->QueryUnsignedAttribute("y", &outImageLayer->y) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->y = 0U;

	// width: optional, default: 0
	if (element->QueryUnsignedAttribute("width", &outImageLayer->widthInTiles) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->widthInTiles = 0U;
	
	// height: optional, default: 0
	if (element->QueryUnsignedAttribute("height", &outImageLayer->heightInTiles) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->heightInTiles = 0U;

	// opacity: optional, default: 1.0
	if (element->QueryFloatAttribute("opacity", &outImageLayer->opacity) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->opacity = 1.f;

	// visible: optional, default: true
	if (element->QueryBoolAttribute("visible", &outImageLayer->visible) == tinyxml2::XML_NO_ATTRIBUTE)
		outImageLayer->visible = true;

	// properties: optional
	if (element->FirstChildElement("properties") != NULL)
	{
		error = _parsePropertyNode(element->FirstChildElement("properties"), &outImageLayer->propertyMap);
		if (error != kSuccess)
		{
			LOGE("Error parsing image layer property node...");
			return error;
		}
	}

	// image: optional
	if (element->FirstChildElement("image") != NULL)
	{
		error = _parseImageNode(element->FirstChildElement("image"), &outImageLayer->image);
		if (error != kSuccess)
			return error;
	}

	return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1c30f(%rip), %rsi     # 0x22271
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, %rsi
movq -0x18(%rbp), %rdi
callq 0x4360
movq -0x18(%rbp), %rdi
callq 0x41c0
cmpq $0x0, %rax
jne 0x5fc9
movq 0x2d04b(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c141(%rip), %rsi     # 0x220d8
leaq 0x1c2d3(%rip), %rdx     # 0x22271
movb $0x0, %al
callq 0x43a0
movq 0x2d02c(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c97a(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x6184
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x20, %rdx
leaq 0x1c914(%rip), %rsi     # 0x228f0
callq 0x7e20
cmpl $0x1, %eax
jne 0x5ff1
movq -0x18(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x24, %rdx
leaq 0x1c3cf(%rip), %rsi     # 0x223d3
callq 0x7e20
cmpl $0x1, %eax
jne 0x6019
movq -0x18(%rbp), %rax
movl $0x0, 0x24(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x28, %rdx
leaq 0x1c0e2(%rip), %rsi     # 0x2210e
callq 0x7e20
cmpl $0x1, %eax
jne 0x6041
movq -0x18(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x2c, %rdx
leaq 0x1c0c4(%rip), %rsi     # 0x22118
callq 0x7e20
cmpl $0x1, %eax
jne 0x6069
movq -0x18(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x30, %rdx
leaq 0x1c351(%rip), %rsi     # 0x223cd
callq 0x89b0
cmpl $0x1, %eax
jne 0x6097
movq -0x18(%rbp), %rax
movss 0x1bf72(%rip), %xmm0    # 0x22004
movss %xmm0, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x34, %rdx
leaq 0x1c32b(%rip), %rsi     # 0x223d5
callq 0x8a00
cmpl $0x1, %eax
jne 0x60bc
movq -0x18(%rbp), %rax
movb $0x1, 0x34(%rax)
movq -0x10(%rbp), %rdi
leaq 0x1c074(%rip), %rsi     # 0x2213b
callq 0x7b60
cmpq $0x0, %rax
je 0x6135
movq -0x10(%rbp), %rdi
leaq 0x1c05e(%rip), %rsi     # 0x2213b
callq 0x7b60
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
callq 0x55c0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6133
movq 0x2ced6(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c481(%rip), %rsi     # 0x2258d
movb $0x0, %al
callq 0x43a0
movq 0x2cebe(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c80c(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6184
jmp 0x6135
movq -0x10(%rbp), %rdi
leaq 0x1c15f(%rip), %rsi     # 0x2229f
callq 0x7b60
cmpq $0x0, %rax
je 0x617e
movq -0x10(%rbp), %rdi
leaq 0x1c149(%rip), %rsi     # 0x2229f
callq 0x7b60
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x70, %rsi
callq 0x6190
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x617c
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6184
jmp 0x617e
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)