// File: /workspace/github_c_makefile_star2_O2/wtakuo[P]SVM/vmdebug.c
// Function: dump_vm
void dump_vm (long nsteps, Bcode *ip, Bcode code[],
              Value *lv, Value *fp, Value *sp, Value *vs_base,
              Value gv[], size_t gv_size, vm_mode_t mode) {
    long i;
    Value *p;
    if (mode == vm_normal_mode) return;

    /* global variables */
    for (i = 0; i < gv_size; i++) {
        printf("gv[%ld]=0x%08lx ", i, gv[i]);
        if ((i+1) % 4 == 0) printf("\n");
    }
    if (i % 4 != 0) printf("\n");
    /* value stack */
    i = 0;
    for (p = vs_base - 1; p >= sp; p--) {
        printf("vs[%ld]=0x%08lx ", vs_base - 1 - p, *p);
        if ((i+1) % 4 == 0) printf("\n");
        i++;
    }
    if (i % 4 != 0) printf("\n");
    /* machine state */
    printf("lv=%p (%ld), fp=%p (%ld), sp=%p (%ld)\n", 
           lv, vs_base - lv, 
           fp, vs_base - fp,
           sp, vs_base - sp);
    /* next instruction */
    printf("nsteps=%ld, ip=%p, pc=%ld, inst=%s\n",
           nsteps, 
           ip,
           ip - code, 
           instr_name(ip[0]));

    if (mode == vm_step_mode) {
        printf("next? [Y/n]");
        switch (getchar()) {
        case 'n':
        case 'N':
            exit(EXIT_SUCCESS);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x0, 0x88(%rsp)
je 0x175b
movq %r9, %r12
movq %rcx, 0x10(%rsp)
movq %r8, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x80(%rsp), %rbx
movq 0x78(%rsp), %rbp
leaq 0xaf2(%rip), %r14       # 0x210e
pushq $0xa
popq %r15
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0x164f
movq (%rbp,%r13,8), %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1050
leal 0x1(%r13), %eax
testb $0x3, %al
jne 0x164a
movl %r15d, %edi
callq 0x1040
incq %r13
jmp 0x1623
testb $0x3, %bl
je 0x165c
pushq $0xa
popq %rdi
callq 0x1040
movq 0x70(%rsp), %rax
leaq -0x8(%rax), %r13
leaq 0xab3(%rip), %r14       # 0x211f
pushq $0xa
popq %r15
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq %r12, %r13
jb 0x16aa
movq %rbp, %rsi
sarq $0x3, %rsi
movq (%r13), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1050
leal 0x1(%rbx), %eax
testb $0x3, %al
jne 0x169d
movl %r15d, %edi
callq 0x1040
addq $-0x8, %r13
addq $0x8, %rbp
incq %rbx
jmp 0x1674
testb $0x3, %bl
je 0x16b7
pushq $0xa
popq %rdi
callq 0x1040
movq 0x70(%rsp), %rax
movq %rax, %rdx
movq 0x10(%rsp), %rsi
subq %rsi, %rdx
sarq $0x3, %rdx
movq %rax, %r8
movq 0x18(%rsp), %rcx
subq %rcx, %r8
sarq $0x3, %r8
subq %r12, %rax
sarq $0x3, %rax
movq %rax, (%rsp)
leaq 0xa44(%rip), %rdi       # 0x2130
movq %r12, %r9
xorl %eax, %eax
callq 0x1050
movq 0x30(%rsp), %rdx
movq %rdx, %rcx
subq 0x20(%rsp), %rcx
movzbl (%rdx), %eax
cmpq $0x36, %rax
ja 0x171c
leaq 0xb21(%rip), %rsi       # 0x2234
movslq (%rsi,%rax,4), %r8
addq %rsi, %r8
jmp 0x1723
leaq 0xb0b(%rip), %r8        # 0x222e
leaq 0xa2d(%rip), %rdi       # 0x2157
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x1050
cmpl $0x2, 0x88(%rsp)
jne 0x175b
leaq 0xa34(%rip), %rdi       # 0x217b
xorl %eax, %eax
callq 0x1050
callq 0x1060
orl $0x20, %eax
cmpl $0x6e, %eax
je 0x176a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x10b0
nopl (%rax)