// File: /workspace/github_c_makefile_star2_O2/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 0x23a(%rip), %rdi       # 0x6f55
callq 0x56f8
leaq 0xa0d9(%rip), %rdi      # 0x10e00
callq 0x31a0
movl 0xa00a(%rip), %ecx      # 0x10d3c
testl %eax, %eax
je 0x6d81
testb $0x8, %cl
je 0x6d72
testb $0x2, %cl
je 0x6d59
movq 0xa079(%rip), %rsi      # 0x10dc0
movl 0xa067(%rip), %edx      # 0x10db4
leaq 0x30d5(%rip), %rdi      # 0x9e29
callq 0x6fa2
movq 0xa068(%rip), %rsi      # 0x10dc8
movl 0xa04e(%rip), %edx      # 0x10db4
leaq 0x30c8(%rip), %rdi      # 0x9e35
callq 0x6fa2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, %cl
je 0x6db4
andq $0x0, 0xa062(%rip)      # 0x10df0
callq 0x48c0
movl %eax, 0xa053(%rip)      # 0x10dec
movl $0x24, 0xa045(%rip)     # 0x10de8
callq 0x7ce7
callq 0x4ae5
andl $0x0, 0x9ffc(%rip)      # 0x10db0
cmpl $0x0, 0x9f7d(%rip)      # 0x10d38
je 0x6dc5
pushq $0x1
popq %rdi
callq 0x6b1d
xorl %ebx, %ebx
leaq 0x7a12(%rip), %r14      # 0xe7e0
leaq 0x306c(%rip), %r12      # 0x9e41
movl %ebx, %ebp
movl 0x9fd3(%rip), %edi      # 0x10db0
movl %edi, %eax
negl %eax
cmovsl %edi, %eax
cmpl %eax, 0x9fca(%rip)      # 0x10db4
jle 0x6df0
movl %edi, %eax
jmp 0x6e08
callq 0x3d81
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %eax
callq 0x5700
movl 0x9fa8(%rip), %eax      # 0x10db0
movl 0x9f2a(%rip), %ecx      # 0x10d38
testl %ecx, %ecx
je 0x6e2e
movq 0x9fbf(%rip), %rdx      # 0x10dd8
movslq %eax, %rsi
cmpl %ecx, (%rdx,%rsi,4)
ja 0x6e2e
movl %ebx, %edi
callq 0x6b1d
movl 0x9f82(%rip), %eax      # 0x10db0
movl %eax, %edi
movq 0x9ef9(%rip), %r13      # 0x10d30
movl %ebx, %esi
callq 0x7022
movl 0x9fa4(%rip), %eax      # 0x10de8
imulq $0x18, %rax, %rax
movl 0x8(%rax,%r14), %eax
movl %eax, %r15d
addq 0x9ed9(%rip), %r15      # 0x10d30
movq %r15, 0x9ed2(%rip)      # 0x10d30
subq %r13, %r15
cmpb $0x0, 0x9f68(%rip)      # 0x10dd0
jne 0x6e7b
callq 0x4a1d
testl %eax, %eax
je 0x6e7b
movl %r15d, %edi
callq 0x48c7
movslq 0x9eca(%rip), %rax      # 0x10d4c
testq %rax, %rax
je 0x6edb
cmpq %rax, %r15
jb 0x6ee6
movq 0x9f2d(%rip), %rax      # 0x10dc0
movq 0x50(%rax), %r13
pushq $0x1
popq %rdi
callq 0x3554
movq %r13, %rdi
movq %rax, %rsi
callq 0x3909
movq 0x9f0f(%rip), %rcx      # 0x10dc0
movq %rax, 0x50(%rcx)
movl 0x9e91(%rip), %ecx      # 0x10d4c
subl %r15d, %ecx
addl $0x3e8, %ecx            # imm = 0x3E8
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmovel %ebx, %ecx
movl %ecx, 0x9e7a(%rip)      # 0x10d4c
movb $0x1, 0x9e77(%rip)      # 0x10d50
jmp 0x6ee6
movl %r15d, %eax
negl %eax
movl %eax, 0x9e66(%rip)      # 0x10d4c
cmpb $0x0, 0x9fdb(%rip)      # 0x10ec8
jne 0x6dd7
cmpl $0x0, 0x9e4e(%rip)      # 0x10d48
jne 0x6dd7
cmpb $0x1, 0x9e49(%rip)      # 0x10d50
jne 0x6f31
movb $0x0, 0x9e40(%rip)      # 0x10d50
pushq $-0xb
popq %rax
movl %eax, %r15d
callq 0x72bf
movl $0x1, 0x9e23(%rip)      # 0x10d48
movl %r15d, 0x9e84(%rip)     # 0x10db0
jmp 0x6dd7
leaq 0x4(%rsp), %rdi
callq 0x4bb3
cmpl $0x1, %eax
jne 0x6dd7
movl 0x4(%rsp), %eax
subl $-0x14, %eax
je 0x6dd7
negl %eax
jmp 0x6f13