LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/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
leaq 0x52ff(%rip), %rdi      # 0xa230
callq 0x2200
movq $-0x87, %r13
leaq 0x14e6(%rip), %r14      # 0x642a
leaq 0x10b9(%rip), %r15      # 0x6004
leaq 0x2138(%rip), %r12      # 0x708a
cmpb $0x0, 0x95(%rbx,%r13)
je 0x4fc3
movzbl 0x1a3(%rbx,%r13,2), %edx
movzbl 0x1a4(%rbx,%r13,2), %esi
incl %esi
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20b0
movzbl 0x95(%rbx,%r13), %eax
decl %eax
cmpl $0x5, %eax
ja 0x4fc3
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x2b, %edi
jmp 0x4fbe
movq %r12, %rdi
jmp 0x4fa9
leaq 0x20dd(%rip), %rdi      # 0x7086
xorl %eax, %eax
callq 0x20b0
jmp 0x4fc3
movl $0x2a, %edi
jmp 0x4fbe
movl $0x2e, %edi
callq 0x2040
incq %r13
jne 0x4f52
movq 0x4ff9(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2160
leaq 0x5252(%rip), %rdi      # 0xa230
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
// File: /workspace/github_c_makefile_star2_O1/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 0x549b(%rip), %r14      # 0xa4b0
leaq 0x2072(%rip), %rsi      # 0x708e
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 0x2073(%rip), %r15      # 0x70bd
xorl %r13d, %r13d
movslq %r12d, %r12
leaq (%r14,%r12), %rdi
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
cmpq $0x5, %r13
jne 0x504d
movslq %r12d, %r12
movw $0xa, (%r12,%r14)
movl $0x3a736d, 0x4(%r12,%r14) # imm = 0x3A736D
movl $0x6d657469, 0x1(%r12,%r14) # imm = 0x6D657469
addl $0x7, %r12d
movl $0x4b, %r13d
leaq 0x202b(%rip), %r15      # 0x70ce
movslq %r12d, %r12
leaq (%r14,%r12), %rdi
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
cmpq $0xd2, %r13
jne 0x50a3
movslq %r12d, %rax
movw $0xa, (%rax,%r14)
addl $0xfff00001, %eax       # imm = 0xFFF00001
cmpl $0xfff00000, %eax       # imm = 0xFFF00000
jb 0x5119
movq 0x506f(%rip), %rsi      # 0xa160
leaq 0x1ff0(%rip), %rdi      # 0x70e8
leaq 0x53b1(%rip), %rcx      # 0xa4b0
movl $0x4c9, %edx            # imm = 0x4C9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27b3
callq 0x234d
// File: /workspace/github_c_makefile_star2_O1/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 0x5032(%rip), %rsi      # 0xa160
leaq 0x18b5(%rip), %rdi      # 0x69ea
leaq 0x1fc4(%rip), %rcx      # 0x7100
movl $0x4cd, %edx            # imm = 0x4CD
xorl %eax, %eax
callq 0x27b3
cmpl $0x3, 0x501d(%rip)      # 0xa16c
jne 0x51bd
movq %rbx, %rdi
callq 0x4ff1
movzbl 0x3(%rbx), %eax
movl %eax, 0x5175(%rip)      # 0xa2d8
movzbl 0x1(%rbx), %eax
movl %eax, 0x5167(%rip)      # 0xa2d4
movq %rbx, %rdi
callq 0x4d5b
movq %rbx, %rdi
callq 0x4e8a
movq %rbx, %rdi
callq 0x4f19
movl 0x4fe1(%rip), %eax      # 0xa16c
movq 0x4fce(%rip), %rdx      # 0xa160
movl 0x513c(%rip), %ecx      # 0xa2d4
movl 0x5139(%rip), %r8d      # 0xa2d8
leaq 0x4a8a(%rip), %rsi      # 0x9c30
movq (%rsi,%rax,8), %r9
leaq 0x133f(%rip), %rsi      # 0x64f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0x28a9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x4dd5(%rip), %rsi      # 0xa160
leaq 0x1ea1(%rip), %rdi      # 0x7233
movl $0x524, %edx            # imm = 0x524
xorl %eax, %eax
callq 0x27b3
movl $0x1a3, %r13d           # imm = 0x1A3
leaq 0x1ea6(%rip), %rbx      # 0x7251
movl $0x98001, %r15d         # imm = 0x98001
movl $0x67b0, %r12d          # imm = 0x67B0
xorl %r14d, %r14d
movl 0x4d98(%rip), %edi      # 0xa158
imulq $0x1a3, %r14, %rax      # imm = 0x1A3
leaq (%rax,%rbp), %rsi
addq $-0x1cb, %rsi           # imm = 0xFE35
movl $0x1a3, %edx            # imm = 0x1A3
subq %r14, %rdx
xorl %ecx, %ecx
callq 0x2030
addq %rax, %r14
cmpq %r13, %r14
jb 0x53ba
movq 0x4d70(%rip), %rsi      # 0xa160
movzbl -0x1cb(%rbp), %eax
leaq 0x4702(%rip), %rcx      # 0x9b00
movq (%rcx,%rax,8), %rcx
movq %rbx, %rdi
movl $0x527, %edx            # imm = 0x527
xorl %eax, %eax
callq 0x27b3
movzbl -0x1cb(%rbp), %eax
btq %rax, %r15
jb 0x546a
movq 0x4d3b(%rip), %rsi      # 0xa160
leaq 0x1e48(%rip), %rdi      # 0x7274
movl $0x529, %edx            # imm = 0x529
xorl %eax, %eax
callq 0x27b3
movzbl -0x1cb(%rbp), %eax
leaq -0x1cb(%rbp), %rdi
leaq 0x4863(%rip), %rcx      # 0x9cb0
callq *(%rcx,%rax,8)
movq 0x4d09(%rip), %rsi      # 0xa160
leaq 0x1e37(%rip), %rdi      # 0x7295
movl $0x52b, %edx            # imm = 0x52B
xorl %eax, %eax
callq 0x27b3
movzbl -0x1cb(%rbp), %eax
movl $0x0, %r14d
cmpl $0xe, %eax
ja 0x53ba
btl %eax, %r12d
movl $0x0, %r14d
jae 0x53ba
movl %eax, 0x4cd2(%rip)      # 0xa168
jmp 0x53b7
// File: /workspace/github_c_makefile_star2_O1/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
pushq %rbx
pushq %rax
movq 0x4c8d(%rip), %rsi      # 0xa160
leaq 0x1e2c(%rip), %rdi      # 0x7306
movl $0x545, %edx            # imm = 0x545
xorl %eax, %eax
callq 0x27b3
callq 0x24c1
movl %eax, 0x4c67(%rip)      # 0xa158
leaq 0x1e44(%rip), %rdi      # 0x733c
callq 0x2090
leaq -0x10(%rbp), %rbx
movl $0x5413, %esi           # imm = 0x5413
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x20d0
movzwl 0x2(%rbx), %eax
movl %eax, 0x4d50(%rip)      # 0xa26c
leaq 0x4d35(%rip), %rdi      # 0xa258
callq 0x2dfb
leaq 0xf04(%rip), %rdi       # 0x6433
xorl %eax, %eax
callq 0x20b0
callq 0x366e
callq 0x549b
callq 0x40cf
// File: /workspace/github_c_makefile_star2_O1/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 0x18ee(%rip), %rdi      # 0x4c58
movl $0x1, %esi
callq 0x2c47
movq %rax, (%rsp)
leaq 0x192a(%rip), %rdi      # 0x4ca9
callq 0x1070
leaq 0x18d8(%rip), %r14      # 0x4c63
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x2784
movq %rax, %r15
callq 0x11a0
movslq %eax, %rbp
imulq $0x431bde83, %rbp, %rax # imm = 0x431BDE83
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x32, %rax
addl %ecx, %eax
imull $0xf4240, %eax, %eax    # imm = 0xF4240
subl %eax, %ebp
movslq %ebp, %r12
xorl %ebx, %ebx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2793
incq %rbx
cmpq $0x64, %rbx
jne 0x33c1
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2aa7
addl $0xfffffc18, %ebp       # imm = 0xFFFFFC18
cmpl $0xa, %ebp
ja 0x33fc
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x10a0
incq %r13
cmpq $0xf4240, %r13          # imm = 0xF4240
jne 0x338e
leaq 0x18da(%rip), %rdi      # 0x4ce9
callq 0x1070
movl $0x3e8, %edx            # imm = 0x3E8
movl $0x3f2, %ecx            # imm = 0x3F2
movl $0x64, %r8d
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x2831
movq %rax, %r14
movq %rax, %rdi
callq 0x2798
testq %rax, %rax
je 0x349f
movq %rax, %r15
leaq 0xe6e(%rip), %r13       # 0x42b7
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x279c
movq %rax, %r12
leaq 0x1829(%rip), %rdi      # 0x4c89
movq %rbp, %rsi
xorl %eax, %eax
callq 0x10a0
xorl %ebx, %ebx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x278e
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x10a0
incq %rbx
cmpq $0xa, %rbx
jne 0x346c
movl $0xa, %edi
callq 0x1040
incq %rbp
cmpq %r15, %rbp
jne 0x344b
movq %r14, %rdi
callq 0x27ca
leaq 0x1881(%rip), %rdi      # 0x4d2f
callq 0x1070
movq (%rsp), %rdi
callq 0x3152
leaq 0x1885(%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_O1/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 0x6e26(%rip), %eax      # 0x80c8
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, 0x6e0b(%rip)      # 0x80c8
retq
// File: /workspace/github_c_makefile_star2_O1/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, %r15
cvtsi2sd %edx, %xmm0
callq 0x26fd
leaq 0xc(%rsp), %r12
movl %eax, (%r12)
movslq %eax, %rdi
callq 0x1120
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebp, %ecx
movl $0x1, %r8d
callq 0x364c
testq %r14, %r14
je 0x183a
movq %r14, %rdi
callq 0x1070
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1100
jmp 0x1851
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x1150
movq %r14, %rdi
callq 0x1110
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O1/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 0x1326
leaq 0x6f35(%rip), %rdi      # 0x8254
xorl %eax, %eax
callq 0x6b70
subl %ebx, %r15d
incl %r15d
movq $-0x1, %rdx
movq $-0x1, %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_O1/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 0x1408
xorl %edx, %edx
testq %rcx, %rcx
setns %dl
xorl $0x303, %edx            # imm = 0x303
movq 0x8(%rdi,%rdx,8), %rdx
btq %rcx, %rdx
jae 0x1408
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)
movq $0x0, 0xa20(%rdi)
movq %rdx, %rcx
andq $-0x23, %rcx
shll $0x4, %edx
andl $0x20, %edx
orq %rcx, %rdx
movq %rdx, 0x808(%rdi)
testq %rax, %rax
je 0x146c
orq $0x100, %rdx            # imm = 0x100
jmp 0x1473
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)
movq $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 0x147a
andq $-0x103, %rdx           # imm = 0xFEFD
movq %rdx, 0x808(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x1523
movzbl %cl, %ecx
movzbl %dl, %eax
subl %eax, %ecx
incl %ecx
movq $-0x1, %rax
movq $-0x1, %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 0x6d9c(%rip), %rdi      # 0x82ca
leaq 0x6daa(%rip), %rsi      # 0x82df
leaq 0x6dad(%rip), %rcx      # 0x82e9
movl $0x37c, %edx            # imm = 0x37C
callq 0x10c0
// File: /workspace/github_c_makefile_star2_O1/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 0x169d
movq 0x8118(%rbx), %rax
movzbl 0x1(%rax), %esi
testl %esi, %esi
je 0x1696
movq 0xb959(%rip), %rax      # 0xcfd8
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 0xb934(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
callq 0x1080
testb %al, %al
je 0x1669
movzbl %al, %ecx
cmpl $0xff, %ecx
je 0x1669
movq 0x8118(%rbx), %rcx
movb %al, (%rcx)
orb $0x1, 0x6(%rcx)
jmp 0x1669
// File: /workspace/github_c_makefile_star2_O1/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
movq 0x8120(%rdi), %rcx
incq 0x10(%rcx)
movq 0x1a28(%rdi), %rax
movq %rax, %rdx
andq $-0x9, %rdx
movq %rdx, 0x1a28(%rdi)
testb $0x1, (%rcx)
je 0x16fe
orq $0x8, %rax
movq %rax, 0x1a28(%rdi)
andb $0x7f, 0x1a28(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 %ecx, %ecx
xorl %esi, %esi
cmpb $0x1, -0x4(%rbp,%rdx)
jne 0x1784
cmpb $0x1, -0x2(%rbp,%rdx)
jne 0x1784
movl -0xc(%rbp,%rdx,4), %r8d
cmpl %esi, %r8d
jbe 0x1784
cmpl 0x1010(%rax), %r8d
jbe 0x1784
movl -0x14(%rbp,%rdx,4), %ecx
movl %r8d, %esi
incq %rdx
cmpq $0x1, %rdx
je 0x175c
testl %ecx, %ecx
je 0x17b9
movl %ecx, 0x1000(%rax)
movzbl 0x8148(%rdi), %eax
cmpl $0x3, %eax
je 0x17af
cmpl $0x1, %eax
jne 0x17b9
movl $0xa28, %eax            # imm = 0xA28
jmp 0x17b4
movl $0x1a28, %eax           # imm = 0x1A28
orb $0x2, 0x1(%rdi,%rax)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x17f1
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
orb $0x1, 0x20(%rax)
callq 0x17f2
movq 0x8130(%rbx), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x1af8
movq %rbx, %rdi
movl %eax, %esi
callq 0x1b51
movq $0x0, 0x8008(%rbx)
cmpb $0x1, 0x8138(%rbx)
jne 0x1a3b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1361
movb $0x0, 0x8138(%rbx)
movq $0x0, 0x8140(%rbx)
movq %rbx, %rdi
callq 0x1654
movq 0x8130(%rbx), %rax
cmpl $0x1234, 0x1c(%rax)     # imm = 0x1234
je 0x1a6d
orb $0x1, 0x20(%rax)
movq %rbx, %rdi
callq 0x17f2
movq 0x8130(%rbx), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
movq 0x8120(%rbx), %rcx
incq 0x10(%rcx)
movq 0x1a28(%rbx), %rax
movq %rax, %rdx
andq $-0x9, %rdx
movq %rdx, 0x1a28(%rbx)
testb $0x1, (%rcx)
je 0x1a9d
orq $0x8, %rax
movq %rax, 0x1a28(%rbx)
andb $0x7f, 0x1a28(%rbx)
movq 0x8130(%rbx), %rax
movl 0x20(%rax), %r14d
andl $0x1, %r14d
movq %rbx, %rdi
callq 0x1d6f
movzbl %al, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1707
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x1546
testb %al, %al
je 0x1af3
cmpb $0x1, 0x8138(%rbx)
jne 0x1af3
movb $0x0, 0x8138(%rbx)
movq $0x0, 0x8140(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x2a65
cmpb $0x0, 0x8138(%rbx)
jne 0x1b45
movq %rax, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2841
movzbl %al, %eax
movl %r12d, %ecx
shll %cl, %eax
orl %eax, %r14d
addq $0x8, %r12
incq %r15
cmpq $0x20, %r12
jne 0x1b22
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x1d8c
cmpb $0x0, (%rcx)
je 0x1d8c
movb $0x1, %al
movb $0x4, %dl
jmp 0x1d9a
testb $0x2, %al
je 0x1d96
cmpb $0x0, 0x1(%rcx)
je 0x1d9f
movb $0xf, %dl
xorl %eax, %eax
movb %dl, 0x3(%rcx)
popq %rbp
retq
movb $0x1, %al
movb $0x2, %dl
jmp 0x1d9a
// File: /workspace/github_c_makefile_star2_O1/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
leal (,%rdx,8), %ecx
movl $0xff, %eax
shlq %cl, %rax
andl %edi, %eax
movzbl %al, %edx
shll %cl, %esi
xorq %rdi, %rdx
movslq %esi, %rax
orq %rdx, %rax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x1e12
movb %dl, 0x1(%rax)
andb $-0x21, 0x6(%rax)
jmp 0x1e2b
testb %cl, %cl
setns %cl
cmpq $0x1, %rsi
sete %dil
andb %cl, %dil
cmpb $0x1, %dil
jne 0x1e2d
movb %dl, 0x2(%rax)
popq %rbp
retq
cmpq $0x7, %rsi
je 0x1e49
cmpq $0x4, %rsi
je 0x1e44
cmpq $0x3, %rsi
jne 0x1e2b
movb %dl, 0x4(%rax)
jmp 0x1e2b
movb %dl, 0x5(%rax)
jmp 0x1e2b
movb %dl, 0x8(%rax)
jmp 0x1e2b
// File: /workspace/github_c_makefile_star2_O1/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 0x1e7c
movb (%rcx), %al
movb $0x0, (%rcx)
andb $-0x2, 0x6(%rcx)
jmp 0x1e95
testb %al, %al
setns %dl
cmpq $0x1, %rsi
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x1e97
movb 0x2(%rcx), %al
popq %rbp
retq
addq $-0x2, %rsi
cmpq $0x5, %rsi
ja 0x1eca
leaq 0x61d0(%rip), %rdx      # 0x8078
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movb 0x3(%rcx), %al
jmp 0x1e95
movb 0x7(%rcx), %al
jmp 0x1e95
movb 0x5(%rcx), %al
jmp 0x1e95
movb 0x6(%rcx), %al
jmp 0x1e95
movb 0x8(%rcx), %al
jmp 0x1e95
xorl %eax, %eax
jmp 0x1e95
// File: /workspace/github_c_makefile_star2_O1/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 0x1f01
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 0x1f76
movq %rcx, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1f48
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1f76
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 0x1f76
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_O1/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
movq %rsi, %rcx
cmpq $0x3, %rsi
ja 0x1f93
movq 0x8120(%rdi), %rax
movl (%rax), %eax
shll $0x3, %ecx
jmp 0x1fd8
movq %rcx, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1fc2
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1fdd
shll $0x3, %ecx
movl $0xff, %eax
shlq %cl, %rax
movq 0x8120(%rdi), %rdx
andq 0x8(%rdx), %rax
jmp 0x1fd8
shll $0x3, %ecx
movl $0xff, %eax
shlq %cl, %rax
movq 0x8120(%rdi), %rdx
andq 0x10(%rdx), %rax
shrq %cl, %rax
popq %rbp
retq
xorl %eax, %eax
jmp 0x1fdb
// File: /workspace/github_c_makefile_star2_O1/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 0x202c
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 0x20eb
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x2073
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 0x20eb
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x20ba
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x20eb
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 0x20eb
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_O1/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
movq %rsi, %rcx
leaq -0x4(%rsi), %rax
cmpq $0xff7, %rax            # imm = 0xFF7
ja 0x2116
movq 0x8128(%rdi), %rdx
andq $-0x4, %rax
movl (%rdx,%rax), %eax
shll $0x3, %ecx
andb $0x18, %cl
jmp 0x2184
movq %rcx, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x2138
movq 0x8128(%rdi), %rax
movq 0x1008(%rax), %rax
shll $0x3, %ecx
jmp 0x2184
movq %rcx, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x2169
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x2189
shll $0x3, %ecx
movl $0xff, %eax
shlq %cl, %rax
movq 0x8128(%rdi), %rdx
andl 0x1010(%rdx), %eax
jmp 0x2184
shll $0x3, %ecx
addb $-0x20, %cl
movl $0xff, %eax
shlq %cl, %rax
movq 0x8128(%rdi), %rdx
andl 0x1000(%rdx), %eax
shrq %cl, %rax
popq %rbp
retq
xorl %eax, %eax
jmp 0x2187
// File: /workspace/github_c_makefile_star2_O1/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 0x25c1
shll $0x3, %esi
movl $0x74726976, %eax       # imm = 0x74726976
movl %esi, %ecx
jmp 0x260d
cmpq $0x7, %rsi
ja 0x25d9
leaq -0x20(,%rsi,8), %rcx
xorl %eax, %eax
testq %rcx, %rcx
sete %al
jmp 0x260d
cmpq $0xb, %rsi
ja 0x25f1
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
andl $0x2, %eax
jmp 0x260d
cmpq $0xf, %rsi
ja 0x2612
shll $0x3, %esi
addb $-0x60, %sil
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
andl $0x554d4551, %eax       # imm = 0x554D4551
shrq %cl, %rax
popq %rbp
retq
cmpq $0x13, %rsi
ja 0x2630
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movq 0x8130(%rdi), %rcx
andl (%rcx), %eax
jmp 0x25bd
movq %rsi, %rcx
andq $-0x4, %rcx
xorl %eax, %eax
cmpq $0x5f, %rcx
jg 0x2667
cmpq $0x34, %rcx
je 0x268f
cmpq $0x40, %rcx
jne 0x2610
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movq 0x8130(%rdi), %rcx
andl 0x18(%rcx), %eax
jmp 0x25bd
cmpq $0x60, %rcx
je 0x26aa
cmpq $0x70, %rcx
jne 0x2610
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movq 0x8130(%rdi), %rcx
andl 0x28(%rcx), %eax
jmp 0x25bd
shll $0x3, %esi
addb $0x60, %sil
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
andl $0x2000, %eax           # imm = 0x2000
jmp 0x260d
shll $0x3, %esi
movl $0xff, %eax
movl %esi, %ecx
shlq %cl, %rax
movq 0x8130(%rdi), %rcx
andl 0x20(%rcx), %eax
jmp 0x25bd
// File: /workspace/github_c_makefile_star2_O1/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 0x26eb
addq $-0x10000000, %rsi      # imm = 0xF0000000
movzbl %dl, %edx
popq %rbp
jmp 0x1de5
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x270c
addq $-0x2000000, %rsi       # imm = 0xFE000000
movzbl %dl, %edx
popq %rbp
jmp 0x1ece
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x272d
addq $-0xc000000, %rsi       # imm = 0xF4000000
movzbl %dl, %edx
popq %rbp
jmp 0x1fe1
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x274e
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
movzbl %dl, %edx
popq %rbp
jmp 0x23c1
movq %rsi, %rax
shrq $0x1f, %rax
je 0x2767
movq 0x8108(%rdi), %rax
movb %dl, -0x80000000(%rax,%rsi)
jmp 0x2779
movb $0x1, 0x8138(%rdi)
movq $0xf, 0x8140(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x2863
addq $-0x10000000, %rsi      # imm = 0xF0000000
popq %rbp
jmp 0x1e4e
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x2881
addq $-0x2000000, %rsi       # imm = 0xFE000000
popq %rbp
jmp 0x1f78
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x289f
addq $-0xc000000, %rsi       # imm = 0xF4000000
popq %rbp
jmp 0x20ed
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x28bd
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
popq %rbp
jmp 0x25ab
movq %rsi, %rax
shrq $0x1f, %rax
je 0x28d6
movq 0x8108(%rdi), %rax
movb -0x80000000(%rax,%rsi), %al
jmp 0x28ea
movb $0x1, 0x8138(%rdi)
movq $0xd, 0x8140(%rdi)
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2841
movzbl %al, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, %r12d
addq $0x8, %r15
incq %rbx
cmpq $0x8, %r15
je 0x2903
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2841
movzbl %al, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, %r12d
addq $0x8, %r15
incq %rbx
cmpq $0x20, %r15
jne 0x2949
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2841
movzbl %al, %eax
movl %r15d, %ecx
shlq %cl, %rax
orq %rax, %r12
incq %rbx
addq $0x8, %r15
cmpq $0x40, %r15
jne 0x298f
movq %r12, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x29f2
cmpl $0x1, %esi
je 0x29e5
testl %esi, %esi
jne 0x29ff
movq $0x1, 0x8140(%rdi)
jmp 0x29fd
movq $0x5, 0x8140(%rdi)
jmp 0x29fd
movq $0x7, 0x8140(%rdi)
popq %rbp
retq
movzbl %sil, %esi
leaq 0x5885(%rip), %rdi      # 0x828f
xorl %eax, %eax
popq %rbp
jmp 0x6b70