// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x1f58(%rax), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x1f54(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1f60(%rax)
je 0x316b
jmp 0x3747
movslq -0x10(%rbp), %rax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x10(%rbp)
leaq (%rax,%rax,2), %rcx
leaq 0x615f(%rip), %rax      # 0x92e0
movl 0x8(%rax,%rcx,4), %edx
movl %edx, -0x18(%rbp)
movq (%rax,%rcx,4), %rax
movq %rax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x238(%rbp)
subq $0x8, %rax
ja 0x36ff
movq -0x238(%rbp), %rax
leaq 0x2eb2(%rip), %rcx      # 0x6064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x1c(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36ff
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movl 0x1f40(%rcx,%rdx,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36ff
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x1c(%rbp), %rsi
movl 0x1f40(%rcx,%rsi,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36ff
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl 0x1f40(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x1f40(%rax,%rcx,4)
movl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x36ff
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0x1f40(%rax,%rcx,4), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, 0x1f40(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0x28(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36ff
movl -0x1c(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $0x7bc, -0xc(%rbp)      # imm = 0x7BC
jl 0x3330
leaq 0x2f12(%rip), %rdi      # 0x623d
callq 0x48b0
jmp 0x36ff
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x36ff
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x335c
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x36ff
movl -0x1c(%rbp), %eax
movq %rax, -0x240(%rbp)
subq $0xe, %rax
ja 0x36fd
movq -0x240(%rbp), %rax
leaq 0x2d05(%rip), %rcx      # 0x6088
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
xorl %edx, %edx
subl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imull (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x8(%rbp), %rax
movq %rax, -0x248(%rbp)
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cltd
idivl %esi
movl %eax, %edx
movq -0x248(%rbp), %rax
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
andl $0x1, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setl %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setg %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setne %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setle %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
setge %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x36fd
leaq 0x2c21(%rip), %rdi      # 0x624f
movb $0x0, %al
callq 0x2080
movq 0x5984(%rip), %rax      # 0x8fc0
movq (%rax), %rdi
callq 0x20f0
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xc(%rbp)
cltq
shlq $0x2, %rax
addq %rax, %rsi
leaq 0x2b05(%rip), %rdi      # 0x6168
movb $0x0, %al
callq 0x2130
jmp 0x36fd
leaq -0x230(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x1f68, %rsi           # imm = 0x1F68
callq 0x2050
movq -0x8(%rbp), %rdi
addq $0x1f68, %rdi           # imm = 0x1F68
leaq -0x230(%rbp), %rcx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %edx
addl $-0x1, %edx
movl %edx, -0xc(%rbp)
movslq %edx, %rdx
movl (%rax,%rdx,4), %r8d
movl $0x200, %esi            # imm = 0x200
leaq 0x2baa(%rip), %rdx      # 0x6262
movb $0x0, %al
callq 0x2090
jmp 0x36fd
leaq -0x230(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x1f68, %rsi           # imm = 0x1F68
callq 0x2050
movq -0x8(%rbp), %rdi
addq $0x1f68, %rdi           # imm = 0x1F68
leaq -0x230(%rbp), %rcx
movl $0x200, %esi            # imm = 0x200
leaq 0x2a6b(%rip), %rdx      # 0x6161
movb $0x0, %al
callq 0x2090
jmp 0x36ff
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1f58(%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1f54(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1f54(%rax)
jne 0x3734
movq -0x8(%rbp), %rax
movl $0x1, 0x1f60(%rax)
movq -0x8(%rbp), %rax
movl 0x1f64(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1f64(%rax)
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq