// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
cmpq $0x20, -0x10(%rbp)
jb 0x32db
cmpq $0x24, -0x10(%rbp)
jae 0x32db
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x20, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x4(%rax)
jmp 0x34ed
cmpq $0x28, -0x10(%rbp)
jb 0x3321
cmpq $0x2c, -0x10(%rbp)
jae 0x3321
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x8(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x28, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x8(%rax)
jmp 0x34ed
cmpq $0x38, -0x10(%rbp)
jb 0x3367
cmpq $0x3c, -0x10(%rbp)
jae 0x3367
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x10(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x38, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x10(%rax)
jmp 0x34ed
cmpq $0x3c, -0x10(%rbp)
jb 0x33ad
cmpq $0x40, -0x10(%rbp)
jae 0x33ad
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x14(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x3c, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x14(%rax)
jmp 0x34ed
cmpq $0x40, -0x10(%rbp)
jb 0x33f3
cmpq $0x44, -0x10(%rbp)
jae 0x33f3
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x40, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x18(%rax)
jmp 0x34ed
cmpq $0x50, -0x10(%rbp)
jb 0x3439
cmpq $0x54, -0x10(%rbp)
jae 0x3439
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x1c(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x50, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x1c(%rax)
jmp 0x34ed
cmpq $0x64, -0x10(%rbp)
jb 0x349c
cmpq $0x68, -0x10(%rbp)
jae 0x349c
movzbl -0x11(%rbp), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x3467
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x24(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x64, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x24(%rax)
jmp 0x34ed
cmpq $0x70, -0x10(%rbp)
jb 0x34df
cmpq $0x74, -0x10(%rbp)
jae 0x34df
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x28(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x70, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl %ecx, 0x28(%rax)
jmp 0x34ed
jmp 0x34e1
jmp 0x34e3
jmp 0x34e5
jmp 0x34e7
jmp 0x34e9
jmp 0x34eb
jmp 0x34ed
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)