// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0xbce7(%rip), %rsi      # 0x12261
xorl %edx, %edx
callq 0xe806
testq %rax, %rax
je 0x65b2
movq %rax, %rbx
movq %r14, %r13
addq $0x28, %r14
movq 0x30(%r13), %r12
movq %rax, %rdi
callq 0x4100
movq %r14, %rdi
movq %r13, %r14
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x4330
leaq 0xbb41(%rip), %rsi      # 0x120fa
movq %r15, %rdi
callq 0xe794
testq %rax, %rax
je 0x6888
leaq 0x48(%r14), %rsi
movq %rax, %rdi
callq 0xe3d2
cmpl $0x1, %eax
je 0x6888
leaq 0xbb1e(%rip), %rsi      # 0x12104
movq %r15, %rdi
callq 0xe794
testq %rax, %rax
je 0x688f
leaq 0x4c(%r14), %rsi
movq %rax, %rdi
callq 0xe3d2
cmpl $0x1, %eax
je 0x688f
leaq 0xbc6d(%rip), %rsi      # 0x12280
movq %r15, %rdi
callq 0x7882
movl %eax, 0x50(%r14)
leaq 0xbc62(%rip), %rsi      # 0x12288
movq %r15, %rdi
callq 0x7882
movl %eax, 0x54(%r14)
leaq 0xbc56(%rip), %rsi      # 0x1228f
movq %r15, %rdi
callq 0xd5f8
testq %rax, %rax
je 0x68ad
leaq -0x108(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xe8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xc8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xbc09(%rip), %rsi      # 0x1228f
movq %r15, %rdi
callq 0xd5f8
leaq 0x68(%r14), %rsi
movq %rax, %rdi
callq 0x63fe
movl %eax, %ebx
testl %eax, %eax
jne 0x68b9
movq $0x0, 0x58(%r14)
leaq 0xbc72(%rip), %rsi      # 0x12325
movq %r15, %rdi
callq 0xd5f8
testq %rax, %rax
je 0x66db
leaq 0xbc5e(%rip), %rsi      # 0x12325
movq %r15, %rdi
callq 0xd5f8
leaq 0x58(%r14), %rsi
movq %rax, %rdi
callq 0x68ef
leaq 0xbc4e(%rip), %rsi      # 0x12330
movq %r15, %rdi
callq 0xd5f8
movq %rax, %r15
leaq -0xa8(%rbp), %r12
movq %r14, -0x38(%rbp)
leaq 0xd0(%r14), %rax
movq %rax, -0x40(%rbp)
leaq -0xb0(%rbp), %r14
testq %r15, %r15
je 0x67ff
leaq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq $0x1, -0xa0(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movl $0x3f800000, -0x88(%rbp) # imm = 0x3F800000
movups %xmm0, 0x58(%r12)
movups %xmm0, 0x48(%r12)
movups %xmm0, 0x38(%r12)
movups %xmm0, 0x28(%r12)
movl $0x0, -0xb0(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x6956
movl %eax, %r13d
testl %eax, %eax
jne 0x67f4
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0xad28
movq %rax, %rbx
movl -0xb0(%rbp), %eax
movl %eax, (%rbx)
cmpq %rbx, %r14
je 0x679c
leaq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x7e6e
leaq 0x40(%rbx), %rdi
leaq -0x70(%rbp), %rsi
callq 0x7cb0
addq $0x58, %rbx
movq %rbx, %rdi
leaq -0x58(%rbp), %rsi
callq 0x7d96
leaq -0x58(%rbp), %rdi
callq 0x90b2
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x67d0
callq 0x41c0
movq %r12, %rdi
callq 0x7b40
testl %r13d, %r13d
jne 0x683b
movq %r15, %rdi
leaq 0xbb49(%rip), %rsi      # 0x12330
callq 0xd720
movq %rax, %r15
jmp 0x670a
callq 0x4881
movl %r13d, -0x2c(%rbp)
jmp 0x67b9
movq -0x38(%rbp), %r8
movl 0xc8(%r8), %eax
movl 0x50(%r8), %ecx
movl 0x54(%r8), %esi
subl %esi, %eax
movl 0x48(%r8), %edi
addl %ecx, %edi
xorl %ebx, %ebx
xorl %edx, %edx
divl %edi
movl %eax, 0x64(%r8)
movl 0xcc(%r8), %eax
subl %esi, %eax
addl 0x4c(%r8), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x60(%r8)
jmp 0x683e
movl -0x2c(%rbp), %ebx
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x6856
callq 0x41c0
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x686e
callq 0x41c0
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x6899
callq 0x41c0
jmp 0x6899
callq 0x491e
jmp 0x6894
callq 0x48e8
movl $0x2, %ebx
movl %ebx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x48b5
movl $0x1, %ebx
jmp 0x6899
callq 0x484d
jmp 0x683e
jmp 0x68c7
jmp 0x68c7
movq %rax, %rbx
jmp 0x68db
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x78b6
leaq -0x118(%rbp), %rdi
callq 0x78e8
movq %rbx, %rdi
callq 0x43d0