// File: /workspace/github_cpp_makefile_star2_O2/DimitriFourny[P]unxip/unxip.cpp
// Function: ParseNodeFile(_xmlNode*, XarFile*)
bool ParseNodeFile(xmlNode* file_node, struct XarFile* xar_file) {
  /*
    <file id="2">
      <data>
        <offset>8111880836</offset>
        <size>355</size>
      </data>
      <name>Metadata</name>
    </file>
  */
  bool is_name_init = false;
  bool is_offset_init = false;
  bool is_size_init = false;

  xmlNode* data_node = nullptr;
  xmlNode* node = file_node->children;
  while (node) {
    if (!node->children) {
      node = node->next;
      continue;
    }
    const char* node_name = reinterpret_cast<const char*>(node->name);
    auto* node_content = reinterpret_cast<const char*>(node->children->content);

    if (!strcmp(node_name, "name")) {
      xar_file->name = std::string(node_content);
      is_name_init = true;
    } else if (!strcmp(node_name, "data")) {
      data_node = node;
    }
    node = node->next;
  }

  if (!is_name_init || !data_node) {
    return false;
  }
  node = data_node->children;
  while (node) {
    if (!node->children) {
      node = node->next;
      continue;
    }
    const char* node_name = reinterpret_cast<const char*>(node->name);
    auto* node_content = reinterpret_cast<const char*>(node->children->content);

    if (!strcmp(node_name, "offset")) {
      xar_file->offset = atol(node_content);
      is_offset_init = true;
    } else if (!strcmp(node_name, "length")) {
      xar_file->size = atol(node_content);
      is_size_init = true;
    }
    node = node->next;
  }

  return is_offset_init && is_size_init;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
addq $0x18, %r14
xorl %r15d, %r15d
leaq 0x19f6(%rip), %rsi      # 0x4056
xorl %ebp, %ebp
movq (%r14), %r14
testq %r14, %r14
je 0x26db
movq 0x18(%r14), %r12
testq %r12, %r12
jne 0x2679
addq $0x30, %r14
jmp 0x2662
movq 0x10(%r14), %r13
movq %r13, %rdi
movq %rsi, %rbx
callq 0x2200
testl %eax, %eax
je 0x26a3
movq %r13, %rdi
leaq 0x19c5(%rip), %rsi      # 0x405b
callq 0x2200
testl %eax, %eax
cmoveq %r14, %r15
jmp 0x26d2
movq 0x50(%r12), %rsi
leaq 0x18(%rsp), %r12
movq %r12, %rdi
leaq 0x7(%rsp), %rdx
callq 0x2bfc
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x21c0
movq %r12, %rdi
callq 0x20a0
movb $0x1, %bpl
addq $0x30, %r14
movq %rbx, %rsi
jmp 0x2662
testq %r15, %r15
setne %al
andb %al, %bpl
cmpb $0x1, %bpl
jne 0x2777
addq $0x18, %r15
movq 0x8(%rsp), %rbx
leaq 0x28(%rbx), %rax
movq %rax, 0x10(%rsp)
addq $0x20, %rbx
xorl %r14d, %r14d
leaq 0x1952(%rip), %rsi      # 0x4060
xorl %ebp, %ebp
movq (%r15), %r15
testq %r15, %r15
je 0x277b
movq 0x18(%r15), %rax
testq %rax, %rax
jne 0x2727
addq $0x30, %r15
jmp 0x2710
movq 0x10(%r15), %r13
movq 0x50(%rax), %r12
movq %r13, %rdi
callq 0x2200
testl %eax, %eax
je 0x2758
movq %r13, %rdi
leaq 0x1922(%rip), %rsi      # 0x4067
callq 0x2200
testl %eax, %eax
jne 0x276a
movb $0x1, %r14b
movq 0x10(%rsp), %r13
jmp 0x275e
movb $0x1, %bpl
movq %rbx, %r13
movq %r12, %rdi
callq 0x21b0
movq %rax, (%r13)
addq $0x30, %r15
leaq 0x18eb(%rip), %rsi      # 0x4060
jmp 0x2710
xorl %ebp, %ebp
jmp 0x277e
andb %r14b, %bpl
andb $0x1, %bpl
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq