// File: /workspace/github_c_makefile_star2_O1/pahihu[P]mixal/run.c
// Function: run
void run(void)
{
    install_error_handler(stop);
    if (setjmp(escape_k) != 0) {
        if (mix_config & MIXCONFIG_CORE) {
            if (mix_config & MIXCONFIG_INTERRUPT)
                save_memory("mixcore.ctl", control_memory, memory_size);
            save_memory("mixcore.dat", memory, memory_size);
        }
        return;
    }

    /* --- Go device support --- */
    if (MIXCONFIG_PUSHGO & mix_config) {
        M = 0; F = io_go_device(); C = 36;
        op_table[C].action();
        io_complete();
        pc = 0;
    }

    if (trace_count)
        print_CPU_trace(true);
    for (;;) {
        if (memory_size <= abs(pc)) {
            error("Program counter out of range: %s", address_to_string(pc));
        }
        {
            unsigned long start_time, delta_time;

            /* --- Instruction trace --- */
            if (trace_count && (frequency[pc] <= trace_count))
                print_CPU_trace(false);

            /* MOV adds 2 clocks per word */
            start_time = elapsed_time;
            xecute(pc, false);
            elapsed_time += op_table[C].clocks;

            /* --- I/O subsystem --- */
            delta_time = elapsed_time - start_time;
            if ((false == wait_state) && io_scheduled())
                do_scheduled_io(delta_time);

            /* --- Real-time clock --- */
            if (rtc_busy) {
                if (rtc_busy <= delta_time) {
                    Cell cell = sub(control_memory[10], ulong_to_cell(1));
                    control_memory[10] = cell;
                    if (magnitude(cell))
                        rtc_busy = 1000 + rtc_busy - delta_time;
                    else
                        rtc_busy = 0;
                    rtc_int_pending = true;
                }
            } else
                rtc_busy -= delta_time;

            /* --- Interrupt facility --- */
            if (!rti_done && 
                normal_state == internal_state)
            {
                Address int_pc = 0;
                Byte device;

                if (true == rtc_int_pending) {
                    rtc_int_pending = false;
                    int_pc = -11;
                }
                else if (true == io_pending_interrupt(&device))
                    int_pc = -(20 + device);
                if (int_pc) {
                    save_state();
                    internal_state = control_state;
                    pc = int_pc;
                }
            }
        } /* for (;;) body */
    } /* for (;;) */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x242(%rip), %rdi       # 0x7381
callq 0x5bb4
leaq 0x9cb5(%rip), %rdi      # 0x10e00
callq 0x31a0
movl 0x9be6(%rip), %ecx      # 0x10d3c
testl %eax, %eax
je 0x71a5
testb $0x8, %cl
je 0x7196
testb $0x2, %cl
je 0x717d
movq 0x9c55(%rip), %rsi      # 0x10dc0
movl 0x9c43(%rip), %edx      # 0x10db4
leaq 0x2cb1(%rip), %rdi      # 0x9e29
callq 0x73d6
movq 0x9c44(%rip), %rsi      # 0x10dc8
movl 0x9c2a(%rip), %edx      # 0x10db4
leaq 0x2ca4(%rip), %rdi      # 0x9e35
callq 0x73d6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, %cl
je 0x71de
movq $0x0, 0x9c3b(%rip) # 0x10df0
callq 0x4ba3
movl %eax, 0x9c2c(%rip)      # 0x10dec
movl $0x24, 0x9c1e(%rip)     # 0x10de8
callq 0x833c
callq 0x4dcf
movl $0x0, 0x9bd2(%rip)      # 0x10db0
cmpl $0x0, 0x9b53(%rip)      # 0x10d38
je 0x71f3
leaq 0x31fc(%rip), %rdi      # 0xa3ea
callq 0x30b0
xorl %ebx, %ebx
leaq 0x75e4(%rip), %r14      # 0xe7e0
leaq 0x2c3e(%rip), %r12      # 0x9e41
movl %ebx, %ebp
movl 0x9ba5(%rip), %edi      # 0x10db0
movl %edi, %eax
negl %eax
cmovsl %edi, %eax
cmpl %eax, 0x9b9c(%rip)      # 0x10db4
jg 0x722c
callq 0x3fca
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %eax
callq 0x5bbc
movl 0x9b06(%rip), %eax      # 0x10d38
testl %eax, %eax
je 0x7250
movq 0x9b9b(%rip), %rcx      # 0x10dd8
movslq 0x9b6c(%rip), %rdx      # 0x10db0
cmpl %eax, (%rcx,%rdx,4)
ja 0x7250
movl %ebx, %edi
callq 0x6f28
movq 0x9ad9(%rip), %r13      # 0x10d30
movl 0x9b53(%rip), %edi      # 0x10db0
movl %ebx, %esi
callq 0x7458
movl 0x9b7e(%rip), %eax      # 0x10de8
leaq (%rax,%rax,2), %rax
movl 0x8(%r14,%rax,8), %eax
movl %eax, %r15d
addq 0x9ab3(%rip), %r15      # 0x10d30
movq %r15, 0x9aac(%rip)      # 0x10d30
subq %r13, %r15
cmpb $0x0, 0x9b42(%rip)      # 0x10dd0
jne 0x72a1
callq 0x4d0c
testl %eax, %eax
je 0x72a1
movl %r15d, %edi
callq 0x4baa
movslq 0x9aa4(%rip), %rax      # 0x10d4c
testq %rax, %rax
je 0x7303
cmpq %rax, %r15
jb 0x730e
movq 0x9b07(%rip), %rax      # 0x10dc0
movq 0x50(%rax), %r13
movl $0x1, %edi
callq 0x376c
movq %r13, %rdi
movq %rax, %rsi
callq 0x3b59
movq 0x9ae7(%rip), %rcx      # 0x10dc0
movq %rax, 0x50(%rcx)
movl 0x9a69(%rip), %ecx      # 0x10d4c
subl %r15d, %ecx
addl $0x3e8, %ecx            # imm = 0x3E8
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmovel %ebx, %ecx
movl %ecx, 0x9a52(%rip)      # 0x10d4c
movb $0x1, 0x9a4f(%rip)      # 0x10d50
jmp 0x730e
movl %r15d, %eax
negl %eax
movl %eax, 0x9a3e(%rip)      # 0x10d4c
cmpb $0x0, 0x9bb3(%rip)      # 0x10ec8
jne 0x7205
cmpl $0x0, 0x9a26(%rip)      # 0x10d48
jne 0x7205
cmpb $0x1, 0x9a21(%rip)      # 0x10d50
jne 0x7340
movb $0x0, 0x9a18(%rip)      # 0x10d50
movl $0xfffffff5, %r15d      # imm = 0xFFFFFFF5
jmp 0x735d
leaq 0x4(%rsp), %rdi
callq 0x4ea4
xorl %r15d, %r15d
cmpl $0x1, %eax
jne 0x735d
movl $0xffffffec, %r15d      # imm = 0xFFFFFFEC
subl 0x4(%rsp), %r15d
testl %r15d, %r15d
je 0x7205
callq 0x774a
movl $0x1, 0x99d3(%rip)      # 0x10d48
movl %r15d, 0x9a34(%rip)     # 0x10db0
jmp 0x7205