// File: /workspace/github_cpp_makefile_star2_O1/halsafar[P]libtmx-parser/./src/tmxparser.cpp
// Function: tmxparser::_parseTileset(tinyxml2::XMLElement*, tmxparser::TmxTileset*)
TmxReturn _parseTileset(tinyxml2::XMLElement* element, TmxTileset* outTileset)
{
  char const* name = element->Attribute("name");
  if (name != nullptr)
  {
    outTileset->name = name;
  }

  CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "tilewidth", &outTileset->tileWidth);
  CHECK_AND_RETRIEVE_REQ_ATTRIBUTE(element->QueryUnsignedAttribute, "tileheight", &outTileset->tileHeight);
  outTileset->tileSpacingInImage = element->UnsignedAttribute("spacing");
  outTileset->tileMarginInImage = element->UnsignedAttribute("margin");

  // TODO - read TODO at end of this function
  if (element->FirstChildElement("image") == NULL)
  {
    LOGE("We do not support maps with tilesets that have no image associated currently...");
    return kErrorParsing;
  }

  TmxImage image;
  TmxReturn error = _parseImageNode(element->FirstChildElement("image"), &outTileset->image);
  if (error)
  {
    LOGE("Error parsing image node...");
    return error;
  }

  outTileset->offset.x = 0;
  outTileset->offset.y = 0;

  if (element->FirstChildElement("tileoffset") != NULL)
  {
    error = _parseOffsetNode(element->FirstChildElement("tileoffset"), &outTileset->offset);
  }

  for (tinyxml2::XMLElement* child = element->FirstChildElement("tile"); child != NULL; child = child->NextSiblingElement("tile"))
  {
    TmxTileDefinition tileDef;

    tileDef.id = 0;

    error = _parseTileDefinitionNode(child, &tileDef);
    if (error)
    {
      LOGE("Error parsing tile definition");
      return error;
    }

    outTileset->tileDefinitions[tileDef.id] = tileDef;
  }

  // derive row/col count, calculate tile indices
  // TODO - this is why we do not accept tilesets without image tag atm
  outTileset->colCount = (outTileset->image.width - outTileset->tileMarginInImage) / (outTileset->tileWidth + outTileset->tileSpacingInImage);
  outTileset->rowCount = (outTileset->image.height - outTileset->tileMarginInImage) / (outTileset->tileHeight + outTileset->tileSpacingInImage);

	return TmxReturn::kSuccess;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r13
movq %rdi, %r15
leaq 0xbcd3(%rip), %rsi      # 0x12261
xorl %edx, %edx
callq 0xe9e8
testq %rax, %rax
je 0x65c0
movq %rax, %rbx
leaq 0x28(%r13), %r14
movq 0x30(%r13), %r12
movq %rax, %rdi
callq 0x4100
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x4330
leaq 0xbb33(%rip), %rsi      # 0x120fa
movq %r15, %rdi
callq 0xe962
testq %rax, %rax
je 0x689f
leaq 0x48(%r13), %rsi
movq %rax, %rdi
callq 0xe58c
cmpl $0x1, %eax
je 0x689f
leaq 0xbb10(%rip), %rsi      # 0x12104
movq %r15, %rdi
callq 0xe962
testq %rax, %rax
je 0x68a6
leaq 0x4c(%r13), %rsi
movq %rax, %rdi
callq 0xe58c
cmpl $0x1, %eax
je 0x68a6
leaq 0xbc5f(%rip), %rsi      # 0x12280
movq %r15, %rdi
callq 0x788e
movl %eax, 0x50(%r13)
leaq 0xbc54(%rip), %rsi      # 0x12288
movq %r15, %rdi
callq 0x788e
movl %eax, 0x54(%r13)
leaq 0xbc48(%rip), %rsi      # 0x1228f
movq %r15, %rdi
callq 0xd6a6
testq %rax, %rax
je 0x68c4
leaq -0x100(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xe0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xc0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xbbfb(%rip), %rsi      # 0x1228f
movq %r15, %rdi
callq 0xd6a6
leaq 0x68(%r13), %rsi
movq %rax, %rdi
callq 0x6412
movl %eax, %ebx
testl %eax, %eax
jne 0x68d0
movq $0x0, 0x58(%r13)
leaq 0xbc64(%rip), %rsi      # 0x12325
movq %r15, %rdi
callq 0xd6a6
testq %rax, %rax
je 0x66e9
leaq 0xbc50(%rip), %rsi      # 0x12325
movq %r15, %rdi
callq 0xd6a6
leaq 0x58(%r13), %rsi
movq %rax, %rdi
callq 0x6906
leaq 0xbc40(%rip), %rsi      # 0x12330
movq %r15, %rdi
callq 0xd6a6
movq %rax, %r15
leaq -0xa0(%rbp), %r12
leaq 0xd0(%r13), %rax
movq %rax, -0x38(%rbp)
testq %r15, %r15
je 0x6817
movq %r13, %r14
leaq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x1, -0x98(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movl $0x3f800000, -0x80(%rbp) # imm = 0x3F800000
movups %xmm0, 0x58(%r12)
movups %xmm0, 0x48(%r12)
movups %xmm0, 0x38(%r12)
movups %xmm0, 0x28(%r12)
movl $0x0, -0xa8(%rbp)
movq %r15, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x696d
movl %eax, %r13d
testl %eax, %eax
jne 0x6809
movq -0x38(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xad00
movq %rax, %rbx
movl -0xa8(%rbp), %eax
movl %eax, (%rbx)
leaq -0xa8(%rbp), %rax
cmpq %rbx, %rax
je 0x67ae
leaq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x7e54
leaq 0x40(%rbx), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7ca4
addq $0x58, %rbx
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0x7d7c
leaq -0x50(%rbp), %rdi
callq 0x9084
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x67e2
callq 0x41c0
movq %r12, %rdi
callq 0x7b34
testl %r13d, %r13d
jne 0x6814
movq %r15, %rdi
leaq 0xbb37(%rip), %rsi      # 0x12330
callq 0xd84e
movq %rax, %r15
movq %r14, %r13
jmp 0x670d
callq 0x4881
movl %r13d, -0x2c(%rbp)
jmp 0x67cb
movq %r14, %r13
testq %r15, %r15
movl -0x2c(%rbp), %ebx
jne 0x6855
movl 0xc8(%r13), %eax
movl 0x50(%r13), %ecx
movl 0x54(%r13), %esi
subl %esi, %eax
movl 0x48(%r13), %edi
addl %ecx, %edi
xorl %ebx, %ebx
xorl %edx, %edx
divl %edi
movl %eax, 0x64(%r13)
movl 0xcc(%r13), %eax
subl %esi, %eax
addl 0x4c(%r13), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x60(%r13)
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x686d
callq 0x41c0
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x6885
callq 0x41c0
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x68b0
callq 0x41c0
jmp 0x68b0
callq 0x491e
jmp 0x68ab
callq 0x48e8
movl $0x2, %ebx
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x48b5
movl $0x1, %ebx
jmp 0x68b0
callq 0x484d
jmp 0x6855
jmp 0x68de
jmp 0x68de
movq %rax, %rbx
jmp 0x68f2
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x78bc
leaq -0x110(%rbp), %rdi
callq 0x78ee
movq %rbx, %rdi
callq 0x43d0