// File: halsafar[P]libtmx-parser/./src/tmxparser.cpp
// Function: tmxparser::_parseTilesetNode(tinyxml2::XMLElement*, tmxparser::TmxTileset*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
TmxReturn _parseTilesetNode(tinyxml2::XMLElement* element, TmxTileset* outTileset, std::string tilesetPath)
{
	if (strcmp(element->Name(), "tileset") == 0)
	{
		CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "firstgid", &outTileset->firstgid);

    // External tileset file
    char const* source = element->Attribute("source");
    if (source != nullptr)
    {
      outTileset->source = source;

      tinyxml2::XMLDocument tileDoc;
      if (tileDoc.LoadFile(_updatePath(source, tilesetPath).c_str()) != tinyxml2::XML_SUCCESS)
      {
        LOGE("Cannot read tileset xml file");
        return TmxReturn::kErrorParsing;
      }

      tinyxml2::XMLElement* tileElement = tileDoc.FirstChildElement("tileset");

      if (tileElement == NULL)
      {
        return TmxReturn::kMissingTilesetNode;
      }

      TmxReturn retVal = _parseTileset(tileElement, outTileset);
      if (retVal != TmxReturn::kSuccess)
      {
        return retVal;
      }

      outTileset->name = outTileset->source.substr(0, outTileset->source.rfind('.'));

    }

    // Embedded tileset
    else
    {
      return _parseTileset(element, outTileset);
    }

	}

	return TmxReturn::kSuccess;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdx, -0x338(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x82a0
movq %rax, %rdi
leaq 0x1c9da(%rip), %rsi     # 0x2217b
callq 0x4390
cmpl $0x0, %eax
jne 0x5aea
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x20, %rdx
leaq 0x1cbb3(%rip), %rsi     # 0x22375
callq 0x7e20
cmpl $0x1, %eax
jne 0x580f
movq 0x2d805(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1c8fb(%rip), %rsi     # 0x220d8
leaq 0x1cb91(%rip), %rdx     # 0x22375
movb $0x0, %al
callq 0x43a0
movq 0x2d7e6(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d134(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x2, -0x4(%rbp)
jmp 0x5af1
movq -0x10(%rbp), %rdi
leaq 0x1ca62(%rip), %rsi     # 0x2227c
xorl %eax, %eax
movl %eax, %edx
callq 0x1c710
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x5ad6
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x4360
leaq -0x2a8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1d490
movq -0x28(%rbp), %rax
movq %rax, -0x348(%rbp)
leaq -0x2e9(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x4480
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdx
leaq -0x2e8(%rbp), %rdi
callq 0x4370
jmp 0x588c
movq -0x338(%rbp), %rdx
leaq -0x2c8(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x5400
jmp 0x58a8
leaq -0x2c8(%rbp), %rdi
callq 0x4100
movq %rax, %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x1d6d0
movl %eax, -0x34c(%rbp)
jmp 0x58cb
leaq -0x2c8(%rbp), %rdi
callq 0x4508
leaq -0x2e8(%rbp), %rdi
callq 0x4508
leaq -0x2e9(%rbp), %rdi
callq 0x42a0
movl -0x34c(%rbp), %eax
cmpl $0x0, %eax
je 0x59a7
movq 0x2d6d3(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1ca6f(%rip), %rsi     # 0x2237e
movb $0x0, %al
callq 0x43a0
movq 0x2d6bb(%rip), %rax     # 0x32fd8
movq (%rax), %rdi
leaq 0x1d009(%rip), %rsi     # 0x22930
movb $0x0, %al
callq 0x43a0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x300(%rbp)
jmp 0x5aac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f8(%rbp)
movl %eax, -0x2fc(%rbp)
jmp 0x5996
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f8(%rbp)
movl %eax, -0x2fc(%rbp)
jmp 0x598a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f8(%rbp)
movl %eax, -0x2fc(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x4508
leaq -0x2e8(%rbp), %rdi
callq 0x4508
leaq -0x2e9(%rbp), %rdi
callq 0x42a0
jmp 0x5ac8
leaq 0x1c7cd(%rip), %rsi     # 0x2217b
leaq -0x2a8(%rbp), %rdi
callq 0x7b60
movq %rax, -0x358(%rbp)
jmp 0x59c3
movq -0x358(%rbp), %rax
movq %rax, -0x308(%rbp)
cmpq $0x0, -0x308(%rbp)
jne 0x5a08
movl $0x5, -0x4(%rbp)
movl $0x1, -0x300(%rbp)
jmp 0x5aac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2f8(%rbp)
movl %eax, -0x2fc(%rbp)
jmp 0x5ac8
movq -0x308(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6300
movl %eax, -0x35c(%rbp)
jmp 0x5a20
movl -0x35c(%rbp), %eax
movl %eax, -0x30c(%rbp)
cmpl $0x0, -0x30c(%rbp)
je 0x5a4a
movl -0x30c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x300(%rbp)
jmp 0x5aac
movq -0x18(%rbp), %rdi
movq %rdi, -0x368(%rbp)
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x44e0
movq -0x368(%rbp), %rsi
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x330(%rbp), %rdi
callq 0x4290
jmp 0x5a82
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
leaq -0x330(%rbp), %rsi
callq 0x42e0
leaq -0x330(%rbp), %rdi
callq 0x4508
movl $0x0, -0x300(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x1d5c0
movl -0x300(%rbp), %eax
testl %eax, %eax
je 0x5ac6
jmp 0x5ac4
jmp 0x5af1
jmp 0x5ae8
leaq -0x2a8(%rbp), %rdi
callq 0x1d5c0
jmp 0x5afd
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6300
movl %eax, -0x4(%rbp)
jmp 0x5af1
jmp 0x5aea
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
movq -0x2f8(%rbp), %rdi
callq 0x4470
nopl (%rax)