// File: /workspace/github_c_makefile_star2_O1/tyabu12[P]pl0compiler/codegen.c
// Function: stepForward
void stepForward(Mem *m) {          /* 目的コード（命令語）の1ステップ前進 */
    int top = m->top, pc = m->pc;
    Inst i;                         /* 実行する命令語 */
    int lev, temp;
    char buf[MAXSCREEN];
    if (m->exitCode) return;        /* 終了状態のチェック */
    i = code[pc++];                 /* これから実行する命令語 */
    switch (i.opCode) {
    case lit: m->stack[top++] = i.u.value;
        break;
    case lod: m->stack[top++] = m->stack[m->display[i.u.addr.level] + i.u.addr.addr];
        break;
    case sto: m->stack[m->display[i.u.addr.level] + i.u.addr.addr] = m->stack[--top];
        break;
    case cal: lev = i.u.addr.level +1;  /* i.u.addr.levelはcalleeの名前のレベル */
                                        /* calleeのブロックのレベルlevはそれに＋１したもの */
        m->stack[top] = m->display[lev]; /* m->display[lev]の退避 */
        m->stack[top+1] = pc; m->display[lev] = top;
                                        /* 現在のtopがcalleeのブロックの先頭番地 */
        pc = i.u.addr.addr;
        break;
    case ret: temp = m->stack[--top];     /* スタックのトップにあるものが返す値 */
        top = m->display[i.u.addr.level]; /* topを呼ばれたときの値に戻す */
        m->display[i.u.addr.level] = m->stack[top]; /* 壊したディスプレイの回復 */
        pc = m->stack[top+1];
        top -= i.u.addr.addr;             /* 実引数の分だけトップを戻す */
        m->stack[top++] = temp;           /* 返す値をスタックのトップへ */
        break;
    case ict: top += i.u.value;
        if (top >= MAXMEM-MAXREG)
            errorF("m->stack overflow");
        break;
    case jmp: pc = i.u.value; break;
    case jpc: if (m->stack[--top] == 0) pc = i.u.value;
        break;
    case opr:
        switch (i.u.optr) {
        case neg: m->stack[top-1] = -m->stack[top-1]; break;
        case add: --top;  m->stack[top-1] += m->stack[top]; break;
        case sub: --top; m->stack[top-1] -= m->stack[top]; break;
        case mul: --top;  m->stack[top-1] *= m->stack[top];  break;
        case div: --top;  m->stack[top-1] /= m->stack[top]; break;
        case odd: m->stack[top-1] = m->stack[top-1] & 1; break;
        case eq: --top;  m->stack[top-1] = (m->stack[top-1] == m->stack[top]); break;
        case ls: --top;  m->stack[top-1] = (m->stack[top-1] < m->stack[top]); break;
        case gr: --top;  m->stack[top-1] = (m->stack[top-1] > m->stack[top]); break;
        case neq: --top;  m->stack[top-1] = (m->stack[top-1] != m->stack[top]); break;
        case lseq: --top;  m->stack[top-1] = (m->stack[top-1] <= m->stack[top]); break;
        case greq: --top;  m->stack[top-1] = (m->stack[top-1] >= m->stack[top]); break;
        case rd:  printf("input number (rd):"); fflush(stdout); scanf("%d", &m->stack[top++]); break;
        case wrt: strcpy(buf, m->screen); snprintf(m->screen, MAXSCREEN, "%s%d", buf, m->stack[--top]); break;
        case wrl: strcpy(buf, m->screen); snprintf(m->screen, MAXSCREEN, "%s\n", buf); break;
        }
    }
    m->top = top;
    m->pc = pc;
    if (m->pc == 0) m->exitCode = 1;  /* 終了状態の更新 */
    m->stepCount++; /* ステップ数の更新 */
}

