LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: WriteCSR
void WriteCSR(State *state, uint16_t csr, uint8_t start_bit, uint8_t end_bit,
              uint64_t val) {
    assert(start_bit <= end_bit);

    uint64_t mask = SetNBits(end_bit - start_bit + 1);
    val &= mask;
    state->csr[csr] &= (~(mask << start_bit));
    state->csr[csr] |= (val << start_bit);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movb %dl, %cl
movw %si, %dx
movq %rdi, -0x8(%rbp)
movw %dx, -0xa(%rbp)
movb %cl, -0xb(%rbp)
movb %al, -0xc(%rbp)
movq %r8, -0x18(%rbp)
movzbl -0xb(%rbp), %eax
movzbl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jg 0x16bf
jmp 0x16de
leaq 0xdd9d(%rip), %rdi      # 0xf463
leaq 0xddab(%rip), %rsi      # 0xf478
movl $0x37c, %edx            # imm = 0x37C
leaq 0xdda9(%rip), %rcx      # 0xf482
callq 0x10b0
movzbl -0xc(%rbp), %edi
movzbl -0xb(%rbp), %eax
subl %eax, %edi
addl $0x1, %edi
callq 0x12b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
andq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rdx
movzbl -0xb(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
shlq %cl, %rdx
xorq $-0x1, %rdx
movq -0x8(%rbp), %rax
movzwl -0xa(%rbp), %ecx
andq 0x8(%rax,%rcx,8), %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq -0x18(%rbp), %rdx
movzbl -0xb(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
shlq %cl, %rdx
movq -0x8(%rbp), %rax
movzwl -0xa(%rbp), %ecx
orq 0x8(%rax,%rcx,8), %rdx
movq %rdx, 0x8(%rax,%rcx,8)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: UartTick
void UartTick(State *state) {
    if (state->uart->rbr == 0) {
        int8_t val = getch();
        if (val != ERR && val != 0) {
            state->uart->rbr = val;
            state->uart->lsr |= 0x01;
        }
    }
    if (state->uart->thr != 0) {
        addch(state->uart->thr);
        state->uart->thr = 0;
        state->uart->lsr |= 0x20;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1b9a
movq 0x11482(%rip), %rax     # 0x12fd8
movq (%rax), %rdi
callq 0x1070
movb %al, -0x9(%rbp)
movsbl -0x9(%rbp), %eax
cmpl $-0x1, %eax
je 0x1b98
movsbl -0x9(%rbp), %eax
cmpl $0x0, %eax
je 0x1b98
movb -0x9(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x6(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x6(%rax)
jmp 0x1b9a
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x1bf0
movq 0x11423(%rip), %rax     # 0x12fd8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x1(%rax), %esi
callq 0x1190
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb $0x0, 0x1(%rax)
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x6(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0x6(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ClintTick
void ClintTick(State *state) {
    state->clint->mtime++;

    WriteCSR(state, MIP, 3, 3, 0);
    if ((state->clint->msip & 1) != 0) {
        WriteCSR(state, MIP, 3, 3, 1);
    }

    WriteCSR(state, MIP, 7, 7, 0);
    if (state->clint->mtimecmp > 0 && state->clint->mtime >= state->clint->mtimecmp) {
        // state->clint->mtime = 0;
        // WriteCSR(state, MIP, 7, 7, 1);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movl $0x344, %esi            # imm = 0x344
movl $0x3, %ecx
xorl %eax, %eax
movl %eax, %r8d
movl %ecx, %edx
callq 0x1690
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1c6d
movq -0x8(%rbp), %rdi
movl $0x344, %esi            # imm = 0x344
movl $0x3, %ecx
movl $0x1, %r8d
movl %ecx, %edx
callq 0x1690
movq -0x8(%rbp), %rdi
movl $0x344, %esi            # imm = 0x344
movl $0x7, %ecx
xorl %eax, %eax
movl %eax, %r8d
movl %ecx, %edx
callq 0x1690
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x1cbb
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8120(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jb 0x1cbb
jmp 0x1cbb
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: VirtioTick
void VirtioTick(State *state) {
    if (state->virtio->queue_notify != 0x1234) {
        // printf("virtio enabled: pc: %llx\n", state->pc);
        state->virtio->interrupt_status |= 1;
        DiskAccess(state);
        state->virtio->queue_notify = 0x1234;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
cmpl $0x1234, 0x1c(%rax)     # imm = 0x1234
je 0x1eff
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl 0x20(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rdi
callq 0x1f10
movq -0x8(%rbp), %rax
movq 0x8130(%rax), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: Tick
void Tick(State *state) {
    state->clock++;
    uint8_t b_mode = state->mode;
    uint64_t b_sepc = state->csr[SEPC];
    uint64_t pc = state->pc;
    uint32_t instr = Fetch32(state, state->pc);
    
    ExecInstruction(state, instr);
    state->x[0] = 0;

    if (state->excepted) {
        HandleTrap(state, pc);
        state->excepted = false;
        state->exception_code = 0;
    }

    UartTick(state);
    VirtioTick(state);
    ClintTick(state);
    PlicTick(state, IsVirtioInterrupting(state), IsUartInterrupting(state));
    bool interrupted = HandleInterrupt(state, state->pc);
    if (interrupted && state->excepted) {
        state->excepted = false;
        state->exception_code = 0;
    }

    if (state->csr[SEPC] != b_sepc) {
        // printf("sepc changed: pc: 0x%llx, 0x%llx to 0x%llx\n", Translate(state, state->pc, AccessInstruction), b_sepc, state->csr[SEPC]);
    }
    if (state->mode != b_mode) {
        // printf("mode changed: pc: 0x%llx, %x to %x\n", Translate(state, state->pc, AccessInstruction), b_mode, state->mode);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8110(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8110(%rax)
movq -0x8(%rbp), %rax
movb 0x8148(%rax), %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq 0xa10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x2390
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x23f0
movq -0x8(%rbp), %rax
movq $0x0, 0x8008(%rax)
movq -0x8(%rbp), %rax
testb $0x1, 0x8138(%rax)
je 0x22cb
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1380
movq -0x8(%rbp), %rax
movb $0x0, 0x8138(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8140(%rax)
movq -0x8(%rbp), %rdi
callq 0x1b30
movq -0x8(%rbp), %rdi
callq 0x1eb0
movq -0x8(%rbp), %rdi
callq 0x1c00
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2740
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2770
movb -0x31(%rbp), %cl
movq -0x30(%rbp), %rdi
movzbl %cl, %esi
andl $0x1, %esi
movzbl %al, %edx
andl $0x1, %edx
callq 0x1cd0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x1750
andb $0x1, %al
movb %al, -0x25(%rbp)
testb $0x1, -0x25(%rbp)
je 0x235d
movq -0x8(%rbp), %rax
testb $0x1, 0x8138(%rax)
je 0x235d
movq -0x8(%rbp), %rax
movb $0x0, 0x8138(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8140(%rax)
movq -0x8(%rbp), %rax
movq 0xa10(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x2370
jmp 0x2370
movq -0x8(%rbp), %rax
movzbl 0x8148(%rax), %eax
movzbl -0x9(%rbp), %ecx
cmpl %ecx, %eax
je 0x2385
jmp 0x2385
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: Fetch32
uint32_t Fetch32(State *state, uint64_t v_addr) {
    uint64_t p_addr = Translate(state, v_addr, AccessInstruction);
    if (state->excepted) return 0;
    // printf("v_addr: %llx -> p_addr: %llx\n", v_addr, p_addr);
    return MemRead32(state, p_addr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x3d00
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0x8138(%rax)
je 0x23c9
movl $0x0, -0x4(%rbp)
jmp 0x23d9
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3b10
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: IsUartInterrupting
bool IsUartInterrupting(State *state) {
    if ((state->uart->ier & 0x1) != 0) {
        if (state->uart->rbr != 0) {
            state->uart->iir = 0x04;
            return true;
        }
    }

    if ((state->uart->ier & 0x2) != 0) {
        if (state->uart->thr == 0) {
            state->uart->iir = 0x02;
            return true;
        }
    }

    state->uart->iir = 0xf;
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x2(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x27b9
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x27b7
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb $0x4, 0x3(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x280e
jmp 0x27b9
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x2(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x27fb
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x27f9
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb $0x2, 0x3(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x280e
jmp 0x27fb
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb $0xf, 0x3(%rax)
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: WriteRange8
uint64_t WriteRange8(uint64_t dest, uint8_t val, uint64_t start) {
    uint8_t mask = dest & (SetNBits(8) << (start * 8));
    dest ^= mask;
    dest |= val << (start * 8);
    return dest;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x8, %edi
callq 0x12b0
movq %rax, %rdx
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
xorq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movzbl -0x9(%rbp), %eax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
shll %cl, %eax
cltq
orq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: UartWrite
void UartWrite(State *state, uint64_t offset, uint8_t val) {
    // if (offset == 0) {
    //     state->uart->uart_mem[offset] = ch;
    //     if (state->uart->uart_mem[3] & SetOneBit(7)) {
    //         return;
    //     }
    //     putc(ch, stdout);
    //     fflush(stdout);
    // } else {
    //     state->uart->uart_mem[offset] = ch;
    // }

    uint8_t dlab = state->uart->lcr >> 7 & 1;
    if (offset == UART_THR && dlab == 0) {
        state->uart->thr = val;
        // Set THRE to 0.
        // THRE indicate that whether the thr register is zero.
        state->uart->lsr &= ~0x20;
    } else if (offset == UART_IER && dlab == 0) {
        state->uart->ier = val;
    } else if (offset == UART_LCR) {
        state->uart->lcr = val;
    } else if (offset == UART_MCR) {
        state->uart->mcr = val;
    } else if (offset == UART_SCR) {
        state->uart->scr = val;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x4(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
movb %al, -0x12(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2951
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x2951
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, 0x1(%rax)
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x6(%rax), %ecx
andl $-0x21, %ecx
movb %cl, 0x6(%rax)
jmp 0x29c8
cmpq $0x1, -0x10(%rbp)
jne 0x2974
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x2974
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, 0x2(%rax)
jmp 0x29c6
cmpq $0x3, -0x10(%rbp)
jne 0x298e
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, 0x4(%rax)
jmp 0x29c4
cmpq $0x4, -0x10(%rbp)
jne 0x29a8
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, 0x5(%rax)
jmp 0x29c2
cmpq $0x7, -0x10(%rbp)
jne 0x29c0
movb -0x11(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x8118(%rax), %rax
movb %cl, 0x8(%rax)
jmp 0x29c2
jmp 0x29c4
jmp 0x29c6
jmp 0x29c8
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: UartRead
uint8_t UartRead(State *state, uint64_t offset) {
    // if (offset == 0) {
    //     if (state->uart->uart_mem[3] & SetOneBit(7)) {
    //         return state->uart->uart_mem[offset];
    //     }
    //     uint8_t ch = getc(stdin);
    //     state->uart->uart_mem[offset] = ch;
    //     return ch;
    // } else {
    //     return state->uart->uart_mem[offset];
    // }

    uint8_t dlab = state->uart->lcr >> 7 & 1;
    if (offset == UART_RBR && dlab == 0) {
        uint8_t rbr = state->uart->rbr;
        state->uart->rbr = 0;
        state->uart->lsr &= ~0x01;
        return rbr;
    } else if (offset == UART_IER && dlab == 0) {
        return state->uart->ier;
    } else if (offset == UART_IIR) {
        return state->uart->iir;
    } else if (offset == UART_LCR) {
        return state->uart->lcr;
    } else if (offset == UART_MCR) {
        return state->uart->mcr;
    } else if (offset == UART_LSR) {
        return state->uart->lsr;
    } else if (offset == UART_MSR) {
        return state->uart->msr;
    } else if (offset == UART_SCR) {
        return state->uart->scr;
    } else {
        return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x4(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
movb %al, -0x19(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2a42
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x2a42
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb (%rax), %al
movb %al, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movzbl 0x6(%rax), %ecx
andl $-0x2, %ecx
movb %cl, 0x6(%rax)
movb -0x1a(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x1, -0x18(%rbp)
jne 0x2a68
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x2a68
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x2(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x2, -0x18(%rbp)
jne 0x2a85
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x3(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x3, -0x18(%rbp)
jne 0x2a9f
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x4(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x4, -0x18(%rbp)
jne 0x2ab9
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x5(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x5, -0x18(%rbp)
jne 0x2ad3
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x6(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x6, -0x18(%rbp)
jne 0x2aed
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x7(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
cmpq $0x7, -0x18(%rbp)
jne 0x2b07
movq -0x10(%rbp), %rax
movq 0x8118(%rax), %rax
movb 0x8(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x2b0b
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ClintWrite
void ClintWrite(State *state, uint64_t offset, uint8_t val) {
    if (offset >= CLINT_MSIP_BASE && offset < CLINT_MSIP_BASE + CLINT_MSIP_SIZE) {
        state->clint->msip = WriteRange8(state->clint->msip, val, offset - CLINT_MSIP_BASE);
    } else if (offset >= CLINT_MTIMECMP_BASE && offset < CLINT_MTIMECMP_BASE + CLINT_MTIMECMP_SIZE) {
        state->clint->mtimecmp = WriteRange8(state->clint->mtimecmp, val, offset - CLINT_MTIMECMP_BASE);
    } else if (offset >= CLINT_MTIME_BASE && offset < CLINT_MTIME_BASE + CLINT_MTIME_SIZE) {
        state->clint->mtime = WriteRange8(state->clint->mtime, val, offset - CLINT_MTIME_BASE);
    } else {
        // Do nothing.
    }
}

// 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 $0x0, -0x10(%rbp)
jb 0x2b69
cmpq $0x4, -0x10(%rbp)
jae 0x2b69
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movl (%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x0, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movl %ecx, (%rax)
jmp 0x2c09
cmpq $0x4000, -0x10(%rbp)    # imm = 0x4000
jb 0x2bb6
cmpq $0x4008, -0x10(%rbp)    # imm = 0x4008
jae 0x2bb6
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x8(%rax), %rdi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x4000, %rdx           # imm = 0x4000
movzbl %al, %esi
callq 0x2820
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0x2c07
cmpq $0xbff8, -0x10(%rbp)    # imm = 0xBFF8
jb 0x2c03
cmpq $0xc000, -0x10(%rbp)    # imm = 0xC000
jae 0x2c03
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x10(%rax), %rdi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0xbff8, %rdx           # imm = 0xBFF8
movzbl %al, %esi
callq 0x2820
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x8120(%rax), %rax
movq %rcx, 0x10(%rax)
jmp 0x2c05
jmp 0x2c05
jmp 0x2c07
jmp 0x2c09
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ClintRead
uint8_t ClintRead(State *state, uint64_t offset) {
    if (offset >= CLINT_MSIP_BASE && offset < CLINT_MSIP_BASE + CLINT_MSIP_SIZE) {
        return ReadRange8(state->clint->msip, offset - CLINT_MSIP_BASE);
    } else if (offset >= CLINT_MTIMECMP_BASE && offset < CLINT_MTIMECMP_BASE + CLINT_MTIMECMP_SIZE) {
        return ReadRange8(state->clint->mtimecmp, offset - CLINT_MTIMECMP_BASE);
    } else if (offset >= CLINT_MTIME_BASE && offset < CLINT_MTIME_BASE + CLINT_MTIME_SIZE) {
        return ReadRange8(state->clint->mtime, offset - CLINT_MTIME_BASE);
    } else {
        return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jb 0x2c4f
cmpq $0x4, -0x18(%rbp)
jae 0x2c4f
movq -0x10(%rbp), %rax
movq 0x8120(%rax), %rax
movl (%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
subq $0x0, %rsi
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2cc3
cmpq $0x4000, -0x18(%rbp)    # imm = 0x4000
jb 0x2c87
cmpq $0x4008, -0x18(%rbp)    # imm = 0x4008
jae 0x2c87
movq -0x10(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
subq $0x4000, %rsi           # imm = 0x4000
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2cc3
cmpq $0xbff8, -0x18(%rbp)    # imm = 0xBFF8
jb 0x2cbf
cmpq $0xc000, -0x18(%rbp)    # imm = 0xC000
jae 0x2cbf
movq -0x10(%rbp), %rax
movq 0x8120(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
subq $0xbff8, %rsi           # imm = 0xBFF8
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2cc3
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: PlicWrite
void PlicWrite(State *state, uint64_t offset, uint8_t val) {
    if (offset >= PLIC_PRIORITY_BASE && offset < PLIC_PRIORITY_BASE + PLIC_PRIORITY_SIZE) {
        state->plic->priority[(offset - PLIC_PRIORITY_BASE + 4) / 4] = WriteRange8(state->plic->priority[(offset - PLIC_PRIORITY_BASE + 4) / 4], val, (offset - PLIC_PRIORITY_BASE + 4) % 4);
    } else if (offset >= PLIC_ENABLE_BASE && offset < PLIC_ENABLE_BASE + PLIC_ENABLE_SIZE) {
        state->plic->enable_bits = WriteRange8(state->plic->enable_bits, val, offset - PLIC_ENABLE_BASE);
    } else if (offset >= PLIC_THRESHOLD_BASE && offset < PLIC_THRESHOLD_BASE + PLIC_THRESHOLD_SIZE) {
        state->plic->threshold = WriteRange8(state->plic->threshold, val, offset - PLIC_THRESHOLD_BASE);
    } else if (offset >= PLIC_IRQ_BASE && offset < PLIC_IRQ_BASE + PLIC_IRQ_SIZE) {
        state->plic->irq = WriteRange8(state->plic->irq, val, offset - PLIC_IRQ_BASE);
    }
}

// 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 $0x4, -0x10(%rbp)
jb 0x2d56
cmpq $0xffc, -0x10(%rbp)     # imm = 0xFFC
jae 0x2d56
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movq -0x10(%rbp), %rcx
subq $0x4, %rcx
addq $0x4, %rcx
shrq $0x2, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x4, %rdx
addq $0x4, %rdx
andq $0x3, %rdx
movzbl %al, %esi
callq 0x2820
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movq -0x10(%rbp), %rcx
subq $0x4, %rcx
addq $0x4, %rcx
shrq $0x2, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2e54
cmpq $0x2080, -0x10(%rbp)    # imm = 0x2080
jb 0x2dac
cmpq $0x2088, -0x10(%rbp)    # imm = 0x2088
jae 0x2dac
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movq 0x1008(%rax), %rdi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x2080, %rdx           # imm = 0x2080
movzbl %al, %esi
callq 0x2820
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movq %rcx, 0x1008(%rax)
jmp 0x2e52
cmpq $0x201000, -0x10(%rbp)  # imm = 0x201000
jb 0x2dfe
cmpq $0x201004, -0x10(%rbp)  # imm = 0x201004
jae 0x2dfe
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movl 0x1010(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x201000, %rdx         # imm = 0x201000
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movl %ecx, 0x1010(%rax)
jmp 0x2e50
cmpq $0x201004, -0x10(%rbp)  # imm = 0x201004
jb 0x2e4e
cmpq $0x201008, -0x10(%rbp)  # imm = 0x201008
jae 0x2e4e
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movl 0x1000(%rax), %eax
movl %eax, %edi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %rdx
subq $0x201004, %rdx         # imm = 0x201004
movzbl %al, %esi
callq 0x2820
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x8128(%rax), %rax
movl %ecx, 0x1000(%rax)
jmp 0x2e50
jmp 0x2e52
jmp 0x2e54
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: PlicRead
uint8_t PlicRead(State *state, uint64_t offset) {
    if (offset >= PLIC_PRIORITY_BASE && offset < PLIC_PRIORITY_BASE + PLIC_PRIORITY_SIZE) {
        return ReadRange8(state->plic->priority[(offset - PLIC_PRIORITY_BASE) / 4], (offset - PLIC_PRIORITY_BASE) % 4);
    } else if (offset >= PLIC_ENABLE_BASE && offset < PLIC_ENABLE_BASE + PLIC_ENABLE_SIZE) {
        return ReadRange8(state->plic->enable_bits, offset - PLIC_ENABLE_BASE);
    } else if (offset >= PLIC_THRESHOLD_BASE && offset < PLIC_THRESHOLD_BASE + PLIC_THRESHOLD_SIZE) {
        return ReadRange8(state->plic->threshold, offset - PLIC_THRESHOLD_BASE);
    } else if (offset >= PLIC_IRQ_BASE && offset < PLIC_IRQ_BASE + PLIC_IRQ_SIZE) {
        return ReadRange8(state->plic->irq, offset - PLIC_IRQ_BASE);
    } else {
        return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x4, -0x18(%rbp)
jb 0x2eb6
cmpq $0xffc, -0x18(%rbp)     # imm = 0xFFC
jae 0x2eb6
movq -0x10(%rbp), %rax
movq 0x8128(%rax), %rax
movq -0x18(%rbp), %rcx
subq $0x4, %rcx
shrq $0x2, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
subq $0x4, %rsi
andq $0x3, %rsi
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2f6d
cmpq $0x2080, -0x18(%rbp)    # imm = 0x2080
jb 0x2ef1
cmpq $0x2088, -0x18(%rbp)    # imm = 0x2088
jae 0x2ef1
movq -0x10(%rbp), %rax
movq 0x8128(%rax), %rax
movq 0x1008(%rax), %rdi
movq -0x18(%rbp), %rsi
subq $0x2080, %rsi           # imm = 0x2080
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2f6d
cmpq $0x201000, -0x18(%rbp)  # imm = 0x201000
jb 0x2f2d
cmpq $0x201004, -0x18(%rbp)  # imm = 0x201004
jae 0x2f2d
movq -0x10(%rbp), %rax
movq 0x8128(%rax), %rax
movl 0x1010(%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
subq $0x201000, %rsi         # imm = 0x201000
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2f6d
cmpq $0x201004, -0x18(%rbp)  # imm = 0x201004
jb 0x2f69
cmpq $0x201008, -0x18(%rbp)  # imm = 0x201008
jae 0x2f69
movq -0x10(%rbp), %rax
movq 0x8128(%rax), %rax
movl 0x1000(%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
subq $0x201004, %rsi         # imm = 0x201004
callq 0x28a0
movb %al, -0x1(%rbp)
jmp 0x2f6d
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemWrite8
void MemWrite8(State *state, uint64_t addr, uint8_t val) {
    if (addr >= UART_BASE && addr < (UART_BASE + UART_SIZE)) {
        UartWrite(state, addr - UART_BASE, val);
        return;
    } else if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
        ClintWrite(state, addr - CLINT_BASE, val);
        return;
    } else if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
        PlicWrite(state, addr - PLIC_BASE, val);
        return;
    } else if (addr >= VIRTIO_BASE && addr < (VIRTIO_BASE + VIRTIO_SIZE)) {
        VirtioWrite(state, addr - VIRTIO_BASE, val);
        return;
    } else if (addr >= DRAM_BASE) {
        *(uint8_t *)(state->mem + (addr - DRAM_BASE)) = val;
        return;
    }
    state->excepted = true;
    state->exception_code = StoreAMOPageFault;
    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 $0x10000000, -0x10(%rbp) # imm = 0x10000000
jb 0x36f6
cmpq $0x10000100, -0x10(%rbp) # imm = 0x10000100
jae 0x36f6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
subq $0x10000000, %rsi       # imm = 0x10000000
movzbl -0x11(%rbp), %edx
callq 0x28f0
jmp 0x37d4
cmpq $0x2000000, -0x10(%rbp) # imm = 0x2000000
jb 0x3727
cmpq $0x2010000, -0x10(%rbp) # imm = 0x2010000
jae 0x3727
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
subq $0x2000000, %rsi        # imm = 0x2000000
movzbl -0x11(%rbp), %edx
callq 0x2b10
jmp 0x37d4
cmpq $0xc000000, -0x10(%rbp) # imm = 0xC000000
jb 0x3755
cmpq $0x10000000, -0x10(%rbp) # imm = 0x10000000
jae 0x3755
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
subq $0xc000000, %rsi        # imm = 0xC000000
movzbl -0x11(%rbp), %edx
callq 0x2cd0
jmp 0x37d4
cmpq $0x10001000, -0x10(%rbp) # imm = 0x10001000
jb 0x3783
cmpq $0x10002000, -0x10(%rbp) # imm = 0x10002000
jae 0x3783
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
subq $0x10001000, %rsi       # imm = 0x10001000
movzbl -0x11(%rbp), %edx
callq 0x3280
jmp 0x37d4
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, -0x10(%rbp)
jb 0x37b2
movb -0x11(%rbp), %dl
movq -0x8(%rbp), %rax
movq 0x8108(%rax), %rax
movq -0x10(%rbp), %rcx
movabsq $0x80000000, %rsi       # imm = 0x80000000
subq %rsi, %rcx
movb %dl, (%rax,%rcx)
jmp 0x37d4
jmp 0x37b4
jmp 0x37b6
jmp 0x37b8
jmp 0x37ba
movq -0x8(%rbp), %rax
movb $0x1, 0x8138(%rax)
movq -0x8(%rbp), %rax
movq $0xf, 0x8140(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemWrite16
void MemWrite16(State *state, uint64_t addr, uint16_t val) {
    // if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return;
    // } else if (addr >= DRAM_BASE) {
    //     *(uint16_t *)(state->mem + (addr - DRAM_BASE)) = val;
    //     return;
    // }
    for (int i = 0; i < 2; i++) {
        MemWrite8(state, addr + i, (uint8_t)(val >> (i * 8) & SetNBits(8)));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movw %dx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x2, -0x18(%rbp)
jge 0x385c
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movzwl -0x12(%rbp), %eax
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
sarl %cl, %eax
cltq
movq %rax, -0x20(%rbp)
movl $0x8, %edi
callq 0x12b0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq %rax, %rcx
movq -0x20(%rbp), %rax
andq %rcx, %rax
movzbl %al, %edx
callq 0x36b0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x37fe
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemWrite32
void MemWrite32(State *state, uint64_t addr, uint32_t val) {
    // if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return;
    // } else if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
    //     return;
    // } else if (addr >= DRAM_BASE) {
    //     *(uint32_t *)(state->mem + (addr - DRAM_BASE)) = val;
    //     return;
    // }
    for (int i = 0; i < 4; i++) {
        MemWrite8(state, addr + i, (uint8_t)(val >> (i * 8) & SetNBits(8)));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0x38e7
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
shrl %cl, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0x8, %edi
callq 0x12b0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq %rax, %rcx
movq -0x20(%rbp), %rax
andq %rcx, %rax
movzbl %al, %edx
callq 0x36b0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x388a
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemWrite64
void MemWrite64(State *state, uint64_t addr, uint64_t val) {
    // if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return;
    // } else if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
    //     return;
    // } else if (addr >= DRAM_BASE) {
    //     *(uint64_t *)(state->mem + (addr - DRAM_BASE)) = val;
    //     return;
    // }
    for (int i = 0; i < 8; i++) {
        MemWrite8(state, addr + i, (uint8_t)(val >> (i * 8) & SetNBits(8)));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x396a
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, -0x28(%rbp)
movl $0x8, %edi
callq 0x12b0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %rax, %rcx
movq -0x28(%rbp), %rax
andq %rcx, %rax
movzbl %al, %edx
callq 0x36b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x390b
addq $0x40, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemRead8
uint8_t MemRead8(State *state, uint64_t addr) {
    if (addr >= UART_BASE && addr < (UART_BASE + UART_SIZE)) {
        return UartRead(state, addr - UART_BASE);
    } else if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
        return ClintRead(state, addr - CLINT_BASE);
    } else if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
        return PlicRead(state, addr - PLIC_BASE);
    } else if (addr >= VIRTIO_BASE && addr < (VIRTIO_BASE + VIRTIO_SIZE)) {
        return VirtioRead(state, addr - VIRTIO_BASE);
    } else if (addr >= DRAM_BASE) {
        return *(uint8_t *)(state->mem + (addr - DRAM_BASE));
    }
    state->excepted = true;
    state->exception_code = LoadPageFault;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x10000000, -0x18(%rbp) # imm = 0x10000000
jb 0x39b0
cmpq $0x10000100, -0x18(%rbp) # imm = 0x10000100
jae 0x39b0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x10000000, %rsi       # imm = 0x10000000
callq 0x29d0
movb %al, -0x1(%rbp)
jmp 0x3a92
cmpq $0x2000000, -0x18(%rbp) # imm = 0x2000000
jb 0x39e0
cmpq $0x2010000, -0x18(%rbp) # imm = 0x2010000
jae 0x39e0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x2000000, %rsi        # imm = 0x2000000
callq 0x2c10
movb %al, -0x1(%rbp)
jmp 0x3a92
cmpq $0xc000000, -0x18(%rbp) # imm = 0xC000000
jb 0x3a10
cmpq $0x10000000, -0x18(%rbp) # imm = 0x10000000
jae 0x3a10
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0xc000000, %rsi        # imm = 0xC000000
callq 0x2e60
movb %al, -0x1(%rbp)
jmp 0x3a92
cmpq $0x10001000, -0x18(%rbp) # imm = 0x10001000
jb 0x3a3d
cmpq $0x10002000, -0x18(%rbp) # imm = 0x10002000
jae 0x3a3d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x10001000, %rsi       # imm = 0x10001000
callq 0x3500
movb %al, -0x1(%rbp)
jmp 0x3a92
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, -0x18(%rbp)
jb 0x3a6c
movq -0x10(%rbp), %rax
movq 0x8108(%rax), %rax
movq -0x18(%rbp), %rcx
movabsq $0x80000000, %rdx       # imm = 0x80000000
subq %rdx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x3a92
jmp 0x3a6e
jmp 0x3a70
jmp 0x3a72
jmp 0x3a74
movq -0x10(%rbp), %rax
movb $0x1, 0x8138(%rax)
movq -0x10(%rbp), %rax
movq $0xd, 0x8140(%rax)
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemRead16
uint16_t MemRead16(State *state, uint64_t addr) {
    // if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return 0;
    // } else if (addr >= DRAM_BASE) {
    //     return *(uint16_t *)(state->mem + (addr - DRAM_BASE));
    // }
    uint16_t val = 0;
    for (int i = 0; i < 2; i++) {
        val |= (uint16_t)(MemRead8(state, addr + i)) << (i * 8);
    }
    return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x2, -0x18(%rbp)
jge 0x3afc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
callq 0x3970
movzbl %al, %eax
movzwl %ax, %eax
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
shll %cl, %eax
movl %eax, %ecx
movzwl -0x12(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x12(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3abd
movw -0x12(%rbp), %ax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemRead32
uint32_t MemRead32(State *state, uint64_t addr) {
    // if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
    //     return 0;
    // } else if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return 0;
    // } else if (addr >= DRAM_BASE) {
    //     return *(uint32_t *)(state->mem + (addr - DRAM_BASE));
    // }
    uint32_t val = 0;
    for (int i = 0; i < 4; i++) {
        val |= (uint32_t)(MemRead8(state, addr + i)) << (i * 8);
    }
    return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0x3b64
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
callq 0x3970
movzbl %al, %eax
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
shll %cl, %eax
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3b2e
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: MemRead64
uint64_t MemRead64(State *state, uint64_t addr) {
    // if (addr >= PLIC_BASE && addr < (PLIC_BASE + PLIC_SIZE)) {
    //     return 0;
    // } else if (addr >= CLINT_BASE && addr < (CLINT_BASE + CLINT_SIZE)) {
    //     return 0;
    // } else if (addr >= DRAM_BASE) {
    //     return *(uint64_t *)(state->mem + (addr - DRAM_BASE));
    // }
    uint64_t val = 0;
    for (int i = 0; i < 8; i++) {
        val |= (uint64_t)(MemRead8(state, addr + i)) << (i * 8);
    }
    return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x3bca
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x1c(%rbp), %rax
addq %rax, %rsi
callq 0x3970
movzbl %al, %eax
movl -0x1c(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shlq %cl, %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3b8f
movq -0x18(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: AccessFault
void AccessFault(State *state, uint8_t access_type) {
    state->excepted = true;
    switch (access_type) {
    case AccessInstruction:
        state->exception_code = InstructionAccessFault;
        break;
    case AccessLoad:
        state->exception_code = LoadAccessFault;
        break;
    case AccessStore:
        state->exception_code = StoreAMOAccessFault;
        break;
    default:
        Error("Unknown access type: %d", access_type);
        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movb $0x1, 0x8138(%rax)
movzbl -0x9(%rbp), %eax
movl %eax, -0x10(%rbp)
testl %eax, %eax
je 0x3c1e
jmp 0x3c0a
movl -0x10(%rbp), %eax
subl $0x1, %eax
je 0x3c2f
jmp 0x3c14
movl -0x10(%rbp), %eax
subl $0x2, %eax
je 0x3c40
jmp 0x3c51
movq -0x8(%rbp), %rax
movq $0x1, 0x8140(%rax)
jmp 0x3c63
movq -0x8(%rbp), %rax
movq $0x5, 0x8140(%rax)
jmp 0x3c63
movq -0x8(%rbp), %rax
movq $0x7, 0x8140(%rax)
jmp 0x3c63
movzbl -0x9(%rbp), %esi
leaq 0xb75b(%rip), %rdi      # 0xf3b7
movb $0x0, %al
callq 0xd690
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: PageFault
void PageFault(State *state, uint8_t access_type) {
    state->excepted = true;
    switch (access_type) {
    case AccessInstruction:
        state->exception_code = InstructionPageFault;
        break;
    case AccessLoad:
        state->exception_code = LoadPageFault;
        break;
    case AccessStore:
        state->exception_code = StoreAMOPageFault;
        break;
    default:
        Error("Unknown access type: %d", access_type);
        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movb $0x1, 0x8138(%rax)
movzbl -0x9(%rbp), %eax
movl %eax, -0x10(%rbp)
testl %eax, %eax
je 0x3cae
jmp 0x3c9a
movl -0x10(%rbp), %eax
subl $0x1, %eax
je 0x3cbf
jmp 0x3ca4
movl -0x10(%rbp), %eax
subl $0x2, %eax
je 0x3cd0
jmp 0x3ce1
movq -0x8(%rbp), %rax
movq $0xc, 0x8140(%rax)
jmp 0x3cf3
movq -0x8(%rbp), %rax
movq $0xd, 0x8140(%rax)
jmp 0x3cf3
movq -0x8(%rbp), %rax
movq $0xf, 0x8140(%rax)
jmp 0x3cf3
movzbl -0x9(%rbp), %esi
leaq 0xb6cb(%rip), %rdi      # 0xf3b7
movb $0x0, %al
callq 0xd690
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: Require
bool Require(State *state, uint8_t mode) {
    if (state->mode == MACHINE) {
        if (mode == MACHINE || mode == SUPERVISOR || mode == USER) {
            return true;
        }
    } else if (state->mode == SUPERVISOR) {
        if (mode == SUPERVISOR || mode == USER) {
            return true;
        }
    } else if (state->mode == USER) {
        if (mode == USER) {
            return true;
        }
    }

    state->excepted = true;
    // printf("Require Illegal Instruction: pc: 0x%llx, state->mode: %d, mode: %d\n", state->pc, state->mode, mode);
    state->exception_code = IllegalInstruction;
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x8148(%rax), %eax
cmpl $0x3, %eax
jne 0x43f1
movzbl -0x11(%rbp), %eax
cmpl $0x3, %eax
je 0x43e9
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
je 0x43e9
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x43ef
movb $0x1, -0x1(%rbp)
jmp 0x445e
jmp 0x4440
movq -0x10(%rbp), %rax
movzbl 0x8148(%rax), %eax
cmpl $0x1, %eax
jne 0x441b
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
je 0x4413
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x4419
movb $0x1, -0x1(%rbp)
jmp 0x445e
jmp 0x443e
movq -0x10(%rbp), %rax
movzbl 0x8148(%rax), %eax
cmpl $0x0, %eax
jne 0x443c
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x443a
movb $0x1, -0x1(%rbp)
jmp 0x445e
jmp 0x443c
jmp 0x443e
jmp 0x4440
movq -0x10(%rbp), %rax
movb $0x1, 0x8138(%rax)
movq -0x10(%rbp), %rax
movq $0x2, 0x8140(%rax)
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ExecAddi
void ExecAddi(State *state, uint32_t instr) {
    uint8_t rd = instr >> 7 & SetNBits(5);
    uint8_t rs1 = instr >> 15 & SetNBits(5);
    int32_t immediate = Sext(instr >> 20 & SetNBits(12), 11);

    state->x[rd] = state->x[rs1] + immediate;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
shrl $0x7, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x30(%rbp), %rax
andq %rcx, %rax
movb %al, -0xd(%rbp)
movl -0xc(%rbp), %eax
shrl $0xf, %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
andq %rcx, %rax
movb %al, -0xe(%rbp)
movl -0xc(%rbp), %eax
shrl $0x14, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0xc, %edi
callq 0x12b0
movq -0x20(%rbp), %rdi
andq %rax, %rdi
movl $0xb, %esi
callq 0x4470
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl -0xe(%rbp), %ecx
movq 0x8008(%rax,%rcx,8), %rdx
movslq -0x14(%rbp), %rax
addq %rax, %rdx
movq -0x8(%rbp), %rax
movzbl -0xd(%rbp), %ecx
movq %rdx, 0x8008(%rax,%rcx,8)
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ExecSlli
void ExecSlli(State *state, uint32_t instr) {
    uint8_t rd = instr >> 7 & SetNBits(5);
    uint8_t rs1 = instr >> 15 & SetNBits(5);
    uint8_t immediate = instr >> 20 & SetNBits(6);

    state->x[rd] = (uint64_t)state->x[rs1] << (uint64_t)immediate;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
shrl $0x7, %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
andq %rcx, %rax
movb %al, -0xd(%rbp)
movl -0xc(%rbp), %eax
shrl $0xf, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
andq %rcx, %rax
movb %al, -0xe(%rbp)
movl -0xc(%rbp), %eax
shrl $0x14, %eax
movl %eax, %eax
movq %rax, -0x18(%rbp)
movl $0x6, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
andq %rcx, %rax
movb %al, -0xf(%rbp)
movq -0x8(%rbp), %rax
movzbl -0xe(%rbp), %ecx
movq 0x8008(%rax,%rcx,8), %rdx
movzbl -0xf(%rbp), %eax
movl %eax, %ecx
shlq %cl, %rdx
movq -0x8(%rbp), %rax
movzbl -0xd(%rbp), %ecx
movq %rdx, 0x8008(%rax,%rcx,8)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ExecSltiu
void ExecSltiu(State *state, uint32_t instr) {
    uint8_t rd = instr >> 7 & SetNBits(5);
    uint8_t rs1 = instr >> 15 & SetNBits(5);
    int32_t immediate = Sext(instr >> 20 & SetNBits(12), 11);

    state->x[rd] = ((uint64_t)state->x[rs1]) < ((uint64_t)immediate);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
shrl $0x7, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x30(%rbp), %rax
andq %rcx, %rax
movb %al, -0xd(%rbp)
movl -0xc(%rbp), %eax
shrl $0xf, %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
andq %rcx, %rax
movb %al, -0xe(%rbp)
movl -0xc(%rbp), %eax
shrl $0x14, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0xc, %edi
callq 0x12b0
movq -0x20(%rbp), %rdi
andq %rax, %rdi
movl $0xb, %esi
callq 0x4470
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl -0xe(%rbp), %ecx
movq 0x8008(%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
cmpq %rcx, %rax
setb %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rdx
movq -0x8(%rbp), %rax
movzbl -0xd(%rbp), %ecx
movq %rdx, 0x8008(%rax,%rcx,8)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/cpu.c
// Function: ExecOri
void ExecOri(State *state, uint32_t instr) {
    uint8_t rd = (instr >> 7) & SetNBits(5);
    uint8_t rs1 = (instr >> 15) & SetNBits(5);
    uint64_t immediate = Sext((instr >> 20) & SetNBits(12), 11);

    state->x[rd] = state->x[rs1] | immediate;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
shrl $0x7, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x30(%rbp), %rax
andq %rcx, %rax
movb %al, -0xd(%rbp)
movl -0xc(%rbp), %eax
shrl $0xf, %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movl $0x5, %edi
callq 0x12b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
andq %rcx, %rax
movb %al, -0xe(%rbp)
movl -0xc(%rbp), %eax
shrl $0x14, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movl $0xc, %edi
callq 0x12b0
movq -0x20(%rbp), %rdi
andq %rax, %rdi
movl $0xb, %esi
callq 0x4470
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzbl -0xe(%rbp), %ecx
movq 0x8008(%rax,%rcx,8), %rdx
orq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movzbl -0xd(%rbp), %ecx
movq %rdx, 0x8008(%rax,%rcx,8)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)