// File: /workspace/github_c_makefile_star2_O2/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)
movq %rdi, 0x8(%rsp)
movups %xmm0, (%rdi)
cmpl $0xf, %edx
jbe 0x4c17
movq %rsi, %r14
movl 0xc(%rsi), %r15d
movl %r15d, %eax
shrl $0x4, %eax
cmpl $0xffffffe, %eax        # imm = 0xFFFFFFE
ja 0x4bf0
movl %edx, %r13d
leal 0x10(%r15), %r12d
cmpl %edx, %r12d
ja 0x4bf0
movl %ecx, %ebp
movl 0x4(%r14), %edx
cmpl $0x3, %edx
je 0x49f0
cmpl $0x8, %edx
je 0x49a6
cmpl $0xb, %edx
jne 0x4b51
cmpl $-0x15, %r15d
setae %al
leal 0x15(%r15), %ecx
cmpl %r13d, %ecx
seta %cl
orb %al, %cl
je 0x4c3e
leaq 0x10(%r14), %rdi
cmpl $-0x14, %r15d
setae %al
leal 0x14(%r15), %ecx
cmpl %r13d, %ecx
seta %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x4a3c
andl $0x0, 0x3(%rsp)
andl $0x0, (%rsp)
movl $0xffff, %r12d          # imm = 0xFFFF
jmp 0x4a5b
leaq 0x10(%r14), %rdi
leaq (%r14,%r15), %r12
addq $0x10, %r12
subl %r15d, %r13d
addl $-0x10, %r13d
movl %r15d, %esi
callq 0x5023
movq %rax, %r15
movq %r12, %rdi
movl %r13d, %esi
callq 0x5023
movq %r15, %r8
movq 0x8(%rsp), %rcx
movq $0x3, (%rcx)
movq %r15, 0x8(%rcx)
andq $0x0, 0x10(%rcx)
movq %rax, 0x18(%rcx)
jmp 0x4a8f
cmpl $-0x15, %r15d
ja 0x4c65
movl %r15d, %eax
addl $0x14, %eax
cmpl %r13d, %eax
ja 0x4c65
leaq 0x10(%r14), %rdi
movl 0x10(%r14,%r15), %r12d
movl %r15d, %esi
callq 0x5023
movq %rax, %r8
movq 0x8(%rsp), %rax
movq $0x2, (%rax)
movq %r8, 0x8(%rax)
andq $0x0, 0x10(%rax)
movl %r12d, 0x18(%rax)
andl $0x0, 0x1c(%rax)
jmp 0x4a8f
movl (%rdi,%r15), %r12d
andl $0x0, 0x3(%rsp)
andl $0x0, (%rsp)
testl %r12d, %r12d
je 0x4a5b
cmpl $0xffff, %r12d          # imm = 0xFFFF
jne 0x4c99
movl %r15d, %esi
callq 0x5023
movq 0x8(%rsp), %rdx
andq $0x0, 0x10(%rdx)
movq %rax, %r8
testl %r12d, %r12d
movq $0x1, (%rdx)
movq %rax, 0x8(%rdx)
setne 0x18(%rdx)
movl (%rsp), %eax
movl 0x3(%rsp), %ecx
movl %eax, 0x19(%rdx)
movl %ecx, 0x1c(%rdx)
testl %ebp, %ebp
je 0x4b3d
movl %ebp, %eax
subq %rax, %r14
movl 0x4(%r14), %eax
leaq (%r14,%rax), %r15
addq $0x14, %r15
movl -0x4(%r15), %r12d
addq %r12, %r12
xorl %eax, %eax
movq 0x4540(%rip), %rbx      # 0x8ff8
leaq 0x1a5c(%rip), %rsi      # 0x651b
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x4b35
movl %r13d, %ecx
cmpl %ebp, (%r15,%rcx,4)
jne 0x4b29
andl $0x0, (%r15,%rcx,4)
leal 0x1(%r13), %ecx
movl (%r15,%rcx,4), %edx
movl %edx, %ecx
andb $0x3, %cl
movl %edx, %r9d
shrb $0x2, %r9b
andb $0x4, %r9b
orb %cl, %r9b
movl %edx, %r14d
shrb $0x4, %r14b
andb $0x8, %r14b
orb %r9b, %r14b
orb %al, %r14b
testl $0xffffff6c, %edx       # imm = 0xFFFFFF6C
je 0x4b2c
movq (%rbx), %rdi
movq %r8, %rcx
xorl %eax, %eax
movq %r8, 0x10(%rsp)
callq 0x1100
leaq 0x19f9(%rip), %rsi      # 0x651b
movq 0x10(%rsp), %r8
jmp 0x4b2c
movl %eax, %r14d
addq $0x2, %r13
movl %r14d, %eax
jmp 0x4ac2
movq 0x8(%rsp), %rcx
movb %al, 0x10(%rcx)
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2008, %edx           # imm = 0x2008
jne 0x4b77
movq 0x4498(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x1932(%rip), %rdi      # 0x649c
pushq $0x3e
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
jmp 0x4bba
movq 0x447a(%rip), %rbx      # 0x8ff8
movq (%rbx), %rdi
leaq 0x1953(%rip), %rsi      # 0x64db
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rcx
leaq 0x1968(%rip), %rdi      # 0x6501
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
leaq 0x10(%r14), %rdi
movq %rdi, 0x10(%rsp)
movl %r15d, %esi
callq 0x4f1b
cmpl %r13d, %r12d
jb 0x4bc2
xorl %r8d, %r8d
jmp 0x4a8f
movq (%rbx), %rcx
leaq 0x193f(%rip), %rdi      # 0x650b
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
movq 0x10(%rsp), %rdi
addq %r15, %rdi
subl %r15d, %r13d
addl $-0x10, %r13d
movl %r13d, %esi
callq 0x4f1b
jmp 0x4bba
movq 0x4401(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x16f7(%rip), %rsi      # 0x62f8
leaq 0x1734(%rip), %rdx      # 0x633c
leaq 0x187d(%rip), %rcx      # 0x648c
movl $0xdf, %r8d
jmp 0x4c8a
movq 0x43da(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x16d0(%rip), %rsi      # 0x62f8
leaq 0x170d(%rip), %rdx      # 0x633c
leaq 0x1856(%rip), %rcx      # 0x648c
movl $0xdc, %r8d
jmp 0x4c8a
movq 0x43b3(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x16a9(%rip), %rsi      # 0x62f8
leaq 0x16e6(%rip), %rdx      # 0x633c
leaq 0x182f(%rip), %rcx      # 0x648c
movl $0xe2, %r8d
jmp 0x4c8a
movq 0x438c(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1682(%rip), %rsi      # 0x62f8
leaq 0x16bf(%rip), %rdx      # 0x633c
leaq 0x1808(%rip), %rcx      # 0x648c
movl $0xe6, %r8d
xorl %eax, %eax
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1170
movq 0x4358(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x164e(%rip), %rsi      # 0x62f8
leaq 0x18a9(%rip), %rdx      # 0x655a
leaq 0x18b2(%rip), %rcx      # 0x656a
movl $0xbf, %r8d
jmp 0x4c8a