LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/wierton[P]socket-based-naive-game/client.c
// Function: draw_items
void draw_items(server_message_t *psm) {
	lock_cursor();
	for(int i = 0; i < MAX_ITEM; i++) {
		if(psm->item_kind[i] == ITEM_NONE)
			continue;

		set_cursor(psm->item_pos[i].x, psm->item_pos[i].y);
		switch(psm->item_kind[i]) {
			case ITEM_MAGAZINE:printf("+");break;
			case ITEM_MAGMA:printf("╳");break;
			case ITEM_GRASS:printf("█");break;
			case ITEM_BLOOD_VIAL:printf("*");break;
			case ITEM_BULLET:printf(".");
		}
	}

	fflush(stdout);

	unlock_cursor();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x2d71
movq $-0x87, %r15
leaq 0x82d(%rip), %r12       # 0x5004
pushq $0x2a
popq %r13
pushq $0x2e
popq %r14
testq %r15, %r15
je 0x484f
cmpb $0x0, 0x95(%rbx,%r15)
je 0x484a
movzbl 0x1a3(%rbx,%r15,2), %edi
movzbl 0x1a4(%rbx,%r15,2), %esi
callq 0x2d05
movzbl 0x95(%rbx,%r15), %eax
decl %eax
cmpl $0x5, %eax
ja 0x484a
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
pushq $0x2b
popq %rdi
jmp 0x4845
leaq 0x185c(%rip), %rdi      # 0x6087
jmp 0x4834
leaq 0x184f(%rip), %rdi      # 0x6083
xorl %eax, %eax
callq 0x20b0
jmp 0x484a
movl %r13d, %edi
jmp 0x4845
movl %r14d, %edi
callq 0x2040
incq %r15
jmp 0x47df
movq 0x4772(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x2160
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d82
// File: /workspace/github_c_makefile_star2_O2/wierton[P]socket-based-naive-game/client.c
// Function: log_psm_info
void log_psm_info(server_message_t *psm) {
	int len = 0;
	static char s[1024 * 1024];
	char *p = s;
	len += sprintf(p + len, "message: %d, life:%d, user_index:%d\n", psm->message, psm->life, psm->index);
	len += sprintf(p + len, "user_pos:");
	for(int i = 0; i < USER_CNT; i++) {
		len += sprintf(p + len, "(%d,%d), ", psm->user_pos[i].x, psm->user_pos[i].y);
	}

	len += sprintf(p + len, "\n");

	len += sprintf(p + len, "items:");
	for(int i = 0; i < MAX_ITEM; i++) {
		len += sprintf(p + len, "(%d:%d,%d), ", psm->item_kind[i], psm->item_pos[i].x, psm->item_pos[i].y);
	}

	len += sprintf(p + len, "\n");

	if(len > sizeof(s) - 1)
		eprintf("buffer overflow\n");

	wlog("battle info:\n%s\n", s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzbl (%rdi), %edx
movzbl 0x1(%rdi), %ecx
movzbl 0x2(%rdi), %r8d
leaq 0x4c1b(%rip), %r14      # 0x94b0
leaq 0x17ef(%rip), %rsi      # 0x608b
movq %r14, %rdi
xorl %eax, %eax
callq 0x21c0
movslq %eax, %r12
movabsq $0x736f705f72657375, %rax # imm = 0x736F705F72657375
movq %rax, (%r12,%r14)
movw $0x3a, 0x8(%r12,%r14)
addl $0x9, %r12d
leaq 0x17f0(%rip), %r15      # 0x60ba
xorl %r13d, %r13d
movslq %r12d, %rdi
addq %r14, %rdi
cmpq $0x5, %r13
je 0x48f7
movzbl 0x4(%rbx,%r13,2), %edx
movzbl 0x5(%rbx,%r13,2), %ecx
movq %r15, %rsi
xorl %eax, %eax
callq 0x21c0
addl %eax, %r12d
incq %r13
jmp 0x48cd
movw $0xa, (%rdi)
movl $0x3a736d, 0x4(%rdi)    # imm = 0x3A736D
movl $0x6d657469, 0x1(%rdi)  # imm = 0x6D657469
addl $0x7, %r12d
pushq $0x4b
popq %r13
leaq 0x17b2(%rip), %r15      # 0x60cb
movslq %r12d, %rdi
addq %r14, %rdi
cmpq $0xd2, %r13
je 0x494b
movzbl -0x3d(%rbx,%r13), %edx
movzbl -0x1(%rbx,%r13,2), %ecx
movzbl (%rbx,%r13,2), %r8d
movq %r15, %rsi
xorl %eax, %eax
callq 0x21c0
addl %eax, %r12d
incq %r13
jmp 0x4919
movw $0xa, (%rdi)
addl $0xfff00001, %r12d      # imm = 0xFFF00001
cmpl $0xfff00000, %r12d      # imm = 0xFFF00000
jb 0x498f
movq 0x47f9(%rip), %rsi      # 0x9160
leaq 0x1777(%rip), %rdi      # 0x60e5
leaq 0x4b3b(%rip), %rcx      # 0x94b0
movl $0x4c9, %edx            # imm = 0x4C9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x261e
movq 0x465a(%rip), %rax      # 0x8ff0
movq (%rax), %rdi
leaq 0xad9(%rip), %rsi       # 0x5479
leaq 0x1731(%rip), %rdx      # 0x60d8
movl $0x4c7, %ecx            # imm = 0x4C7
xorl %eax, %eax
callq 0x2130
xorl %edi, %edi
callq 0x21d0
// File: /workspace/github_c_makefile_star2_O2/wierton[P]socket-based-naive-game/client.c
// Function: serv_msg_battle_info
int serv_msg_battle_info(server_message_t *psm) {
	wlog("call message handler %s\n", __func__);
	if(user_state == USER_STATE_BATTLE) {
		log_psm_info(psm);
		user_bullets = psm->bullets_num;
		user_hp = psm->life;
		flip_old_items(psm);
		draw_users(psm);
		draw_items(psm);
		display_user_state();
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x4796(%rip), %rsi      # 0x9160
leaq 0x1016(%rip), %rdi      # 0x59e7
leaq 0x1725(%rip), %rcx      # 0x60fd
movl $0x4cd, %edx            # imm = 0x4CD
xorl %eax, %eax
callq 0x261e
cmpl $0x3, 0x4781(%rip)      # 0x916c
jne 0x4a26
movq %rbx, %rdi
callq 0x4871
movzbl 0x3(%rbx), %eax
movl %eax, 0x48d9(%rip)      # 0x92d8
movzbl 0x1(%rbx), %eax
movl %eax, 0x48cb(%rip)      # 0x92d4
movq %rbx, %rdi
callq 0x4639
movq %rbx, %rdi
callq 0x4740
movq %rbx, %rdi
callq 0x47b3
callq 0x2f94
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/wierton[P]socket-based-naive-game/client.c
// Function: message_monitor
void *message_monitor(void *args) {
	server_message_t sm;
	wlog("monitor thread starts\n");
	while(1) {
		wrap_recv(&sm);
		wlog("receive server message: %s\n", server_message_s[sm.message]);
		if(recv_msg_func[sm.message]) {
			wlog("==> call message handler\n");
			recv_msg_func[sm.message](&sm);
			wlog("==> quit message handler\n");
		}

		// delay assignment
		if(sm.message == SERVER_RESPONSE_LOGIN_SUCCESS
			|| sm.message == SERVER_RESPONSE_YOU_HAVE_LOGINED
			|| sm.message == SERVER_RESPONSE_LOGIN_FAIL_UNREGISTERED_USERID
			|| sm.message == SERVER_RESPONSE_LOGIN_FAIL_ERROR_PASSWORD
			|| sm.message == SERVER_RESPONSE_LOGIN_FAIL_DUP_USERID
			|| sm.message == SERVER_RESPONSE_LOGIN_FAIL_SERVER_LIMITS
			|| sm.message == SERVER_RESPONSE_LAUNCH_BATTLE_SUCCESS
			|| sm.message == SERVER_RESPONSE_LAUNCH_BATTLE_FAIL)
		global_serv_message = sm.message;
	}
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq 0x45d8(%rip), %rsi      # 0x9160
leaq 0x16a1(%rip), %rdi      # 0x6230
movl $0x524, %edx            # imm = 0x524
xorl %eax, %eax
callq 0x261e
leaq -0x1cb(%rbp), %rbx
leaq 0x3f57(%rip), %r13      # 0x8b00
leaq 0x169e(%rip), %r14      # 0x624e
movl $0x98001, %r15d         # imm = 0x98001
movl $0x67b0, %r12d          # imm = 0x67B0
movq %rbx, %rdi
callq 0x242c
movq 0x4595(%rip), %rsi      # 0x9160
movzbl -0x1cb(%rbp), %eax
movq (%r13,%rax,8), %rcx
movq %r14, %rdi
movl $0x527, %edx            # imm = 0x527
xorl %eax, %eax
callq 0x261e
movzbl -0x1cb(%rbp), %eax
btq %rax, %r15
jb 0x4c41
movq 0x4566(%rip), %rsi      # 0x9160
leaq 0x1670(%rip), %rdi      # 0x6271
movl $0x529, %edx            # imm = 0x529
xorl %eax, %eax
callq 0x261e
movzbl -0x1cb(%rbp), %eax
movq %rbx, %rdi
leaq 0x4092(%rip), %rcx      # 0x8cb0
callq *(%rcx,%rax,8)
movq 0x4538(%rip), %rsi      # 0x9160
leaq 0x1663(%rip), %rdi      # 0x6292
movl $0x52b, %edx            # imm = 0x52B
xorl %eax, %eax
callq 0x261e
movb -0x1cb(%rbp), %al
cmpb $0xe, %al
ja 0x4bbc
movzbl %al, %eax
btl %eax, %r12d
jae 0x4bbc
movl %eax, 0x450c(%rip)      # 0x9168
jmp 0x4bbc
// File: /workspace/github_c_makefile_star2_O2/wierton[P]socket-based-naive-game/client.c
// Function: main
int main() {
	wlog("====================START====================\n");
	client_fd = connect_to_server();

	system("clear");
	init_scr_wh();
	wrap_get_term_attr(&raw_termio);
	hide_cursor();

	flip_screen();

	start_message_monitor();
	start_ui();

	resume_and_exit(0);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x44a3(%rip), %rsi      # 0x9160
leaq 0x163f(%rip), %rdi      # 0x6303
movl $0x545, %edx            # imm = 0x545
xorl %eax, %eax
callq 0x261e
callq 0x2339
movl %eax, 0x447d(%rip)      # 0x9158
leaq 0x1657(%rip), %rdi      # 0x6339
callq 0x2090
callq 0x2d93
leaq 0x4565(%rip), %rdi      # 0x9258
callq 0x2bca
callq 0x2d1d
callq 0x33ac
callq 0x4c61
callq 0x3c7e
// File: /workspace/github_c_makefile_star2_O2/CkTD[P]btree/table_test1.c
// Function: main
int main()
{
    TableOpenFlag   flag;
    Table          *table;
    TableRows      *rows;
    TableRow       *row;
    uint64_t        i,j,n,count;
    

    flag.dir = "test_table";
    flag.create_if_missing = 1;
    flag.error_if_exist = 0;

    table = table_open(flag);

    printf("插入 1000000 行随机数据，每一行所有属性相同...\n");
    for(i = 0; i < 1000000; i++)
    {
        row = table_row_new();
        n = rand() % 1000000;
        for(j=0;j<100;j++)
            table_row_set_property(row, j, n );
        table_append(table, row);
        if (n<=1010 && n >=1000)
            printf("\t插入一个属性都为 %ld 的行\n", n);
    }

    printf("查找 第0个属性的范围在 1000 到 10010 的行，limit = 100.\n");
    rows = table_search_range(table, 0, 1000, 1010, 100);
    count = table_rows_get_counts(rows);
    for(i = 0; i < count; i++)
    {
        row = table_rows_get_row(rows, i);
        printf("\tROW %lu, first 10 properties: ", i);
        for(j = 0; j < 10; j++)
        {
            printf("%lu ", table_row_get_property(row, j));
        }
        printf("\n");
    }
    table_rows_destory(rows);

    printf("关闭表(刷磁盘)....\n");
    table_close(table);
    printf("done\n");
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1aea(%rip), %rdi      # 0x4c58
pushq $0x1
popq %rsi
callq 0x2ac2
movq %rax, (%rsp)
leaq 0x1b28(%rip), %rdi      # 0x4ca9
callq 0x1070
movl $0xf4240, %r13d         # imm = 0xF4240
xorl %r14d, %r14d
cmpq $0xf4240, %r14          # imm = 0xF4240
je 0x31f9
xorl %eax, %eax
callq 0x26cc
movq %rax, %r15
callq 0x11b0
cltd
idivl %r13d
movl %edx, %ebp
movslq %edx, %rbx
xorl %r12d, %r12d
cmpq $0x64, %r12
je 0x31cc
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x26db
incq %r12
jmp 0x31b3
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2966
addl $0xfffffc18, %ebp       # imm = 0xFFFFFC18
cmpl $0xa, %ebp
ja 0x31f4
leaq 0x1a79(%rip), %rdi      # 0x4c63
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
incq %r14
jmp 0x318f
leaq 0x1ae9(%rip), %rdi      # 0x4ce9
callq 0x1070
pushq $0x64
popq %r8
movl $0x3e8, %edx            # imm = 0x3E8
movl $0x3f2, %ecx            # imm = 0x3F2
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x27a4
movq %rax, %r14
movq %rax, %rdi
callq 0x26e0
movq %rax, %r15
leaq 0x1084(%rip), %r13      # 0x42b7
xorl %ebx, %ebx
cmpq %r15, %rbx
je 0x328b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26e4
movq %rax, %r12
leaq 0x1a3a(%rip), %rdi      # 0x4c89
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
xorl %ebp, %ebp
cmpq $0xa, %rbp
je 0x327e
movq %r12, %rdi
movq %rbp, %rsi
callq 0x26d6
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x10a0
incq %rbp
jmp 0x325b
pushq $0xa
popq %rdi
callq 0x1040
incq %rbx
jmp 0x3235
movq %r14, %rdi
callq 0x2712
leaq 0x1a95(%rip), %rdi      # 0x4d2f
callq 0x1070
movq (%rsp), %rdi
callq 0x2f47
leaq 0x1a99(%rip), %rdi      # 0x4d48
callq 0x1070
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/983[P]bigint/cpp_examples.cpp
// Function: xorshift32()
uint32_t xorshift32() {
    static uint32_t x = 314159265;
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return x;
}

// Assembly:
movl 0x5e4e(%rip), %eax      # 0x70a0
movl %eax, %ecx
shll $0xd, %ecx
xorl %eax, %ecx
movl %ecx, %edx
shrl $0x11, %edx
xorl %ecx, %edx
movl %edx, %eax
shll $0x5, %eax
xorl %edx, %eax
movl %eax, 0x5e33(%rip)      # 0x70a0
retq
// File: /workspace/github_c_makefile_star2_O2/983[P]bigint/./bigint.hpp
// Function: std::ostream& BigInt::write<std::ostream>(std::ostream&, int) const
STREAM& write(STREAM &s, int dst_base = 10) const {
        int n = bigint_write_size(data, dst_base);
        char *buf = (char*)malloc(n);
        write(buf, &n, dst_base);
        s << buf;
        free(buf);
        return s;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
cvtsi2sd %edx, %xmm0
callq 0x2466
leaq 0xc(%rsp), %r15
movl %eax, (%r15)
movslq %eax, %rdi
callq 0x10e0
movq %rax, %r12
pushq $0x1
popq %r8
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x3014
movq %rbx, %rdi
movq %r12, %rsi
callq 0x10c0
movq %r12, %rdi
callq 0x10d0
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/hobo0xcc[P]rve/src/cpu.c
// Function: GetRange
uint64_t GetRange(uint64_t v, uint64_t start, uint64_t end) {
    if (start < 0 || end >= 64) {
        Error("Out of range: GetRange");
    }
    
    uint64_t mask = SetNBits(end - start + 1);
    return (v & (mask << start)) >> start;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x40, %rdx
jb 0x132a
leaq 0x5f31(%rip), %rdi      # 0x7254
xorl %eax, %eax
callq 0x5ca8
subl %ebx, %r15d
incl %r15d
pushq $-0x1
popq %rdx
movq %rdx, %rax
movl %r15d, %ecx
shlq %cl, %rax
cmpl $0x40, %r15d
notq %rax
cmoveq %rdx, %rax
movl %ebx, %ecx
shlq %cl, %rax
andq %r14, %rax
shrq %cl, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/hobo0xcc[P]rve/src/cpu.c
// Function: HandleTrap
void HandleTrap(State *state, uint64_t instr_addr) {
    uint8_t prev_mode = state->mode;
    uint64_t cause = state->exception_code;
    // printf("Trap: addr: 0x%llx, cause: 0x%llx\n", instr_addr, cause);
    uint64_t mdeleg = MEDELEG;
    if (cause & SetOneBit(63)) {
        mdeleg = MIDELEG;
    }
    if (state->mode <= SUPERVISOR && state->csr[mdeleg] >> (cause & 0xffff) & 1) {
        state->mode = SUPERVISOR;
        state->csr[SEPC] = instr_addr;
        uint64_t vector = 0;
        if (ReadCSR(state, STVEC, 0, 0) == 1) {
            vector = 4 * (cause & SetNBits(63));
        }
        state->pc = (state->csr[STVEC] & ~1) + vector;
        state->csr[SCAUSE] = cause;
        state->csr[STVAL] = 0;
        WriteCSR(state, SSTATUS, 5, 5, ReadCSR(state, SSTATUS, 1, 1));
        WriteCSR(state, SSTATUS, 1, 1, 0);
        if (prev_mode == USER) {
            WriteCSR(state, SSTATUS, 8, 8, 0);
        } else {
            WriteCSR(state, SSTATUS, 8, 8, 1);
        }
    } else {
        state->mode = MACHINE;
        state->csr[MEPC] = instr_addr;
        uint64_t vector = 0;
        if (ReadCSR(state, MTVEC, 0, 0) == 1) {
            vector = 4 * (cause & SetNBits(63));
        }
        state->pc = (state->csr[MTVEC] & ~1) + vector;
        state->csr[MCAUSE] = cause;
        state->csr[MTVAL] = 0;
        // Save current Mode into CSRs[mstatus].MPP.
        WriteCSR(state, MSTATUS, 11, 12, prev_mode);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x8148(%rdi), %eax
movq 0x8140(%rdi), %rcx
cmpq $0x1, %rax
ja 0x13fa
xorl %edx, %edx
testq %rcx, %rcx
setns %dl
xorl $0x303, %edx            # imm = 0x303
movq 0x8(%rdi,%rdx,8), %rdx
btq %rcx, %rdx
jae 0x13fa
movb $0x1, 0x8148(%rdi)
movq %rsi, 0xa10(%rdi)
movq 0x808(%rdi), %rdx
movq 0x830(%rdi), %rsi
movl %esi, %r8d
andl $0x1, %r8d
negq %r8
leaq (,%rcx,4), %r9
andq %r8, %r9
andq $-0x2, %rsi
addq %r9, %rsi
movq %rsi, (%rdi)
movq %rcx, 0xa18(%rdi)
andq $0x0, 0xa20(%rdi)
movq %rdx, %rcx
andq $-0x23, %rcx
shll $0x4, %edx
andl $0x20, %edx
orq %rcx, %rdx
testq %rax, %rax
je 0x145b
orq $0x100, %rdx            # imm = 0x100
jmp 0x1462
movb $0x3, 0x8148(%rdi)
movq %rsi, 0x1a10(%rdi)
movq 0x1830(%rdi), %rdx
movl %edx, %esi
andl $0x1, %esi
negq %rsi
leaq (,%rcx,4), %r8
andq %rsi, %r8
andq $-0x2, %rdx
addq %r8, %rdx
movq %rdx, (%rdi)
movq %rcx, 0x1a18(%rdi)
andq $0x0, 0x1a20(%rdi)
movq $-0x1801, %rcx          # imm = 0xE7FF
andq 0x1808(%rdi), %rcx
andl $0x3, %eax
shll $0xb, %eax
orq %rcx, %rax
movq %rax, 0x1808(%rdi)
jmp 0x1469
andq $-0x103, %rdx           # imm = 0xFEFD
movq %rdx, 0x808(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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:
cmpb %cl, %dl
ja 0x1503
movzbl %cl, %ecx
movzbl %dl, %eax
subl %eax, %ecx
incl %ecx
pushq $-0x1
popq %rax
movq %rax, %r9
shlq %cl, %r9
cmpl $0x40, %ecx
notq %r9
cmoveq %rax, %r9
andq %r9, %r8
movl %edx, %ecx
shlq %cl, %r9
notq %r9
movzwl %si, %eax
shlq %cl, %r8
andq 0x8(%rdi,%rax,8), %r9
orq %r9, %r8
movq %r8, 0x8(%rdi,%rax,8)
retq
pushq %rbp
movq %rsp, %rbp
leaq 0x5dbc(%rip), %rdi      # 0x72ca
leaq 0x5dca(%rip), %rsi      # 0x72df
leaq 0x5dcd(%rip), %rcx      # 0x72e9
movl $0x37c, %edx            # imm = 0x37C
callq 0x10c0
// File: /workspace/github_c_makefile_star2_O2/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
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8118(%rdi), %rax
cmpb $0x0, (%rax)
je 0x1667
movq 0x8118(%rbx), %rax
movzbl 0x1(%rax), %esi
testl %esi, %esi
je 0x1660
movq 0xa98f(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x11a0
movq 0x8118(%rbx), %rax
movb $0x0, 0x1(%rax)
orb $0x20, 0x6(%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq 0xa96a(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x1080
testb %al, %al
je 0x1633
movzbl %al, %ecx
cmpl $0xff, %ecx
je 0x1633
movq 0x8118(%rbx), %rcx
movb %al, (%rcx)
orb $0x1, 0x6(%rcx)
jmp 0x1633
// File: /workspace/github_c_makefile_star2_O2/hobo0xcc[P]rve/src/cpu.c
// Function: PlicTick
void PlicTick(State *state, bool virtio_int, bool uart_int) {
    uint32_t virtio_irq = VIRTIO_IRQ;
    uint32_t uart_irq = UART_IRQ;
    uint32_t virtio_priority = state->plic->priority[virtio_irq];
    uint32_t uart_priority = state->plic->priority[uart_irq];
    bool virtio_enable = state->plic->enable_bits >> virtio_irq & 1;
    bool uart_enable = state->plic->enable_bits >> uart_irq & 1;

    bool ints[2] = {virtio_int, uart_int};
    uint32_t irqs[2] = {virtio_irq, uart_irq};
    uint32_t priorities[2] = {virtio_priority, uart_priority};
    bool enables[2] = {virtio_enable, uart_enable};

    int priority = 0;
    int irq = 0;
    for (int i = 0; i < 2; i++) {
        // if (ints[i])
        //     printf("irqs[i]: %x, ints[i]: %d, enables[i]: %d, priorities[i]: %d, priority: %d, threshold: %d\n", irqs[i], ints[i], enables[i], priorities[i], priority, state->plic->threshold);
        if (ints[i] && enables[i] && priorities[i] > priority && priorities[i] > state->plic->threshold) {
            irq = irqs[i];
            priority = priorities[i];
        }
    }

    if (irq != 0) {
        // printf("Interrupted: irq: %d, virtio_int: %d\n", irq, virtio_int);
        state->plic->irq = irq;
        if (state->mode == MACHINE) {
            WriteCSR(state, MIP, 9, 9, 1);
        } else if (state->mode == SUPERVISOR) {
            WriteCSR(state, SIP, 9, 9, 1);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x8128(%rdi), %rax
movl 0x4(%rax), %ecx
movl 0x28(%rax), %r8d
movq 0x1008(%rax), %r9
movl %r9d, %r10d
shrb %r10b
andb $0x1, %r10b
shrl $0xa, %r9d
andb $0x1, %r9b
movb %sil, -0x4(%rbp)
movb %dl, -0x3(%rbp)
movabsq $0xa00000001, %rdx      # imm = 0xA00000001
movq %rdx, -0x14(%rbp)
movl %ecx, -0xc(%rbp)
movl %r8d, -0x8(%rbp)
movb %r10b, -0x2(%rbp)
movb %r9b, -0x1(%rbp)
xorl %edx, %edx
xorl %esi, %esi
xorl %ecx, %ecx
cmpq $0x2, %rdx
je 0x174b
cmpb $0x1, -0x4(%rbp,%rdx)
jne 0x1746
cmpb $0x1, -0x2(%rbp,%rdx)
jne 0x1746
movl -0xc(%rbp,%rdx,4), %r8d
cmpl %esi, %r8d
jbe 0x1746
cmpl 0x1010(%rax), %r8d
jbe 0x1746
movl -0x14(%rbp,%rdx,4), %ecx
movl %r8d, %esi
incq %rdx
jmp 0x1718
testl %ecx, %ecx
je 0x1777
movl %ecx, 0x1000(%rax)
movzbl 0x8148(%rdi), %eax
cmpl $0x3, %eax
je 0x176d
cmpl $0x1, %eax
jne 0x1777
movl $0xa28, %eax            # imm = 0xA28
jmp 0x1772
movl $0x1a28, %eax           # imm = 0x1A28
orb $0x2, 0x1(%rdi,%rax)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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:
movq 0x8130(%rdi), %rax
cmpl $0x1234, 0x1c(%rax)     # imm = 0x1234
je 0x17af
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
orb $0x1, 0x20(%rax)
callq 0x17b0
movq 0x8130(%rbx), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r14
pushq %rbx
movq %rdi, %rbx
incq 0x8110(%rdi)
movq (%rdi), %r14
movq %r14, %rsi
callq 0x1a52
movq %rbx, %rdi
movl %eax, %esi
callq 0x1a85
andq $0x0, 0x8008(%rbx)
cmpb $0x1, 0x8138(%rbx)
jne 0x19e9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x135d
movb $0x0, 0x8138(%rbx)
andq $0x0, 0x8140(%rbx)
movq %rbx, %rdi
callq 0x161e
movq %rbx, %rdi
callq 0x1779
movq %rbx, %rdi
callq 0x1694
movq 0x8130(%rbx), %rax
movl 0x20(%rax), %r14d
andl $0x1, %r14d
movq %rbx, %rdi
callq 0x1bc7
movzbl %al, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x16c3
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x1526
testb %al, %al
je 0x1a4d
cmpb $0x1, 0x8138(%rbx)
jne 0x1a4d
movb $0x0, 0x8138(%rbx)
andq $0x0, 0x8140(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %edx, %edx
callq 0x2785
cmpb $0x0, 0x8138(%rbx)
je 0x1a74
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x264e
// File: /workspace/github_c_makefile_star2_O2/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 0x8118(%rdi), %rcx
movb 0x2(%rcx), %al
testb $0x1, %al
je 0x1be4
cmpb $0x0, (%rcx)
je 0x1be4
movb $0x1, %al
movb $0x4, %dl
jmp 0x1bf2
testb $0x2, %al
je 0x1bee
cmpb $0x0, 0x1(%rcx)
je 0x1bf7
movb $0xf, %dl
xorl %eax, %eax
movb %dl, 0x3(%rcx)
popq %rbp
retq
movb $0x1, %al
movb $0x2, %dl
jmp 0x1bf2
// File: /workspace/github_c_makefile_star2_O2/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
movq 0x8118(%rdi), %rax
movb 0x4(%rax), %cl
testq %rsi, %rsi
sete %dil
testb %cl, %cl
setns %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x1c6a
movb %dl, 0x1(%rax)
andb $-0x21, 0x6(%rax)
jmp 0x1c83
testb %cl, %cl
setns %cl
cmpq $0x1, %rsi
sete %dil
andb %cl, %dil
cmpb $0x1, %dil
jne 0x1c85
movb %dl, 0x2(%rax)
popq %rbp
retq
cmpq $0x7, %rsi
je 0x1ca1
cmpq $0x4, %rsi
je 0x1c9c
cmpq $0x3, %rsi
jne 0x1c83
movb %dl, 0x4(%rax)
jmp 0x1c83
movb %dl, 0x5(%rax)
jmp 0x1c83
movb %dl, 0x8(%rax)
jmp 0x1c83
// File: /workspace/github_c_makefile_star2_O2/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 0x8118(%rdi), %rcx
movb 0x4(%rcx), %al
testq %rsi, %rsi
sete %dl
testb %al, %al
setns %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x1cd4
movb (%rcx), %al
movb $0x0, (%rcx)
andb $-0x2, 0x6(%rcx)
jmp 0x1ced
testb %al, %al
setns %dl
cmpq $0x1, %rsi
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x1cef
movb 0x2(%rcx), %al
popq %rbp
retq
addq $-0x2, %rsi
cmpq $0x5, %rsi
ja 0x1d22
leaq 0x5378(%rip), %rdx      # 0x7078
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movb 0x3(%rcx), %al
jmp 0x1ced
movb 0x7(%rcx), %al
jmp 0x1ced
movb 0x5(%rcx), %al
jmp 0x1ced
movb 0x6(%rcx), %al
jmp 0x1ced
movb 0x8(%rcx), %al
jmp 0x1ced
xorl %eax, %eax
jmp 0x1ced
// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rcx
cmpq $0x3, %rsi
ja 0x1d59
shll $0x3, %ecx
movl $0xff, %eax
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8120(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl (%rcx), %eax
orl %edx, %eax
movl %eax, (%rcx)
jmp 0x1dce
movq %rcx, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1da0
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1dce
movq 0x8120(%rdi), %rax
shll $0x3, %ecx
movl $0xff, %esi
shlq %cl, %rsi
notl %esi
orq $-0x100, %rsi
andq 0x8(%rax), %rsi
movzbl %dl, %edx
shll %cl, %edx
movslq %edx, %rcx
orq %rsi, %rcx
movq %rcx, 0x8(%rax)
jmp 0x1dce
movq 0x8120(%rdi), %rax
shll $0x3, %ecx
movl $0xff, %esi
shlq %cl, %rsi
notl %esi
orq $-0x100, %rsi
andq 0x10(%rax), %rsi
movzbl %dl, %edx
shll %cl, %edx
movslq %edx, %rcx
orq %rsi, %rcx
movq %rcx, 0x10(%rax)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
cmpq $0x3, %rsi
ja 0x1de5
movq 0x8120(%rdi), %rax
movl (%rax), %eax
jmp 0x1e14
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1e09
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1e1e
movq 0x8120(%rdi), %rax
movq 0x8(%rax), %rax
jmp 0x1e14
movq 0x8120(%rdi), %rax
movq 0x10(%rax), %rax
shll $0x3, %esi
movl %esi, %ecx
shrq %cl, %rax
popq %rbp
retq
xorl %eax, %eax
jmp 0x1e1c
// File: /workspace/github_c_makefile_star2_O2/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
leaq -0x4(%rsi), %rax
cmpq $0xff7, %rax            # imm = 0xFF7
ja 0x1e6d
movq %rsi, %rax
shll $0x3, %esi
movzbl %dl, %edx
movl %esi, %ecx
shll %cl, %edx
movl $0xff, %r8d
shll %cl, %r8d
movq 0x8128(%rdi), %rcx
andq $-0x4, %rax
notl %r8d
orl $0xffffff00, %r8d       # imm = 0xFFFFFF00
andl (%rcx,%rax), %r8d
orl %edx, %r8d
movl %r8d, (%rcx,%rax)
jmp 0x1f2c
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x1eb4
movq 0x8128(%rdi), %rax
shll $0x3, %esi
movl $0xff, %edi
movl %esi, %ecx
shlq %cl, %rdi
notl %edi
orq $-0x100, %rdi
andq 0x1008(%rax), %rdi
movzbl %dl, %edx
shll %cl, %edx
movslq %edx, %rcx
orq %rdi, %rcx
movq %rcx, 0x1008(%rax)
jmp 0x1f2c
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x1efb
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x1f2c
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movzbl %dl, %edx
shll %cl, %edx
movq 0x8128(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x1010(%rcx), %eax
orl %edx, %eax
movl %eax, 0x1010(%rcx)
jmp 0x1f2c
shll $0x3, %esi
leal -0x20(%rsi), %ecx
movl $0xff, %eax
shlq %cl, %rax
movzbl %dl, %edx
movl %esi, %ecx
shll %cl, %edx
movq 0x8128(%rdi), %rcx
notl %eax
orl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x1000(%rcx), %eax
orl %edx, %eax
movl %eax, 0x1000(%rcx)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
leaq -0x4(%rsi), %rax
cmpq $0xff7, %rax            # imm = 0xFF7
ja 0x1f55
movq 0x8128(%rdi), %rcx
andq $-0x4, %rax
movl (%rcx,%rax), %eax
shll $0x3, %esi
andb $0x18, %sil
jmp 0x1f9b
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x1f74
movq 0x8128(%rdi), %rax
movq 0x1008(%rax), %rax
jmp 0x1f98
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x1fa2
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x1fb8
movq 0x8128(%rdi), %rax
movl 0x1010(%rax), %eax
shll $0x3, %esi
movl %esi, %ecx
shrq %cl, %rax
popq %rbp
retq
movq 0x8128(%rdi), %rax
movl 0x1000(%rax), %eax
shll $0x3, %esi
addb $-0x20, %sil
jmp 0x1f9b
xorl %eax, %eax
jmp 0x1fa0
// File: /workspace/github_c_makefile_star2_O2/hobo0xcc[P]rve/src/cpu.c
// Function: VirtioRead
uint8_t VirtioRead(State *state, uint64_t offset) {
    if (offset >= VIRTIO_MAGIC_VALUE_BASE && offset < VIRTIO_MAGIC_VALUE_BASE + 4) {
        return ReadRange8(0x74726976, offset - VIRTIO_MAGIC_VALUE_BASE);
    } else if (offset >= VIRTIO_DEVICE_VERSION_BASE && offset < VIRTIO_DEVICE_VERSION_BASE + 4) {
        return ReadRange8(0x01, offset - VIRTIO_DEVICE_VERSION_BASE);
    } else if (offset >= VIRTIO_DEVICE_ID_BASE && offset < VIRTIO_DEVICE_ID_BASE + 4) {
        return ReadRange8(0x02, offset - VIRTIO_DEVICE_ID_BASE);
    } else if (offset >= VIRTIO_VENDOR_ID_BASE && offset < VIRTIO_VENDOR_ID_BASE + 4) {
        return ReadRange8(0x554d4551, offset - VIRTIO_VENDOR_ID_BASE);
    } else if (offset >= VIRTIO_HOST_FEATURES_BASE && offset < VIRTIO_HOST_FEATURES_BASE + 4) {
        return ReadRange8(state->virtio->host_features, offset - VIRTIO_HOST_FEATURES_BASE);
    } else if (offset >= VIRTIO_QUEUE_NUM_MAX_BASE && offset < VIRTIO_QUEUE_NUM_MAX_BASE + 4) {
        return ReadRange8(0x2000, offset - VIRTIO_QUEUE_NUM_MAX_BASE);
    } else if (offset >= VIRTIO_QUEUE_PFN_BASE && offset < VIRTIO_QUEUE_PFN_BASE + 4) {
        return ReadRange8(state->virtio->queue_pfn, offset - VIRTIO_QUEUE_PFN_BASE);
    } else if (offset >= VIRTIO_INTERRUPT_STATUS_BASE && offset < VIRTIO_INTERRUPT_STATUS_BASE + 4) {
        return ReadRange8(state->virtio->interrupt_status, offset - VIRTIO_INTERRUPT_STATUS_BASE);
    } else if (offset >= VIRTIO_STATUS_BASE && offset < VIRTIO_STATUS_BASE + 4) {
        return ReadRange8(state->virtio->status, offset - VIRTIO_STATUS_BASE);
    } else {
        return 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpq $0x3, %rsi
ja 0x231f
shll $0x3, %esi
movl $0x74726976, %eax       # imm = 0x74726976
movl %esi, %ecx
jmp 0x2335
cmpq $0x7, %rsi
ja 0x233a
leaq -0x20(,%rsi,8), %rcx
xorl %eax, %eax
testq %rcx, %rcx
sete %al
shrq %cl, %rax
popq %rbp
retq
cmpq $0xb, %rsi
ja 0x234f
shll $0x3, %esi
movabsq $0x2, %rax
jmp 0x231b
cmpq $0xf, %rsi
ja 0x2363
shll $0x3, %esi
addb $-0x60, %sil
movl $0x554d4551, %eax       # imm = 0x554D4551
jmp 0x231b
cmpq $0x13, %rsi
ja 0x2377
movq 0x8130(%rdi), %rax
movl (%rax), %eax
shll $0x3, %esi
jmp 0x231b
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x70, %rax
je 0x23c7
cmpq $0x40, %rax
je 0x23af
cmpq $0x60, %rax
je 0x23bb
cmpq $0x34, %rax
jne 0x23d3
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
andq %rax, %rsi
cmpq $0x35, %rsi
sete %al
shlb $0x5, %al
jmp 0x2338
movq 0x8130(%rdi), %rax
movl 0x18(%rax), %eax
jmp 0x2372
movq 0x8130(%rdi), %rax
movl 0x20(%rax), %eax
jmp 0x2372
movq 0x8130(%rdi), %rax
movl 0x28(%rax), %eax
jmp 0x2372
xorl %eax, %eax
jmp 0x2338
// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rax
andq $-0x100, %rax
cmpq $0x10000000, %rax       # imm = 0x10000000
jne 0x23ff
addq $-0x10000000, %rsi      # imm = 0xF0000000
movzbl %dl, %edx
popq %rbp
jmp 0x1c3d
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x2420
addq $-0x2000000, %rsi       # imm = 0xFE000000
movzbl %dl, %edx
popq %rbp
jmp 0x1d26
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x2441
addq $-0xc000000, %rsi       # imm = 0xF4000000
movzbl %dl, %edx
popq %rbp
jmp 0x1e22
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x2462
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
movzbl %dl, %edx
popq %rbp
jmp 0x214a
movq %rsi, %rax
shrq $0x1f, %rax
je 0x247b
movq 0x8108(%rdi), %rax
movb %dl, -0x80000000(%rax,%rsi)
jmp 0x248d
movb $0x1, 0x8138(%rdi)
movq $0xf, 0x8140(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
xorl %r12d, %r12d
cmpq $0x10, %r12
je 0x24c9
movl %ebx, %eax
movl %r12d, %ecx
shrl %cl, %eax
movzbl %al, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x23da
addq $0x8, %r12
incq %r14
jmp 0x24a5
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
xorl %r12d, %r12d
cmpq $0x20, %r12
je 0x250c
movl %ebx, %eax
movl %r12d, %ecx
shrl %cl, %eax
movzbl %al, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x23da
addq $0x8, %r12
incq %r14
jmp 0x24e8
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
xorl %r12d, %r12d
cmpq $0x40, %r12
je 0x2552
movq %rbx, %rax
movl %r12d, %ecx
shrq %cl, %rax
movzbl %al, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x23da
addq $0x8, %r12
incq %r14
jmp 0x252c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rax
andq $-0x100, %rax
cmpq $0x10000000, %rax       # imm = 0x10000000
jne 0x257d
addq $-0x10000000, %rsi      # imm = 0xF0000000
popq %rbp
jmp 0x1ca6
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x259b
addq $-0x2000000, %rsi       # imm = 0xFE000000
popq %rbp
jmp 0x1dd0
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x25b9
addq $-0xc000000, %rsi       # imm = 0xF4000000
popq %rbp
jmp 0x1f2e
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x25d7
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
popq %rbp
jmp 0x2309
movq %rsi, %rax
shrq $0x1f, %rax
je 0x25f0
movq 0x8108(%rdi), %rax
movb -0x80000000(%rax,%rsi), %al
jmp 0x2604
movb $0x1, 0x8138(%rdi)
movq $0xd, 0x8140(%rdi)
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x10, %r15
je 0x2642
movq %r14, %rdi
movq %rbx, %rsi
callq 0x255b
movzbl %al, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, %r12d
addq $0x8, %r15
incq %rbx
jmp 0x261d
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x20, %r15
je 0x268a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x255b
movzbl %al, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, %r12d
addq $0x8, %r15
incq %rbx
jmp 0x2665
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x40, %r15
je 0x26d3
movq %r14, %rdi
movq %rbx, %rsi
callq 0x255b
movzbl %al, %eax
movl %r15d, %ecx
shlq %cl, %rax
orq %rax, %r12
addq $0x8, %r15
incq %rbx
jmp 0x26ad
movq %r12, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
movb $0x1, 0x8138(%rdi)
cmpl $0x2, %esi
je 0x2712
cmpl $0x1, %esi
je 0x2705
testl %esi, %esi
jne 0x271f
movq $0x1, 0x8140(%rdi)
jmp 0x271d
movq $0x5, 0x8140(%rdi)
jmp 0x271d
movq $0x7, 0x8140(%rdi)
popq %rbp
retq
movzbl %sil, %esi
leaq 0x4b65(%rip), %rdi      # 0x728f
xorl %eax, %eax
popq %rbp
jmp 0x5ca8
// File: /workspace/github_c_makefile_star2_O2/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
movb $0x1, 0x8138(%rdi)
cmpl $0x2, %esi
je 0x2765
cmpl $0x1, %esi
je 0x2758
testl %esi, %esi
jne 0x2772
movq $0xc, 0x8140(%rdi)
jmp 0x2770
movq $0xd, 0x8140(%rdi)
jmp 0x2770
movq $0xf, 0x8140(%rdi)
popq %rbp
retq
movzbl %sil, %esi
leaq 0x4b12(%rip), %rdi      # 0x728f
xorl %eax, %eax
popq %rbp
jmp 0x5ca8