// File: /workspace/github_c_makefile_star2_O0/pahihu[P]mixal/io.c
// Function: do_operation
static unsigned do_operation(Address pc,
                             Byte device, Operation operation,
                             Cell rX, Cell offset, Address buffer)
{
    unsigned clocks = 0;

    /*
    if (true == devices[device].int_pending)
        error("Interrupt pending - %02o", device);
    */

    ensure_open(device);
    if (devices[device].busy) {
        clocks = 1;
        idle_time += clocks;
        do_scheduled_io(clocks);
        set_wait_state();
        return clocks;
    }

    if (control_state == get_internal_state())
        devices[device].int_request = true;

    if (attributes(device)->io_time)
        io_schedule(pc, device, operation, rX, offset, buffer);
    else {
        switch (operation) {
        case control: attributes(device)->ioc_handler(device, rX, offset); break;
        case input:   attributes(device)->in_handler(device, rX, buffer); break;
        case output:  attributes(device)->out_handler(device, rX, buffer); break;
        }
        if (devices[device].int_request == true)
            devices[device].int_pending = true;
    }
    return clocks;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0xc(%rbp), %edi
callq 0x5fd0
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xce28(%rip), %rax      # 0x12170
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x18(%rax)
je 0x5385
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
addq 0xd96a(%rip), %rax      # 0x12cd0
movq %rax, 0xd963(%rip)      # 0x12cd0
movl -0x28(%rbp), %edi
callq 0x5570
callq 0x8fe0
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5484
callq 0x8b50
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x53af
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xcdcf(%rip), %rax      # 0x12170
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x3c(%rax)
movl -0xc(%rbp), %edi
callq 0x6140
cmpl $0x0, 0x30(%rax)
je 0x53dc
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl -0x24(%rbp), %r9d
callq 0x6170
jmp 0x547e
movl -0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x53fc
jmp 0x53e8
movl -0x2c(%rbp), %eax
subl $0x1, %eax
je 0x5417
jmp 0x53f2
movl -0x2c(%rbp), %eax
subl $0x2, %eax
je 0x5431
jmp 0x5449
movl -0xc(%rbp), %edi
callq 0x6140
movq 0x28(%rax), %rax
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq *%rax
jmp 0x5449
movl -0xc(%rbp), %edi
callq 0x6140
movq 0x18(%rax), %rax
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq *%rax
jmp 0x5449
movl -0xc(%rbp), %edi
callq 0x6140
movq 0x20(%rax), %rax
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq *%rax
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xcd1b(%rip), %rax      # 0x12170
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x3c(%rax)
jne 0x547c
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xcd02(%rip), %rax      # 0x12170
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x40(%rax)
jmp 0x547e
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)