// File: /workspace/github_c_makefile_star2_O1/pali[P]bmfdec/./bmfparse.c
// Function: parse_qualifier
static struct mof_qualifier parse_qualifier(char *buf, uint32_t size, uint32_t offset) {
  struct mof_qualifier out;
  memset(&out, 0, sizeof(out));
  uint32_t *buf2 = (uint32_t *)buf;
  if (size < 16) error("Invalid size");
  uint32_t type = buf2[1];
  uint32_t len = buf2[3];
  if (!check_sum(16, len, size)) error("Invalid size");
  switch (type) {
  case 0x0B:
    if (check_sum(16+4+1, len, size)) error("Invalid size");
    out = parse_qualifier_boolean(buf+16, len, !check_sum(16+4, len, size) ? 0xFFFF : *((uint32_t *)(buf+16+len)));
    break;
  case 0x03:
    if (!check_sum(16+4, len, size)) error("Invalid size");
    out = parse_qualifier_sint32(buf+16, len, *((int32_t *)(buf+16+len)));
    break;
  case 0x08:
    out = parse_qualifier_string(buf+16, len, buf+16+len, size-len-16);
    break;
  case 0x2008:
    fprintf(stderr, "Warning: ValueMap and Values qualifiers are not supported yet\n");
    break;
  default:
    fprintf(stderr, "Warning: Unknown qualifier type 0x%x\n", type);
    fprintf(stderr, "Hexdump:\n");
    dump_bytes(buf+16, len);
    if (len+16 < size) {
      fprintf(stderr, "...continue...\n");
      dump_bytes(buf+16+len, size-len-16);
    }
    break;
  }
  if (offset) {
    uint32_t i;
    uint32_t olen = ((uint32_t *)(buf-offset))[1];
    uint32_t count = ((uint32_t *)(buf-offset+olen+16))[0];
    for (i=0; i<count; ++i) {
      uint32_t *offset_addr = (uint32_t *)(buf-offset+olen+16+4) + 2*i;
      if (*offset_addr != offset)
        continue;
      *offset_addr = 0;
      uint32_t flavors = ((uint32_t *)(buf-offset+olen+16+4))[2*i+1];
      if (flavors & (1U << 0))
        out.toinstance = 1;
      if (flavors & (1U << 1))
        out.tosubclass = 1;
      if (flavors & (1U << 4))
        out.disableoverride = 1;
      if (flavors & (1U << 7))
        out.amended = 1;
      if (flavors & ~((1U << 0) | (1U << 1) | (1U << 4) | (1U << 7)))
        fprintf(stderr, "Warning: Unknown qualifier flavors 0x%x in second part for %s\n", flavors, out.name);
    }
  }
  return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
cmpl $0xf, %edx
jbe 0x5a2e
movq %rsi, %r14
movl 0xc(%rsi), %r15d
movl %r15d, %eax
shrl $0x4, %eax
cmpl $0xffffffe, %eax        # imm = 0xFFFFFFE
ja 0x5a29
movl %edx, %r12d
leal 0x10(%r15), %r13d
cmpl %edx, %r13d
ja 0x5a29
movl %ecx, %ebp
movq %rdi, %rbx
movl 0x4(%r14), %edx
cmpl $0xa, %edx
jg 0x5815
cmpl $0x3, %edx
je 0x589a
cmpl $0x8, %edx
jne 0x59c2
leaq 0x10(%r14), %rdi
leaq (%r14,%r15), %r13
addq $0x10, %r13
subl %r15d, %r12d
addl $-0x10, %r12d
movl %r15d, %esi
callq 0x5cbb
movq %rax, %r15
movq %r13, %rdi
movl %r12d, %esi
callq 0x5cbb
movq $0x3, (%rbx)
movq %r15, 0x8(%rbx)
movq $0x0, 0x10(%rbx)
movq %rax, 0x18(%rbx)
jmp 0x58e0
cmpl $0xb, %edx
jne 0x59b0
cmpl $-0x15, %r15d
setae %al
leal 0x15(%r15), %ecx
cmpl %r12d, %ecx
seta %cl
orb %al, %cl
je 0x5a33
leaq 0x10(%r14), %rdi
cmpl $-0x14, %r15d
setae %al
movl %r15d, %ecx
addl $0x14, %ecx
cmpl %r12d, %ecx
seta %cl
orb %al, %cl
movl $0xffff, %r12d          # imm = 0xFFFF
jne 0x585c
movl (%rdi,%r15), %r12d
testl %r12d, %r12d
je 0x586e
cmpl $0xffff, %r12d          # imm = 0xFFFF
jne 0x5a3d
movl %r15d, %esi
callq 0x5cbb
testl %r12d, %r12d
movq $0x1, (%rbx)
movq %rax, 0x8(%rbx)
movq $0x0, 0x10(%rbx)
setne 0x18(%rbx)
xorl %eax, %eax
movl %eax, 0x19(%rbx)
movl %eax, 0x1c(%rbx)
jmp 0x58e0
cmpl $-0x15, %r15d
ja 0x5a38
leal 0x14(%r15), %eax
cmpl %r12d, %eax
ja 0x5a38
leaq 0x10(%r14), %rdi
movl 0x10(%r14,%r15), %r12d
movl %r15d, %esi
callq 0x5cbb
movq $0x2, (%rbx)
movq %rax, 0x8(%rbx)
movq $0x0, 0x10(%rbx)
movl %r12d, 0x18(%rbx)
movl $0x0, 0x1c(%rbx)
testl %ebp, %ebp
je 0x599e
movl %ebp, %eax
subq %rax, %r14
movl 0x4(%r14), %eax
movl 0x10(%r14,%rax), %r13d
testq %r13, %r13
je 0x599e
addq %rax, %r14
addq $0x14, %r14
movq 0x8(%rbx), %rcx
movb 0x10(%rbx), %r12b
addq %r13, %r13
movq 0x56e0(%rip), %rdi      # 0xaff8
leaq 0x1bff(%rip), %rsi      # 0x751e
xorl %r15d, %r15d
movl %r15d, %eax
cmpl %ebp, (%r14,%rax,4)
jne 0x5962
movl $0x0, (%r14,%rax,4)
leal 0x1(%r15), %eax
movl (%r14,%rax,4), %edx
movl %edx, %eax
andb $0x3, %al
movl %edx, %r8d
shrb $0x2, %r8b
andb $0x4, %r8b
orb %al, %r8b
movl %edx, %eax
shrb $0x4, %al
andb $0x8, %al
orb %r8b, %al
orb %al, %r12b
testl $0xffffff6c, %edx       # imm = 0xFFFFFF6C
jne 0x596d
addq $0x2, %r15
cmpq %r15, %r13
jne 0x5922
jmp 0x599a
movq %rbx, 0x10(%rsp)
movq %rdi, %rbx
movq (%rdi), %rdi
xorl %eax, %eax
movq %rcx, 0x8(%rsp)
callq 0x1100
leaq 0x1b93(%rip), %rsi      # 0x751e
movq %rbx, %rdi
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rcx
jmp 0x5962
movb %r12b, 0x10(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2008, %edx           # imm = 0x2008
jne 0x59c2
callq 0x25e2
jmp 0x58e0
movq 0x562f(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x1b0b(%rip), %rsi      # 0x74de
xorl %eax, %eax
callq 0x1100
movq 0x5617(%rip), %rax      # 0xaff8
movq (%rax), %rcx
leaq 0x1b19(%rip), %rdi      # 0x7504
movl $0x9, %esi
movl $0x1, %edx
callq 0x1180
leaq 0x10(%r14), %rdi
movq %rdi, 0x8(%rsp)
movl %r15d, %esi
callq 0x5be3
cmpl %r12d, %r13d
jae 0x58e0
movl %r15d, %edi
movq 0x8(%rsp), %rsi
movl %r12d, %edx
callq 0x269d
jmp 0x58e0
callq 0x26d9
callq 0x270e
callq 0x2633
callq 0x25fe
callq 0x2668