// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
testl %ecx, %ecx
jle 0x1128e
leaq 0x6c20(%rip), %r12      # 0x17e9c
movl %ebx, %r14d
movq %r12, %rdi
xorl %eax, %eax
callq 0x5060
decl %r14d
jne 0x1127f
movq (%r15), %rax
movq (%rax), %rsi
leaq 0x6981(%rip), %rdi      # 0x17c1c
xorl %eax, %eax
callq 0x5060
movq (%r15), %r12
movl 0x24(%r12), %eax
cmpq $0x6, %rax
ja 0x11b38
leaq 0x688d(%rip), %rcx      # 0x17b48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, 0x90(%rsp)
movq 0x8(%r15), %rbx
movq %rbx, 0x98(%rsp)
testq %rbx, %rbx
je 0x113cb
movq 0xfce0(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x113dd
incl 0x8(%rbx)
leaq 0x90(%rsp), %rsi
callq 0x11bbc
jmp 0x11b1f
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x113f7
movq 0xfcae(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x113fe
incl 0x8(%rdi)
jmp 0x11402
movq 0x8(%r15), %rbx
testq %rbx, %rbx
je 0x11437
movq 0xfc89(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11433
incl 0x8(%rbx)
jmp 0x11437
movq 0x8(%r15), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0x114fe
movq 0xfc61(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x114f7
incl 0x8(%rcx)
movq %r12, %rax
jmp 0x114fe
movq 0x8(%r15), %rcx
testq %rcx, %rcx
je 0x116eb
movq 0xfc39(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x116e7
incl 0x8(%rcx)
jmp 0x116eb
movq 0x8(%r15), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0x1182c
movq 0xfc11(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11825
incl 0x8(%rcx)
movq %r12, %rax
jmp 0x1182c
leaq 0x90(%rsp), %rsi
callq 0x11bbc
jmp 0x11b38
lock
incl 0x8(%rbx)
leaq 0x90(%rsp), %rsi
movq 0x8(%rsi), %rbx
callq 0x11bbc
jmp 0x11b1a
movl 0x28(%r12), %ebx
jmp 0x1140c
lock
incl 0x8(%rdi)
movl 0x28(%r12), %ebx
callq 0x671a
cmpl $0x5, %ebx
ja 0x11b38
movl %ebx, %eax
leaq 0x6756(%rip), %rcx      # 0x17b74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x67a7(%rip), %rdi      # 0x17bd5
jmp 0x11ad9
lock
incl 0x8(%rbx)
movq 0x28(%r12), %rax
movq (%rax), %rsi
leaq 0x67a3(%rip), %rdi      # 0x17be9
xorl %eax, %eax
callq 0x5060
movq 0x50(%r12), %r14
addq $0x40, %r12
cmpq %r12, %r14
je 0x114d7
leaq 0xc0(%rsp), %rbp
leaq 0xb0(%rsp), %r15
leaq 0x6784(%rip), %r13      # 0x17bf6
movq %rbp, 0xb0(%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x688a
movl 0x40(%r14), %edx
movl %edx, 0xd0(%rsp)
movq 0xb0(%rsp), %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x5060
movq 0xb0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x114c7
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r14, %rdi
callq 0x51a0
movq %rax, %r14
cmpq %r12, %rax
jne 0x11472
movl $0x7d, %edi
callq 0x52e0
testq %rbx, %rbx
je 0x11b38
movq %rbx, %rdi
callq 0x671a
jmp 0x11b38
lock
incl 0x8(%rcx)
movq (%r15), %rax
movq %rcx, 0x18(%rsp)
movl 0x20(%rax), %esi
leaq 0x671a(%rip), %rdi      # 0x17c27
xorl %eax, %eax
callq 0x5060
movq 0x28(%r12), %r14
movq 0x30(%r12), %r12
cmpq %r12, %r14
je 0x116ba
leal 0x1(%rbx), %eax
movl %eax, 0x4(%rsp)
movl %ebp, %r13d
shrl $0x10, %r13d
movzwl %bp, %eax
movl %eax, 0x10(%rsp)
addq $0x28, %r14
movq -0x28(%r14), %rsi
leaq 0x66cf(%rip), %rdi      # 0x17c1a
xorl %eax, %eax
callq 0x5060
movq -0x8(%r14), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0x115c0
cmpl $0x4, %ecx
je 0x1159d
cmpl $0x5, %ecx
jne 0x115e3
movq %rax, 0x20(%rsp)
movq (%r14), %r15
movq %r15, 0x28(%rsp)
testq %r15, %r15
je 0x115f6
movq 0xfa47(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11647
incl 0x8(%r15)
leaq 0x20(%rsp), %rsi
callq 0x11bbc
jmp 0x11660
movq %rax, 0x60(%rsp)
movq (%r14), %rax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x11606
movq 0xfa12(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11602
incl 0x8(%rax)
jmp 0x11606
movq %rax, 0x50(%rsp)
movq (%r14), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x11626
movq 0xf9ef(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x11622
incl 0x8(%rax)
jmp 0x11626
movq (%rax), %rsi
leaq 0x65dd(%rip), %rdi      # 0x17bca
xorl %eax, %eax
callq 0x5060
jmp 0x11668
leaq 0x20(%rsp), %rsi
callq 0x11bbc
jmp 0x11668
lock
incl 0x8(%rax)
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0x11254
movq 0x68(%rsp), %rdi
jmp 0x11640
lock
incl 0x8(%rax)
movq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0x11254
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
jne 0x11663
jmp 0x11668
lock
incl 0x8(%r15)
movq 0x28(%rsp), %r15
leaq 0x20(%rsp), %rsi
callq 0x11bbc
testq %r15, %r15
je 0x11668
movq %r15, %rdi
callq 0x671a
leaq 0x65b2(%rip), %rdi      # 0x17c21
xorl %eax, %eax
callq 0x5060
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0x11695
leaq 0x6604(%rip), %rdi      # 0x17c89
movl %r13d, %esi
movl 0x10(%rsp), %edx
xorl %eax, %eax
callq 0x5060
jmp 0x116a5
leaq 0x65c2(%rip), %rdi      # 0x17c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5060
leaq -0x28(%r14), %rax
addq $0x30, %r14
addq $0x30, %rax
cmpq %r12, %rax
jne 0x11540
testl %ebx, %ebx
jle 0x116d3
leaq 0x67d7(%rip), %r14      # 0x17e9c
movq %r14, %rdi
xorl %eax, %eax
callq 0x5060
decl %ebx
jne 0x116c5
movl $0x7d, %edi
callq 0x52e0
movq 0x18(%rsp), %rdi
jmp 0x11a31
lock
incl 0x8(%rcx)
movq %rcx, 0x8(%rsp)
leaq 0x5eb2(%rip), %rdi      # 0x175a9
callq 0x5350
movq 0x28(%r12), %rbx
movq 0x30(%r12), %r14
cmpq %r14, %rbx
je 0x117a7
leaq 0xa0(%rsp), %r15
leaq 0x6576(%rip), %rbp      # 0x17c94
movq (%rbx), %rsi
leaq 0x64f2(%rip), %rdi      # 0x17c1a
xorl %eax, %eax
callq 0x5060
movq 0x20(%rbx), %rax
movq %rax, 0xa0(%rsp)
movq 0x28(%rbx), %r13
movq %r13, 0xa8(%rsp)
testq %r13, %r13
je 0x11766
movq 0xf875(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11770
incl 0x8(%r13)
movq %r15, %rsi
callq 0x11bbc
jmp 0x1178a
movq %r15, %rsi
callq 0x11bbc
jmp 0x11792
lock
incl 0x8(%r13)
movq 0xa8(%rsp), %r13
movq %r15, %rsi
callq 0x11bbc
testq %r13, %r13
je 0x11792
movq %r13, %rdi
callq 0x671a
movq %rbp, %rdi
callq 0x5350
addq $0x30, %rbx
cmpq %r14, %rbx
jne 0x1171e
movq 0x40(%r12), %rax
cmpq $0x0, 0x28(%rax)
je 0x11802
leaq 0x6483(%rip), %rdi      # 0x17c3d
xorl %eax, %eax
callq 0x5060
movq 0x40(%r12), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%r12), %r14
movq %r14, 0x48(%rsp)
testq %r14, %r14
movq 0x8(%rsp), %rbx
je 0x11816
movq 0xf7e2(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11a3f
incl 0x8(%r14)
leaq 0x40(%rsp), %rsi
callq 0x11bbc
jmp 0x11a57
movl $0x29, %edi
callq 0x52e0
movq 0x8(%rsp), %rbx
jmp 0x11a5f
leaq 0x40(%rsp), %rsi
callq 0x11bbc
jmp 0x11a5f
lock
incl 0x8(%rcx)
movq (%r15), %rax
movq %rcx, 0x10(%rsp)
movl 0x20(%rax), %esi
leaq 0x63c8(%rip), %rdi      # 0x17c03
xorl %eax, %eax
callq 0x5060
movq 0x28(%r12), %r14
movq 0x30(%r12), %r12
cmpq %r12, %r14
je 0x11a09
leal 0x1(%rbx), %eax
movl %eax, 0x4(%rsp)
leaq 0x6639(%rip), %r13      # 0x17e9c
testl %ebx, %ebx
jle 0x11879
movl %ebx, %r15d
movq %r13, %rdi
xorl %eax, %eax
callq 0x5060
decl %r15d
jne 0x1186a
movq (%r14), %rsi
leaq 0x6397(%rip), %rdi      # 0x17c1a
xorl %eax, %eax
callq 0x5060
movq 0x20(%r14), %rax
movl 0x24(%rax), %ecx
cmpl $0x3, %ecx
je 0x11902
cmpl $0x4, %ecx
je 0x118de
cmpl $0x5, %ecx
jne 0x1192c
movq %rax, 0x30(%rsp)
movq 0x28(%r14), %r15
movq %r15, 0x38(%rsp)
testq %r15, %r15
je 0x1193f
movq 0xf706(%rip), %rax      # 0x20fc8
cmpb $0x0, (%rax)
je 0x11996
incl 0x8(%r15)
leaq 0x30(%rsp), %rsi
callq 0x11bbc
jmp 0x119af
movq %rax, 0x70(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x1194f
movq 0xf6d0(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x1194b
incl 0x8(%rax)
jmp 0x1194f
movq %rax, 0x80(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
je 0x1196f
movq 0xf6a6(%rip), %rcx      # 0x20fc8
cmpb $0x0, (%rcx)
je 0x1196b
incl 0x8(%rax)
jmp 0x1196f
movq (%rax), %rsi
leaq 0x6294(%rip), %rdi      # 0x17bca
xorl %eax, %eax
callq 0x5060
jmp 0x119b7
leaq 0x30(%rsp), %rsi
callq 0x11bbc
jmp 0x119b7
lock
incl 0x8(%rax)
movq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0x11254
movq 0x78(%rsp), %rdi
jmp 0x1198f
lock
incl 0x8(%rax)
movq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl %ebp, %edx
movl 0x4(%rsp), %ecx
callq 0x11254
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
jne 0x119b2
jmp 0x119b7
lock
incl 0x8(%r15)
movq 0x38(%rsp), %r15
leaq 0x30(%rsp), %rsi
callq 0x11bbc
testq %r15, %r15
je 0x119b7
movq %r15, %rdi
callq 0x671a
leaq 0x6263(%rip), %rdi      # 0x17c21
xorl %eax, %eax
callq 0x5060
cmpl $0x10000, %ebp          # imm = 0x10000
jb 0x119e5
movl %ebp, %esi
shrl $0x10, %esi
movzwl %bp, %edx
leaq 0x62ad(%rip), %rdi      # 0x17c89
xorl %eax, %eax
callq 0x5060
jmp 0x119f5
leaq 0x6272(%rip), %rdi      # 0x17c5e
movl %ebp, %esi
xorl %eax, %eax
callq 0x5060
movq 0x20(%r14), %rax
addl 0x20(%rax), %ebp
addq $0x30, %r14
cmpq %r12, %r14
jne 0x11863
testl %ebx, %ebx
jle 0x11a22
leaq 0x6488(%rip), %r14      # 0x17e9c
movq %r14, %rdi
xorl %eax, %eax
callq 0x5060
decl %ebx
jne 0x11a14
movl $0x7d, %edi
callq 0x52e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
jne 0x11b22
jmp 0x11b38
lock
incl 0x8(%r14)
leaq 0x40(%rsp), %rsi
movq 0x8(%rsi), %r14
callq 0x11bbc
testq %r14, %r14
je 0x11a5f
movq %r14, %rdi
callq 0x671a
movq 0x50(%r12), %rax
movl (%rax), %esi
testl %esi, %esi
js 0x11a80
movl 0x4(%rax), %edx
leaq 0x61cd(%rip), %rdi      # 0x17c41
xorl %eax, %eax
callq 0x5060
jmp 0x11b1a
addl $0x4, %esi
cmpl $0x3, %esi
ja 0x11b1a
leaq 0x60d1(%rip), %rcx      # 0x17b64
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl 0x4(%rax), %esi
movzwl %si, %edx
sarl $0x10, %esi
leaq 0x61d9(%rip), %rdi      # 0x17c85
jmp 0x11a74
leaq 0x6127(%rip), %rdi      # 0x17bdc
jmp 0x11ad9
leaq 0x6124(%rip), %rdi      # 0x17be2
jmp 0x11ad9
leaq 0x610f(%rip), %rdi      # 0x17bd6
jmp 0x11ad9
leaq 0x610b(%rip), %rdi      # 0x17bdb
jmp 0x11ad9
leaq 0x610a(%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 0x6169(%rip), %rdi      # 0x17c64
jmp 0x11b13
movl 0x8(%rax), %esi
leaq 0x614e(%rip), %rdi      # 0x17c55
jmp 0x11b13
movl 0x8(%rax), %esi
leaq 0x615e(%rip), %rdi      # 0x17c71
xorl %eax, %eax
callq 0x5060
testq %rbx, %rbx
je 0x11b38
movq %rbx, %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x671a
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x88(%rsp), %rdi
jmp 0x11b69
movq %rax, %r14
movq 0x58(%rsp), %rdi
jmp 0x11b8a
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x11b73
callq 0x671a
cmpq $0x0, 0x10(%rsp)
je 0x11bb3
movq 0x10(%rsp), %rdi
jmp 0x11bae
movq %rax, %r14
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x11b94
callq 0x671a
cmpq $0x0, 0x18(%rsp)
je 0x11bb3
movq 0x18(%rsp), %rdi
jmp 0x11bae
movq %rax, %r14
testq %rbx, %rbx
je 0x11bb3
movq %rbx, %rdi
callq 0x671a
movq %r14, %rdi
callq 0x53e0
nop