// File: /workspace/github_c_makefile_star2_O1/hobo0xcc[P]rve/src/cpu.c
// Function: VirtioWrite
void VirtioWrite(State *state, uint64_t offset, uint8_t val) {
    if (offset >= VIRTIO_GUEST_FEATURES_BASE && offset < VIRTIO_GUEST_FEATURES_BASE + 4) {
        state->virtio->guest_features = WriteRange8(state->virtio->guest_features, val, offset - VIRTIO_GUEST_FEATURES_BASE);
        return;
    } else if (offset >= VIRTIO_GUEST_PAGE_SIZE_BASE && offset < VIRTIO_GUEST_PAGE_SIZE_BASE + 4) {
        state->virtio->guest_page_size = WriteRange8(state->virtio->guest_page_size, val, offset - VIRTIO_GUEST_PAGE_SIZE_BASE);
        return;
    } else if (offset >= VIRTIO_QUEUE_NUM_BASE && offset < VIRTIO_QUEUE_NUM_BASE + 4) {
        state->virtio->queue_num = WriteRange8(state->virtio->queue_num, val, offset - VIRTIO_QUEUE_NUM_BASE);
        return;
    } else if (offset >= VIRTIO_QUEUE_ALIGN_BASE && offset < VIRTIO_QUEUE_ALIGN_BASE + 4) {
        state->virtio->queue_align = WriteRange8(state->virtio->queue_align, val, offset - VIRTIO_QUEUE_ALIGN_BASE);
        return;
    } else if (offset >= VIRTIO_QUEUE_PFN_BASE && offset < VIRTIO_QUEUE_PFN_BASE + 4) {
        state->virtio->queue_pfn = WriteRange8(state->virtio->queue_pfn, val, offset - VIRTIO_QUEUE_PFN_BASE);
        return;
    } else if (offset >= VIRTIO_QUEUE_NOTIFY_BASE && offset < VIRTIO_QUEUE_NOTIFY_BASE + 4) {
        state->virtio->queue_notify = WriteRange8(state->virtio->queue_notify, val, offset - VIRTIO_QUEUE_NOTIFY_BASE);
        return;
    } else if (offset >= VIRTIO_INTERRUPT_ACK_BASE && offset < VIRTIO_INTERRUPT_ACK_BASE + 4) {
        if ((val & 1) == 1) {
            state->virtio->interrupt_status &= ~1;
            // printf("virtio disabled: pc: %llx, interrupt_status: %d\n", state->pc, state->virtio->interrupt_status);
        }
        state->virtio->interrupt_ack = WriteRange8(state->virtio->interrupt_ack, val, offset - VIRTIO_INTERRUPT_ACK_BASE);
        return;
    } else if (offset >= VIRTIO_STATUS_BASE && offset < VIRTIO_STATUS_BASE + 4) {
        state->virtio->status = WriteRange8(state->virtio->status, val, offset - VIRTIO_STATUS_BASE);
        return;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x3f, %rax
jg 0x241d
cmpq $0x37, %rax
jg 0x2468
cmpq $0x20, %rax
je 0x24ed
cmpq $0x28, %rax
jne 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x8(%rcx), %eax
orl %edx, %eax
movl %eax, 0x8(%rcx)
jmp 0x25a9
cmpq $0x63, %rax
jg 0x24ac
cmpq $0x40, %rax
je 0x251a
cmpq $0x50, %rax
jne 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x1c(%rcx), %eax
orl %edx, %eax
movl %eax, 0x1c(%rcx)
jmp 0x25a9
cmpq $0x38, %rax
je 0x2544
cmpq $0x3c, %rax
jne 0x25a9
shll $0x3, %esi
leal 0x20(%rsi), %ecx
movl $0xff, %eax
shlq %cl, %rax
movzbl %dl, %edx
movl %esi, %ecx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x14(%rcx), %eax
orl %edx, %eax
movl %eax, 0x14(%rcx)
jmp 0x25a9
cmpq $0x64, %rax
je 0x256e
cmpq $0x70, %rax
jne 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x28(%rcx), %eax
orl %edx, %eax
movl %eax, 0x28(%rcx)
jmp 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x4(%rcx), %eax
orl %edx, %eax
movl %eax, 0x4(%rcx)
jmp 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x18(%rcx), %eax
orl %edx, %eax
movl %eax, 0x18(%rcx)
jmp 0x25a9
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x10(%rcx), %eax
orl %edx, %eax
movl %eax, 0x10(%rcx)
jmp 0x25a9
testb $0x1, %dl
je 0x257e
movq 0x8130(%rdi), %rax
andl $-0x2, 0x20(%rax)
shll $0x3, %esi
leal -0x20(%rsi), %ecx
movl $0xff, %eax
shlq %cl, %rax
movzbl %dl, %edx
movl %esi, %ecx
shll %cl, %edx
movq 0x8130(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x24(%rcx), %eax
orl %edx, %eax
movl %eax, 0x24(%rcx)
popq %rbp
retq