// File: /workspace/github_c_makefile_star2_O3/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 0x248(%rip), %rdi       # 0x73a8
callq 0x5be4
leaq 0x9c94(%rip), %rdi      # 0x10e00
callq 0x31a0
movl 0x9bc5(%rip), %ecx      # 0x10d3c
testl %eax, %eax
je 0x71c6
testb $0x8, %cl
je 0x71b7
testb $0x2, %cl
je 0x719e
movq 0x9c34(%rip), %rsi      # 0x10dc0
movl 0x9c22(%rip), %edx      # 0x10db4
leaq 0x2c90(%rip), %rdi      # 0x9e29
callq 0x73fd
movq 0x9c23(%rip), %rsi      # 0x10dc8
movl 0x9c09(%rip), %edx      # 0x10db4
leaq 0x2c83(%rip), %rdi      # 0x9e35
callq 0x73fd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, %cl
je 0x71ff
movq $0x0, 0x9c1a(%rip) # 0x10df0
callq 0x4beb
movl %eax, 0x9c0b(%rip)      # 0x10dec
movl $0x24, 0x9bfd(%rip)     # 0x10de8
callq 0x8353
callq 0x4e24
movl $0x0, 0x9bb1(%rip)      # 0x10db0
cmpl $0x0, 0x9b32(%rip)      # 0x10d38
je 0x7214
leaq 0x31db(%rip), %rdi      # 0xa3ea
callq 0x30b0
xorl %ebx, %ebx
leaq 0x75c3(%rip), %r14      # 0xe7e0
leaq 0x2c1d(%rip), %r12      # 0x9e41
movl %ebx, %ebp
movl 0x9b84(%rip), %edi      # 0x10db0
movl %edi, %eax
negl %eax
cmovsl %edi, %eax
cmpl %eax, 0x9b7b(%rip)      # 0x10db4
jle 0x723f
movl %edi, %eax
jmp 0x7257
callq 0x3fa3
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %eax
callq 0x5bec
movl 0x9b59(%rip), %eax      # 0x10db0
movl 0x9adb(%rip), %ecx      # 0x10d38
testl %ecx, %ecx
je 0x727d
movq 0x9b70(%rip), %rdx      # 0x10dd8
movslq %eax, %rsi
cmpl %ecx, (%rdx,%rsi,4)
ja 0x727d
movl %ebx, %edi
callq 0x6f49
movl 0x9b33(%rip), %eax      # 0x10db0
movl %eax, %edi
movq 0x9aaa(%rip), %r13      # 0x10d30
movl %ebx, %esi
callq 0x747f
movl 0x9b55(%rip), %eax      # 0x10de8
leaq (%rax,%rax,2), %rax
movl 0x8(%r14,%rax,8), %eax
movl %eax, %r15d
addq 0x9a8a(%rip), %r15      # 0x10d30
movq %r15, 0x9a83(%rip)      # 0x10d30
subq %r13, %r15
cmpb $0x0, 0x9b19(%rip)      # 0x10dd0
jne 0x72ca
callq 0x4d50
testl %eax, %eax
je 0x72ca
movl %r15d, %edi
callq 0x4bf2
movslq 0x9a7b(%rip), %rax      # 0x10d4c
testq %rax, %rax
je 0x732c
cmpq %rax, %r15
jb 0x7337
movq 0x9ade(%rip), %rax      # 0x10dc0
movq 0x50(%rax), %r13
movl $0x1, %edi
callq 0x374c
movq %r13, %rdi
movq %rax, %rsi
callq 0x3b2b
movq 0x9abe(%rip), %rcx      # 0x10dc0
movq %rax, 0x50(%rcx)
movl 0x9a40(%rip), %ecx      # 0x10d4c
subl %r15d, %ecx
addl $0x3e8, %ecx            # imm = 0x3E8
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmovel %ebx, %ecx
movl %ecx, 0x9a29(%rip)      # 0x10d4c
movb $0x1, 0x9a26(%rip)      # 0x10d50
jmp 0x7337
movl %r15d, %eax
negl %eax
movl %eax, 0x9a15(%rip)      # 0x10d4c
cmpb $0x0, 0x9b8a(%rip)      # 0x10ec8
jne 0x7226
cmpl $0x0, 0x99fd(%rip)      # 0x10d48
jne 0x7226
cmpb $0x1, 0x99f8(%rip)      # 0x10d50
jne 0x7384
movb $0x0, 0x99ef(%rip)      # 0x10d50
movl $0xfffffff5, %eax       # imm = 0xFFFFFFF5
movl %eax, %r15d
callq 0x776d
movl $0x1, 0x99d0(%rip)      # 0x10d48
movl %r15d, 0x9a31(%rip)     # 0x10db0
jmp 0x7226
leaq 0x4(%rsp), %rdi
callq 0x4ef9
cmpl $0x1, %eax
jne 0x7226
movl 0x4(%rsp), %eax
subl $-0x14, %eax
je 0x7226
negl %eax
jmp 0x7366