// File: /workspace/github_c_makefile_star2_O2/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 $0xf8, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl %ecx, %edi
callq 0xe90a
movq (%r14), %rax
movq (%rax), %rsi
leaq 0x69b6(%rip), %rdi      # 0x14c1c
xorl %eax, %eax
callq 0x5050
movq (%r14), %rax
movl 0x24(%rax), %eax
cmpq $0x6, %rax
ja 0xe835
leaq 0x68c4(%rip), %rcx      # 0x14b48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xec4c
movq %rbx, %rsi
callq 0xe89e
leaq 0xf0(%rsp), %rdi
jmp 0xe830
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xebae
movq (%rbx), %rax
movl 0x28(%rax), %ebx
leaq 0x28(%rsp), %rdi
callq 0x61e4
cmpq $0x5, %rbx
ja 0xe835
leaq 0x688e(%rip), %rax      # 0x14b74
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x68df(%rip), %rdi      # 0x14bd5
jmp 0xe7f9
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xebca
movq (%rbx), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
leaq 0x68ca(%rip), %rdi      # 0x14be9
xorl %eax, %eax
callq 0x5050
movq (%rbx), %r12
movq 0x50(%r12), %r14
addq $0x40, %r12
leaq 0x20(%rsp), %rbx
leaq 0x68b8(%rip), %r15      # 0x14bf6
cmpq %r12, %r14
je 0xe762
leaq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0xecb0
movq 0x20(%rsp), %rsi
movl 0x40(%rsp), %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x5050
movq %rbx, %rdi
callq 0x5140
movq %r14, %rdi
callq 0x5190
movq %rax, %r14
jmp 0xe33e
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xec68
movq (%r14), %rax
movl 0x20(%rax), %esi
leaq 0x688f(%rip), %rdi      # 0x14c27
xorl %eax, %eax
callq 0x5050
movq (%r15), %rax
movq 0x28(%rax), %r13
movq 0x30(%rax), %r12
movq 0x18(%rsp), %rax
incl %eax
movl %eax, 0x4(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x48(%rsp)
movl %ebp, %r15d
shrl $0x10, %r15d
movzwl %bp, %eax
movl %eax, 0x8(%rsp)
addq $0x20, %r13
leaq 0x6849(%rip), %r14      # 0x14c21
movq %r12, 0x50(%rsp)
leaq -0x20(%r13), %rax
cmpq %r12, %rax
je 0xe74b
movq -0x20(%r13), %rsi
leaq 0x6825(%rip), %rdi      # 0x14c1a
xorl %eax, %eax
callq 0x5050
movq (%r13), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0xe46a
cmpl $0x4, %ecx
je 0xe43b
cmpl $0x5, %ecx
jne 0xe4aa
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xec4c
movq %rbx, %rsi
callq 0xe89e
leaq 0xd0(%rsp), %rdi
jmp 0xe463
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x61a4
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0xe232
leaq 0x70(%rsp), %rdi
callq 0x61e4
jmp 0xe4bb
movl %r15d, %ebx
movq %r14, %r15
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x61a4
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0xe232
leaq 0x60(%rsp), %rdi
callq 0x61e4
movq %r15, %r14
movl %ebx, %r15d
movq 0x50(%rsp), %r12
jmp 0xe4bb
movq (%rax), %rsi
leaq 0x6716(%rip), %rdi      # 0x14bca
xorl %eax, %eax
callq 0x5050
movq %r14, %rdi
xorl %eax, %eax
callq 0x5050
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0xe4e4
leaq 0x67b5(%rip), %rdi      # 0x14c89
movl %r15d, %esi
movl 0x8(%rsp), %edx
xorl %eax, %eax
callq 0x5050
jmp 0xe4f4
leaq 0x6773(%rip), %rdi      # 0x14c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5050
addq $0x30, %r13
jmp 0xe3dd
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6055
leaq 0x6095(%rip), %rdi      # 0x145a9
callq 0x5340
movq (%rbx), %rax
movq 0x28(%rax), %r13
movq 0x30(%rax), %rbp
leaq 0xc0(%rsp), %rbx
leaq 0x66e7(%rip), %r14      # 0x14c1a
leaq 0xb8(%rsp), %r15
leaq 0x6752(%rip), %r12      # 0x14c94
cmpq %rbp, %r13
je 0xe57f
movq (%r13), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x5050
leaq 0x20(%r13), %rsi
movq %r15, %rdi
callq 0xed1a
movq %r15, %rsi
callq 0xe89e
movq %rbx, %rdi
callq 0x61e4
movq %r12, %rdi
callq 0x5340
addq $0x30, %r13
jmp 0xe542
movq 0x20(%rsp), %rax
movq 0x40(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0xe777
leaq 0x66a3(%rip), %rdi      # 0x14c3d
xorl %eax, %eax
callq 0x5050
movq 0x20(%rsp), %rsi
addq $0x40, %rsi
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
callq 0xed1a
movq %rbx, %rsi
callq 0xe89e
leaq 0xb0(%rsp), %rdi
callq 0x61e4
jmp 0xe77f
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xec68
movq (%r14), %rax
movl 0x20(%rax), %esi
leaq 0x6612(%rip), %rdi      # 0x14c03
xorl %eax, %eax
callq 0x5050
movq (%r15), %rax
movq 0x28(%rax), %r13
movq 0x30(%rax), %r14
movq 0x18(%rsp), %rax
incl %eax
movl %eax, 0x4(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x20, %r13
leaq 0x65fb(%rip), %r12      # 0x14c21
leaq -0x20(%r13), %r15
movq 0x18(%rsp), %rdi
callq 0xe90a
cmpq %r14, %r15
je 0xe755
movq -0x20(%r13), %rsi
leaq 0x65d2(%rip), %rdi      # 0x14c1a
xorl %eax, %eax
callq 0x5050
movq (%r13), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0xe6bb
cmpl $0x4, %ecx
je 0xe68e
cmpl $0x5, %ecx
jne 0xe6f0
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xec4c
movq %r15, %rsi
callq 0xe89e
leaq 0xe0(%rsp), %rdi
jmp 0xe6e9
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x61a4
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0xe232
leaq 0x80(%rsp), %rdi
jmp 0xe6e9
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x61a4
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0xe232
leaq 0x90(%rsp), %rdi
callq 0x61e4
jmp 0xe701
movq (%rax), %rsi
leaq 0x64d0(%rip), %rdi      # 0x14bca
xorl %eax, %eax
callq 0x5050
movq %r12, %rdi
xorl %eax, %eax
callq 0x5050
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0xe72b
movl %ebp, %esi
shrl $0x10, %esi
movzwl %bp, %edx
leaq 0x6567(%rip), %rdi      # 0x14c89
xorl %eax, %eax
callq 0x5050
jmp 0xe73b
leaq 0x652c(%rip), %rdi      # 0x14c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5050
movq (%r13), %rax
addl 0x20(%rax), %ebp
addq $0x30, %r13
jmp 0xe626
movq 0x18(%rsp), %rdi
callq 0xe90a
pushq $0x7d
popq %rdi
callq 0x52d0
jmp 0xe82b
pushq $0x7d
popq %rdi
callq 0x52d0
leaq 0xa0(%rsp), %rdi
jmp 0xe830
pushq $0x29
popq %rdi
callq 0x52d0
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movl (%rax), %esi
testl %esi, %esi
js 0xe7a4
movl 0x4(%rax), %edx
leaq 0x64a9(%rip), %rdi      # 0x14c41
xorl %eax, %eax
callq 0x5050
jmp 0xe82b
addl $0x4, %esi
cmpl $0x3, %esi
ja 0xe82b
leaq 0x63b1(%rip), %rcx      # 0x14b64
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl 0x4(%rax), %esi
movzwl %si, %edx
sarl $0x10, %esi
leaq 0x64b9(%rip), %rdi      # 0x14c85
jmp 0xe798
leaq 0x6407(%rip), %rdi      # 0x14bdc
jmp 0xe7f9
leaq 0x6404(%rip), %rdi      # 0x14be2
jmp 0xe7f9
leaq 0x63ef(%rip), %rdi      # 0x14bd6
jmp 0xe7f9
leaq 0x63eb(%rip), %rdi      # 0x14bdb
jmp 0xe7f9
leaq 0x63ea(%rip), %rdi      # 0x14be3
xorl %eax, %eax
callq 0x5050
jmp 0xe835
movl 0x8(%rax), %esi
leaq 0x6458(%rip), %rdi      # 0x14c64
jmp 0xe824
movl 0x8(%rax), %esi
leaq 0x643d(%rip), %rdi      # 0x14c55
jmp 0xe824
movl 0x8(%rax), %esi
leaq 0x644d(%rip), %rdi      # 0x14c71
xorl %eax, %eax
callq 0x5050
leaq 0x28(%rsp), %rdi
callq 0x61e4
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xe86b
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0xe875
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
jmp 0xe87a
movq %rax, %rbx
movq 0x48(%rsp), %rdi
callq 0x61e4
leaq 0x28(%rsp), %rdi
jmp 0xe891
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x61e4
movq %rbx, %rdi
callq 0x53c0