// Assembly:
cmpl $0x0, 0x1f60(%rdi)
je 0x2b8d
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
movl 0x1f58(%rdi), %r12d
movslq 0x1f54(%rdi), %rax
leal 0x1(%rax), %ebp
leaq (%rax,%rax,2), %rcx
leaq 0x5533(%rip), %rsi      # 0x80f0
movl (%rsi,%rcx,4), %edi
cmpq $0x8, %rdi
ja 0x2e7c
movslq %r12d, %r13
movl 0x4(%rsi,%rcx,4), %edx
movslq %edx, %rax
movl 0x8(%rsi,%rcx,4), %esi
movslq %esi, %rcx
leaq 0x245e(%rip), %r8       # 0x5040
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
leal 0x1(%r13), %r12d
movl %edx, (%rbx,%r13,4)
jmp 0x2e7c
movl 0x1f44(%rbx,%rax,4), %ecx
movl %ecx, (%rbx,%r13,4)
movl %ebp, 0x4(%rbx,%r13,4)
movl %r13d, 0x1f44(%rbx,%rax,4)
movl %esi, %ebp
jmp 0x2e7c
movslq 0x1f40(%rbx,%rax,4), %rax
addq %rcx, %rax
movl (%rbx,%rax,4), %eax
movl %r13d, %r12d
incl %r12d
movl %eax, (%rbx,%r13,4)
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x4(%rbx,%r13,4), %edx
movslq 0x1f40(%rbx,%rax,4), %rax
addq %rcx, %rax
movl %edx, (%rbx,%rax,4)
jmp 0x2e7c
movl %edx, %ebp
jmp 0x2e7c
cmpl $0xe, %edx
ja 0x2e7c
movl %edx, %eax
leaq 0x23f9(%rip), %rcx      # 0x5064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
negl -0x4(%rbx,%r13,4)
jmp 0x2e7c
movl -0x4(%rbx,%r13,4), %edx
movslq 0x1f40(%rbx,%rax,4), %rsi
movl (%rbx,%rsi,4), %edi
movl %edi, 0x1f40(%rbx,%rax,4)
movl 0x4(%rbx,%rsi,4), %ebp
subq %rcx, %rsi
leal 0x1(%rsi), %r12d
movl %edx, (%rbx,%rsi,4)
jmp 0x2e7c
addl %edx, %r12d
cmpl $0x7bc, %r12d           # imm = 0x7BC
jl 0x2e7c
leaq 0x253e(%rip), %rdi      # 0x51fd
callq 0x3953
jmp 0x2e7c
movq %r13, %r12
decq %r12
cmpl $0x0, -0x4(%rbx,%r13,4)
cmovel %edx, %ebp
jmp 0x2e7c
leaq 0x1f68(%rbx), %r14
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2050
leaq 0x248c(%rip), %rdx      # 0x5185
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x20a0
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
setge %cl
jmp 0x2e77
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
cltd
idivl -0x4(%rbx,%r13,4)
jmp 0x2db5
leaq 0x24cb(%rip), %rdi      # 0x520f
xorl %eax, %eax
callq 0x2090
movq 0x526e(%rip), %rax      # 0x7fc0
movq (%rax), %rdi
callq 0x2120
leal 0x1(%r13), %r12d
leaq (%rbx,%r13,4), %rsi
leaq 0x2423(%rip), %rdi      # 0x518c
xorl %eax, %eax
callq 0x2160
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
setne %cl
jmp 0x2e77
movq %r13, %r12
decq %r12
movl -0x4(%rbx,%r13,4), %eax
subl %eax, -0x8(%rbx,%r13,4)
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
imull -0x4(%rbx,%r13,4), %eax
movl %eax, -0x8(%rbx,%r13,4)
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
setl %cl
jmp 0x2e77
movq %r13, %r12
decq %r12
movl -0x4(%rbx,%r13,4), %eax
addl %eax, -0x8(%rbx,%r13,4)
jmp 0x2e7c
andl $0x1, -0x4(%rbx,%r13,4)
jmp 0x2e7c
leaq 0x1f68(%rbx), %r14
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2050
movq %r13, %r12
decq %r12
movl -0x4(%rbx,%r13,4), %r8d
leaq 0x2402(%rip), %rdx      # 0x5222
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x20a0
jmp 0x2e7c
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
sete %cl
jmp 0x2e77
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
setle %cl
jmp 0x2e77
movq %r13, %r12
decq %r12
movl -0x8(%rbx,%r13,4), %eax
xorl %ecx, %ecx
cmpl -0x4(%rbx,%r13,4), %eax
setg %cl
movl %ecx, -0x8(%rbx,%r13,4)
movl %r12d, 0x1f58(%rbx)
movl %ebp, 0x1f54(%rbx)
testl %ebp, %ebp
jne 0x2e97
movl $0x1, 0x1f60(%rbx)
incl 0x1f64(%rbx)
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq