// File: /workspace/github_c_makefile_star2_O2/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 $0x70, %rax
je 0x22df
cmpq $0x28, %rax
je 0x225e
cmpq $0x38, %rax
je 0x22b5
cmpq $0x3c, %rax
je 0x2288
cmpq $0x40, %rax
je 0x21ca
cmpq $0x50, %rax
je 0x2231
cmpq $0x64, %rax
je 0x21f7
cmpq $0x20, %rax
jne 0x2307
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 0x2307
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 0x2307
movq 0x8130(%rdi), %rax
testb $0x1, %dl
je 0x2207
andb $-0x2, 0x20(%rax)
shll $0x3, %esi
leal -0x20(%rsi), %ecx
movl $0xff, %edi
shlq %cl, %rdi
movzbl %dl, %edx
movl %esi, %ecx
shll %cl, %edx
notl %edi
orl $0xffffff00, %edi       # imm = 0xFFFFFF00
andl 0x24(%rax), %edi
orl %edx, %edi
movl %edi, 0x24(%rax)
jmp 0x2307
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 0x2307
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 0x2307
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 0x2307
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 0x2307
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)
popq %rbp
retq