// File: /workspace/github_c_makefile_star2_O1/mrkite[P]regs/src/api.cc
// Function: API::dumpSymbol(std::shared_ptr<symbol::Symbol>, unsigned int, int)
void API::dumpSymbol(std::shared_ptr<symbol::Symbol> sym, uint32_t org, int depth) {
  indent(depth);
  printf("%s: ", sym->name.c_str());
  switch (sym->kind) {
    case symbol::Kind::isIntrinsic:
      switch (std::static_pointer_cast<symbol::Intrinsic>(sym)->type) {
        case symbol::Intrinsic::U8:
          printf("uint8");
          break;
        case symbol::Intrinsic::U16:
          printf("uint16");
          break;
        case symbol::Intrinsic::U32:
          printf("uint32");
          break;
        case symbol::Intrinsic::S8:
          printf("int8");
          break;
        case symbol::Intrinsic::S16:
          printf("int16");
          break;
        case symbol::Intrinsic::S32:
          printf("int32");
          break;
      }
      break;
    case symbol::Kind::isEnum:
      {
        auto e = std::static_pointer_cast<symbol::Enum>(sym);
        printf("enum : %s {\n", e->type->name.c_str());
        for (auto entry : e->entries) {
          printf("  %s = $%x,\n", entry.first.c_str(), entry.second);
        }
        printf("}");
      }
      break;
    case symbol::Kind::isAlias:
    case symbol::Kind::isRef:
      dumpRef(std::static_pointer_cast<symbol::Ref>(sym));
      break;
    case symbol::Kind::isStruct:
      {
        auto s = std::static_pointer_cast<symbol::Struct>(sym);
        printf("struct { // $%x bytes\n", sym->size);
        for (auto &f : s->fields) {
          indent(depth);
          printf("  %s: ", f.key.c_str());
          switch (f.value->kind) {
            case symbol::Kind::isRef:
              dumpRef(std::static_pointer_cast<symbol::Ref>(f.value));
              break;
            case symbol::Kind::isStruct:
              dumpSymbol(f.value, org, depth + 1);
              break;
            case symbol::Kind::isUnion:
              dumpSymbol(f.value, org, depth + 1);
              break;
            default:
              printf("%s", f.value->name.c_str());
              break;
          }
          printf(" // $");
          if (org > 0xffff) {
            printf("%02x/%04x\n", org >> 16, org & 0xffff);
          } else {
            printf("%04x\n", org);
          }
          org += f.value->size;
        }
        indent(depth);
        printf("}");
      }
      break;
    case symbol::Kind::isUnion:
      {
        auto s = std::static_pointer_cast<symbol::Struct>(sym);
        printf("union { // $%x bytes\n", sym->size);
        for (auto &f : s->fields) {
          printf("  %s: ", f.key.c_str());
          switch (f.value->kind) {
            case symbol::Kind::isRef:
              dumpRef(std::static_pointer_cast<symbol::Ref>(f.value));
              break;
            case symbol::Kind::isUnion:
              dumpSymbol(f.value, org, depth + 1);
              break;
            case symbol::Kind::isStruct:
              dumpSymbol(f.value, org, depth + 1);
              break;
            default:
              printf("%s", f.value->name.c_str());
              break;
          }
          printf(" // $");
          if (org > 0xffff) {
            printf("%02x/%04x\n", org >> 16, org & 0xffff);
          } else {
            printf("%04x\n", org);
          }
        }
        indent(depth);
        printf("}");
      }
      break;
    case symbol::Kind::isFunction:
      {
        auto f = std::static_pointer_cast<symbol::Function>(sym);
        printf("(\n");
        for (auto &a : f->arguments) {
          printf("  %s: ", a.key.c_str());
          dumpRef(a.ref);
          printf(",\n");
        }
        if (f->returnType->symbol != nullptr) {
          printf("): ");
          dumpRef(f->returnType);
        } else {
          printf(")");
        }
        if (f->signature[0] >= 0) {  // tool
          printf(" = TOOL $%02x:%02x\n", f->signature[0],
                 f->signature[1]);
        } else if (f->signature[0] == -1) {  // p16/gsos
          printf(" = GSOS $%04x\n", f->signature[2]);
        } else if (f->signature[0] == -2) {  // p8
          printf(" = P8 $%02x\n", f->signature[2]);
        } else if (f->signature[0] == -3) {  // smartport
          printf(" = Smartport $%02x\n", f->signature[2]);
        } else if (f->signature[0] == -4) {  // symbol
          printf(" = $%02x/%04x\n", f->signature[1] >> 16,
                 f->signature[1] & 0xffff);
        }
      }
      break;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %ecx, %r14d
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
testl %ecx, %ecx
jle 0x1158d
leaq 0x6921(%rip), %r12      # 0x17e9c
movl %r14d, %r15d
movq %r12, %rdi
xorl %eax, %eax
callq 0x5060
decl %r15d
jne 0x1157e
movq (%rbx), %rax
movq (%rax), %rsi
leaq 0x6682(%rip), %rdi      # 0x17c1c
xorl %eax, %eax
callq 0x5060
movq (%rbx), %r13
movl 0x24(%r13), %eax
cmpq $0x6, %rax
ja 0x11d90
leaq 0x658f(%rip), %rcx      # 0x17b48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, 0xa0(%rsp)
movq 0x8(%rbx), %rax
movq %rax, 0xa8(%rsp)
testq %rax, %rax
je 0x116b4
movq 0xf9e2(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x116b0
incl 0x8(%rax)
jmp 0x116b4
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x116d1
movq 0xf9bd(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x116cd
incl 0x8(%rdi)
jmp 0x116d1
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x1170a
movq 0xf998(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11706
incl 0x8(%rcx)
jmp 0x1170a
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x117d2
movq 0xf973(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x117ce
incl 0x8(%rcx)
jmp 0x117d2
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x11996
movq 0xf94e(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11992
incl 0x8(%rcx)
jmp 0x11996
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x11a98
movq 0xf929(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11a94
incl 0x8(%rcx)
jmp 0x11a98
lock
incl 0x8(%rax)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
callq 0x11df2
movq 0x8(%rbx), %rdi
jmp 0x11c88
lock
incl 0x8(%rdi)
movl 0x28(%r13), %ebx
testq %rdi, %rdi
je 0x116df
callq 0x6752
cmpl $0x5, %ebx
ja 0x11d90
movl %ebx, %eax
leaq 0x6483(%rip), %rcx      # 0x17b74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x64d4(%rip), %rdi      # 0x17bd5
jmp 0x11d31
lock
incl 0x8(%rcx)
movq %rcx, 0x8(%rsp)
movq 0x28(%r13), %rax
movq (%rax), %rsi
leaq 0x64cc(%rip), %rdi      # 0x17be9
xorl %eax, %eax
callq 0x5060
movq 0x50(%r13), %rbx
addq $0x40, %r13
cmpq %r13, %rbx
je 0x117ac
leaq 0xc0(%rsp), %r12
leaq 0xb0(%rsp), %r14
leaq 0x64ae(%rip), %r15      # 0x17bf6
movq %r12, 0xb0(%rsp)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x68c2
movl 0x40(%rbx), %edx
movl %edx, 0xd0(%rsp)
movq 0xb0(%rsp), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x5060
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x1179c
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x5230
movq %rbx, %rdi
callq 0x51a0
movq %rax, %rbx
cmpq %r13, %rax
jne 0x11748
movl $0x7d, %edi
callq 0x52e0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x11d90
callq 0x6752
jmp 0x11d90
lock
incl 0x8(%rcx)
movq %rcx, 0x8(%rsp)
movq (%rbx), %rax
movl 0x20(%rax), %esi
leaq 0x6443(%rip), %rdi      # 0x17c27
xorl %eax, %eax
callq 0x5060
movq 0x28(%r13), %rbx
movq 0x30(%r13), %r13
cmpq %r13, %rbx
je 0x1196e
leal 0x1(%r14), %r15d
movl %ebp, %r12d
shrl $0x10, %r12d
movzwl %bp, %eax
movl %eax, 0x14(%rsp)
addq $0x28, %rbx
movq -0x28(%rbx), %rsi
leaq 0x63fd(%rip), %rdi      # 0x17c1a
xorl %eax, %eax
callq 0x5060
movq -0x8(%rbx), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0x1188b
cmpl $0x4, %ecx
je 0x11868
cmpl $0x5, %ecx
jne 0x118ae
movq %rax, 0x70(%rsp)
movq (%rbx), %rax
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x11903
movq 0xf771(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x118ff
incl 0x8(%rax)
jmp 0x11903
movq %rax, 0x30(%rsp)
movq (%rbx), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x118c5
movq 0xf747(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x118c1
incl 0x8(%rax)
jmp 0x118c5
movq %rax, 0x20(%rsp)
movq (%rbx), %rax
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x118e4
movq 0xf724(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x118e0
incl 0x8(%rax)
jmp 0x118e4
movq (%rax), %rsi
leaq 0x6312(%rip), %rdi      # 0x17bca
xorl %eax, %eax
callq 0x5060
jmp 0x1191c
lock
incl 0x8(%rax)
movq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x11552
movq 0x38(%rsp), %rdi
jmp 0x11912
lock
incl 0x8(%rax)
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x11552
movq 0x28(%rsp), %rdi
jmp 0x11912
lock
incl 0x8(%rax)
leaq 0x70(%rsp), %rsi
callq 0x11df2
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x1191c
callq 0x6752
leaq 0x62fe(%rip), %rdi      # 0x17c21
xorl %eax, %eax
callq 0x5060
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0x11949
leaq 0x6350(%rip), %rdi      # 0x17c89
movl %r12d, %esi
movl 0x14(%rsp), %edx
xorl %eax, %eax
callq 0x5060
jmp 0x11959
leaq 0x630e(%rip), %rdi      # 0x17c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5060
leaq -0x28(%rbx), %rax
addq $0x30, %rbx
addq $0x30, %rax
cmpq %r13, %rax
jne 0x11812
testl %r14d, %r14d
jle 0x11c79
leaq 0x651e(%rip), %rbx      # 0x17e9c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5060
decl %r14d
jne 0x1197e
jmp 0x11c79
lock
incl 0x8(%rcx)
movq %rcx, 0x18(%rsp)
leaq 0x5c07(%rip), %rdi      # 0x175a9
callq 0x5350
movq 0x28(%r13), %rbp
movq 0x30(%r13), %rbx
cmpq %rbx, %rbp
je 0x11a29
leaq 0x625f(%rip), %r14      # 0x17c1a
leaq 0x60(%rsp), %r15
leaq 0x62cd(%rip), %r12      # 0x17c94
movq (%rbp), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x5060
movq 0x20(%rbp), %rax
movq %rax, 0x60(%rsp)
movq 0x28(%rbp), %rax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x11a01
movq 0xf5d5(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x119fd
incl 0x8(%rax)
jmp 0x11a01
lock
incl 0x8(%rax)
movq %r15, %rsi
callq 0x11df2
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x11a18
callq 0x6752
movq %r12, %rdi
callq 0x5350
addq $0x30, %rbp
cmpq %rbx, %rbp
jne 0x119c7
movq 0x40(%r13), %rax
cmpq $0x0, 0x28(%rax)
je 0x11a80
leaq 0x6202(%rip), %rdi      # 0x17c3d
xorl %eax, %eax
callq 0x5060
movq 0x40(%r13), %rax
movq %rax, 0x90(%rsp)
movq 0x48(%r13), %rax
movq %rax, 0x98(%rsp)
testq %rax, %rax
movq 0x18(%rsp), %rbx
je 0x11c9a
movq 0xf559(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11c96
incl 0x8(%rax)
jmp 0x11c9a
movl $0x29, %edi
callq 0x52e0
movq 0x18(%rsp), %rbx
jmp 0x11cb8
lock
incl 0x8(%rcx)
movq %rcx, 0x8(%rsp)
movq (%rbx), %rax
movl 0x20(%rax), %esi
leaq 0x6159(%rip), %rdi      # 0x17c03
xorl %eax, %eax
callq 0x5060
movq 0x28(%r13), %r12
movq 0x30(%r13), %rbx
cmpq %rbx, %r12
je 0x11c5e
leal 0x1(%r14), %eax
movl %eax, 0x14(%rsp)
leaq 0x63cb(%rip), %r13      # 0x17e9c
testl %r14d, %r14d
jle 0x11ae8
movl %r14d, %r15d
movq %r13, %rdi
xorl %eax, %eax
callq 0x5060
decl %r15d
jne 0x11ad9
movq (%r12), %rsi
leaq 0x6127(%rip), %rdi      # 0x17c1a
xorl %eax, %eax
callq 0x5060
movq 0x20(%r12), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0x11b70
cmpl $0x4, %ecx
je 0x11b4b
cmpl $0x5, %ecx
jne 0x11b95
movq %rax, 0x80(%rsp)
movq 0x28(%r12), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
je 0x11bec
movq 0xf48e(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11be8
incl 0x8(%rax)
jmp 0x11bec
movq %rax, 0x40(%rsp)
movq 0x28(%r12), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x11bac
movq 0xf462(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11ba8
incl 0x8(%rax)
jmp 0x11bac
movq %rax, 0x50(%rsp)
movq 0x28(%r12), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x11bcc
movq 0xf43d(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11bc8
incl 0x8(%rax)
jmp 0x11bcc
movq (%rax), %rsi
leaq 0x602b(%rip), %rdi      # 0x17bca
xorl %eax, %eax
callq 0x5060
jmp 0x11c0b
lock
incl 0x8(%rax)
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
callq 0x11552
movq 0x48(%rsp), %rdi
jmp 0x11c01
lock
incl 0x8(%rax)
movq 0x18(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
callq 0x11552
movq 0x58(%rsp), %rdi
jmp 0x11c01
lock
incl 0x8(%rax)
leaq 0x80(%rsp), %rsi
callq 0x11df2
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x11c0b
callq 0x6752
leaq 0x600f(%rip), %rdi      # 0x17c21
xorl %eax, %eax
callq 0x5060
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0x11c39
movl %ebp, %esi
shrl $0x10, %esi
movzwl %bp, %edx
leaq 0x6059(%rip), %rdi      # 0x17c89
xorl %eax, %eax
callq 0x5060
jmp 0x11c49
leaq 0x601e(%rip), %rdi      # 0x17c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5060
movq 0x20(%r12), %rax
addl 0x20(%rax), %ebp
addq $0x30, %r12
cmpq %rbx, %r12
jne 0x11ad1
testl %r14d, %r14d
jle 0x11c79
leaq 0x6232(%rip), %rbx      # 0x17e9c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5060
decl %r14d
jne 0x11c6a
movl $0x7d, %edi
callq 0x52e0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x11d7a
jmp 0x11d90
lock
incl 0x8(%rax)
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x11df2
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x11cb8
callq 0x6752
movq 0x50(%r13), %rax
movl (%rax), %esi
testl %esi, %esi
js 0x11cd8
movl 0x4(%rax), %edx
leaq 0x5f75(%rip), %rdi      # 0x17c41
xorl %eax, %eax
callq 0x5060
jmp 0x11d72
addl $0x4, %esi
cmpl $0x3, %esi
ja 0x11d72
leaq 0x5e79(%rip), %rcx      # 0x17b64
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl 0x4(%rax), %esi
movzwl %si, %edx
sarl $0x10, %esi
leaq 0x5f81(%rip), %rdi      # 0x17c85
jmp 0x11ccc
leaq 0x5ecf(%rip), %rdi      # 0x17bdc
jmp 0x11d31
leaq 0x5ecc(%rip), %rdi      # 0x17be2
jmp 0x11d31
leaq 0x5eb7(%rip), %rdi      # 0x17bd6
jmp 0x11d31
leaq 0x5eb3(%rip), %rdi      # 0x17bdb
jmp 0x11d31
leaq 0x5eb2(%rip), %rdi      # 0x17be3
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5060
movl 0x8(%rax), %esi
leaq 0x5f11(%rip), %rdi      # 0x17c64
jmp 0x11d6b
movl 0x8(%rax), %esi
leaq 0x5ef6(%rip), %rdi      # 0x17c55
jmp 0x11d6b
movl 0x8(%rax), %esi
leaq 0x5f06(%rip), %rdi      # 0x17c71
xorl %eax, %eax
callq 0x5060
testq %rbx, %rbx
je 0x11d90
movq %rbx, %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6752
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x58(%rsp), %rdi
jmp 0x11dc8
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x11dc8
movq %rax, %rbx
movq 0x48(%rsp), %rdi
jmp 0x11dc8
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x11dd7
callq 0x6752
jmp 0x11dd7
movq %rax, %rbx
cmpq $0x0, 0x8(%rsp)
je 0x11de9
movq 0x8(%rsp), %rdi
callq 0x6752
movq %rbx, %rdi
callq 0x53e0
nop