LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/wierton[P]socket-based-naive-game/client.c
// Function: flip_old_items
void flip_old_items(server_message_t *psm) {
	static server_message_t sm = {0};
	wlog("call flip old items\n");
	lock_cursor();
	for(int i = 0; i < USER_CNT; i++) {
		if(sm.user_pos[i].x >= BATTLE_W
		|| sm.user_pos[i].y >= BATTLE_H)
			continue;

		wlog("clear user %d@(%d, %d)\n", i, sm.user_pos[i].x, sm.user_pos[i].y);
		set_cursor(sm.user_pos[i].x, sm.user_pos[i].y);
		printf(" ");
	}

	for(int i = 0; i < MAX_ITEM; i++) {
		if(sm.item_kind[i] != ITEM_BULLET)
			continue;

		set_cursor(sm.item_pos[i].x, sm.item_pos[i].y);
		printf(" ");
	}

	fflush(stdout);

	unlock_cursor();
	memcpy(&sm, psm, sizeof(server_message_t));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x5342(%rip), %rsi      # 0xa160
leaq 0x2223(%rip), %rdi      # 0x7048
movl $0x472, %edx            # imm = 0x472
xorl %eax, %eax
callq 0x27b9
leaq 0x53f8(%rip), %rdi      # 0xa230
callq 0x2200
leaq 0x54bf(%rip), %r13      # 0xa303
leaq 0x2219(%rip), %r14      # 0x7064
leaq 0x15d8(%rip), %r15      # 0x642a
xorl %r12d, %r12d
movzbl 0x4(%r13,%r12,2), %r8d
cmpl $0x3b, %r8d
ja 0x4eaa
movzbl 0x5(%r13,%r12,2), %r9d
cmpl $0xf, %r9d
ja 0x4eaa
movq 0x52ec(%rip), %rsi      # 0xa160
movq %r14, %rdi
movl $0x479, %edx            # imm = 0x479
movl %r12d, %ecx
xorl %eax, %eax
callq 0x27b9
movzbl 0x4(%r13,%r12,2), %edx
movzbl 0x5(%r13,%r12,2), %esi
incl %esi
incl %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x20b0
movl $0x20, %edi
callq 0x2040
incq %r12
cmpq $0x5, %r12
jne 0x4e55
movl $0x4b, %r15d
leaq 0x156a(%rip), %r14      # 0x642a
cmpb $0x6, -0x3d(%r15,%r13)
jne 0x4eec
movzbl -0x1(%r13,%r15,2), %edx
movzbl (%r13,%r15,2), %esi
incl %esi
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20b0
movl $0x20, %edi
callq 0x2040
incq %r15
cmpq $0xd2, %r15
jne 0x4ec0
movq 0x50c9(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2160
leaq 0x5322(%rip), %rdi      # 0xa230
callq 0x2150
leaq 0x53e9(%rip), %rdi      # 0xa303
movl $0x1a3, %edx            # imm = 0x1A3
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140
// File: /workspace/github_c_makefile_star2_O3/wierton[P]socket-based-naive-game/client.c
// Function: draw_users
void draw_users(server_message_t *psm) {
	lock_cursor();
	for(int i = 0; i < USER_CNT; i++) {
		if(psm->user_pos[i].x >= BATTLE_W
		|| psm->user_pos[i].y >= BATTLE_H)
			continue;

		set_cursor(psm->user_pos[i].x, psm->user_pos[i].y);
		if(i == psm->index)
			printf("Y");
		else
			printf("A");
	}

	fflush(stdout);
	unlock_cursor();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0x52e6(%rip), %rdi      # 0xa230
callq 0x2200
leaq 0x14d4(%rip), %r14      # 0x642a
movl $0x59, %r15d
xorl %r12d, %r12d
movzbl 0x4(%rbx,%r12,2), %edx
cmpl $0x3b, %edx
ja 0x4f98
movzbl 0x5(%rbx,%r12,2), %esi
cmpl $0xf, %esi
ja 0x4f98
incl %esi
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20b0
movzbl 0x2(%rbx), %eax
cmpq %rax, %r12
movl $0x41, %edi
cmovel %r15d, %edi
callq 0x2040
incq %r12
cmpq $0x5, %r12
jne 0x4f5f
movq 0x5020(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2160
leaq 0x5279(%rip), %rdi      # 0xa230
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2150
// File: /workspace/github_c_makefile_star2_O3/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 0x5254(%rip), %rdi      # 0xa230
callq 0x2200
movq $-0x87, %r13
leaq 0x143b(%rip), %r14      # 0x642a
leaq 0x100e(%rip), %r15      # 0x6004
leaq 0x208a(%rip), %r12      # 0x7087
cmpb $0x0, 0x95(%rbx,%r13)
je 0x506e
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 0x506e
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x2b, %edi
jmp 0x5069
movq %r12, %rdi
jmp 0x5054
leaq 0x202f(%rip), %rdi      # 0x7083
xorl %eax, %eax
callq 0x20b0
jmp 0x506e
movl $0x2a, %edi
jmp 0x5069
movl $0x2e, %edi
callq 0x2040
incq %r13
jne 0x4ffd
movq 0x4f4e(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2160
leaq 0x51a7(%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_O3/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 0x53f0(%rip), %r14      # 0xa4b0
leaq 0x1fc4(%rip), %rsi      # 0x708b
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 0x1fc5(%rip), %r15      # 0x70ba
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 0x50f8
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 0x1f7d(%rip), %r15      # 0x70cb
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 0x514e
movslq %r12d, %rax
movw $0xa, (%rax,%r14)
addl $0xfff00001, %eax       # imm = 0xFFF00001
cmpl $0xfff00000, %eax       # imm = 0xFFF00000
jb 0x51c4
movq 0x4fc4(%rip), %rsi      # 0xa160
leaq 0x1f42(%rip), %rdi      # 0x70e5
leaq 0x5306(%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 0x27b9
callq 0x234d
// File: /workspace/github_c_makefile_star2_O3/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 0x4f87(%rip), %rsi      # 0xa160
leaq 0x1807(%rip), %rdi      # 0x69e7
leaq 0x1f16(%rip), %rcx      # 0x70fd
movl $0x4cd, %edx            # imm = 0x4CD
xorl %eax, %eax
callq 0x27b9
cmpl $0x3, 0x4f72(%rip)      # 0xa16c
jne 0x5268
movq %rbx, %rdi
callq 0x509c
movzbl 0x3(%rbx), %eax
movl %eax, 0x50ca(%rip)      # 0xa2d8
movzbl 0x1(%rbx), %eax
movl %eax, 0x50bc(%rip)      # 0xa2d4
movq %rbx, %rdi
callq 0x4e06
movq %rbx, %rdi
callq 0x4f35
movq %rbx, %rdi
callq 0x4fc4
movl 0x4f36(%rip), %eax      # 0xa16c
movq 0x4f23(%rip), %rdx      # 0xa160
movl 0x5091(%rip), %ecx      # 0xa2d4
movl 0x508e(%rip), %r8d      # 0xa2d8
leaq 0x49df(%rip), %rsi      # 0x9c30
movq (%rsi,%rax,8), %r9
leaq 0x1294(%rip), %rsi      # 0x64f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0x28af
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x4d2a(%rip), %rsi      # 0xa160
leaq 0x1df3(%rip), %rdi      # 0x7230
movl $0x524, %edx            # imm = 0x524
xorl %eax, %eax
callq 0x27b9
movl $0x1a3, %r13d           # imm = 0x1A3
leaq 0x1df8(%rip), %rbx      # 0x724e
movl $0x98001, %r15d         # imm = 0x98001
movl $0x67b0, %r12d          # imm = 0x67B0
xorl %r14d, %r14d
movl 0x4ced(%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 0x5465
movq 0x4cc5(%rip), %rsi      # 0xa160
movzbl -0x1cb(%rbp), %eax
leaq 0x4657(%rip), %rcx      # 0x9b00
movq (%rcx,%rax,8), %rcx
movq %rbx, %rdi
movl $0x527, %edx            # imm = 0x527
xorl %eax, %eax
callq 0x27b9
movzbl -0x1cb(%rbp), %eax
btq %rax, %r15
jb 0x551b
movq 0x4c90(%rip), %rsi      # 0xa160
leaq 0x1d9a(%rip), %rdi      # 0x7271
movl $0x529, %edx            # imm = 0x529
xorl %eax, %eax
callq 0x27b9
movzbl -0x1cb(%rbp), %eax
leaq -0x1cb(%rbp), %rdi
leaq 0x47b8(%rip), %rcx      # 0x9cb0
callq *(%rcx,%rax,8)
movq 0x4c5e(%rip), %rsi      # 0xa160
leaq 0x1d89(%rip), %rdi      # 0x7292
movl $0x52b, %edx            # imm = 0x52B
xorl %eax, %eax
callq 0x27b9
movb -0x1cb(%rbp), %al
movl $0x0, %r14d
cmpb $0xe, %al
ja 0x5465
movzbl %al, %eax
btl %eax, %r12d
movl $0x0, %r14d
jae 0x5465
movl %eax, 0x4c26(%rip)      # 0xa168
jmp 0x5462
// File: /workspace/github_c_makefile_star2_O3/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 0x4be1(%rip), %rsi      # 0xa160
leaq 0x1d7d(%rip), %rdi      # 0x7303
movl $0x545, %edx            # imm = 0x545
xorl %eax, %eax
callq 0x27b9
callq 0x24c1
movl %eax, 0x4bbb(%rip)      # 0xa158
leaq 0x1d95(%rip), %rdi      # 0x7339
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, 0x4ca4(%rip)      # 0xa26c
leaq 0x4c89(%rip), %rdi      # 0xa258
callq 0x2e01
leaq 0xe58(%rip), %rdi       # 0x6433
xorl %eax, %eax
callq 0x20b0
callq 0x3654
callq 0x5547
callq 0x417a
// File: /workspace/github_c_makefile_star2_O3/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 0x186e(%rip), %rdi      # 0x4c58
movl $0x1, %esi
callq 0x2cb1
movq %rax, (%rsp)
leaq 0x18aa(%rip), %rdi      # 0x4ca9
callq 0x1070
leaq 0x1858(%rip), %r14      # 0x4c63
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x27d0
movq %rax, %r15
callq 0x11b0
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 0x27df
incq %rbx
cmpq $0x64, %rbx
jne 0x3441
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2b11
addl $0xfffffc18, %ebp       # imm = 0xFFFFFC18
cmpl $0xa, %ebp
ja 0x347c
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x10a0
incq %r13
cmpq $0xf4240, %r13          # imm = 0xF4240
jne 0x340e
leaq 0x185a(%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 0x287d
movq %rax, %r14
movq %rax, %rdi
callq 0x27e4
testq %rax, %rax
je 0x351f
movq %rax, %r15
leaq 0xdee(%rip), %r13       # 0x42b7
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x27e8
movq %rax, %r12
leaq 0x17a9(%rip), %rdi      # 0x4c89
movq %rbp, %rsi
xorl %eax, %eax
callq 0x10a0
xorl %ebx, %ebx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27da
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x10a0
incq %rbx
cmpq $0xa, %rbx
jne 0x34ec
movl $0xa, %edi
callq 0x1040
incq %rbp
cmpq %r15, %rbp
jne 0x34cb
movq %r14, %rdi
callq 0x2816
leaq 0x1801(%rip), %rdi      # 0x4d2f
callq 0x1070
movq (%rsp), %rdi
callq 0x31df
leaq 0x1805(%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_O3/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 0x6e2e(%rip), %eax      # 0x80c0
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, 0x6e13(%rip)      # 0x80c0
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x271e
leaq 0xc(%rsp), %r12
movl %eax, (%r12)
movslq %eax, %rdi
callq 0x1110
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebp, %ecx
movl $0x1, %r8d
callq 0x362b
testq %r14, %r14
je 0x182a
movq %r14, %rdi
callq 0x1070
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10f0
jmp 0x1841
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x1140
movq %r14, %rdi
callq 0x1100
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O3/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 0x1401
xorl %edx, %edx
testq %rcx, %rcx
setns %dl
xorl $0x303, %edx            # imm = 0x303
movq 0x8(%rdi,%rdx,8), %rdx
btq %rcx, %rdx
jae 0x1401
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
testq %rax, %rax
je 0x1465
orq $0x100, %rdx            # imm = 0x100
jmp 0x146c
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 0x1473
andq $-0x103, %rdx           # imm = 0xFEFD
movq %rdx, 0x808(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x151c
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 0x6da3(%rip), %rdi      # 0x82ca
leaq 0x6db1(%rip), %rsi      # 0x82df
leaq 0x6db4(%rip), %rcx      # 0x82e9
movl $0x37c, %edx            # imm = 0x37C
callq 0x10c0
// File: /workspace/github_c_makefile_star2_O3/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 0x1680
movq 0x8118(%rbx), %rax
movzbl 0x1(%rax), %esi
testl %esi, %esi
je 0x1679
movq 0xb976(%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 0xb951(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
callq 0x1080
testb %al, %al
je 0x164c
movzbl %al, %ecx
cmpl $0xff, %ecx
je 0x164c
movq 0x8118(%rbx), %rcx
movb %al, (%rcx)
orb $0x1, 0x6(%rcx)
jmp 0x164c
// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x8128(%rdi), %rax
movl 0x4(%rax), %r8d
movl 0x28(%rax), %r9d
movq 0x1008(%rax), %r11
movl %r11d, %r10d
shrb %r10b
andb $0x1, %r10b
shrl $0xa, %r11d
andb $0x1, %r11b
leaq -0x34(%rbp), %r14
movl $0x1, (%r14)
leaq -0x30(%rbp), %rcx
movl $0xa, (%rcx)
leaq -0x2c(%rbp), %r15
movl %r8d, (%r15)
leaq -0x28(%rbp), %r8
movl %r9d, (%r8)
leaq -0x22(%rbp), %r12
movb %r10b, (%r12)
leaq -0x21(%rbp), %r10
movb %r11b, (%r10)
xorl %r9d, %r9d
movb $0x1, %r11b
xorl %ebx, %ebx
testb $0x1, %sil
je 0x176a
cmpb $0x1, (%r12)
jne 0x176a
movl (%r15), %esi
cmpl %ebx, %esi
jbe 0x176a
cmpl 0x1010(%rax), %esi
jbe 0x176a
movl (%r14), %r9d
movl %esi, %ebx
movq %r10, %r12
movq %r8, %r15
movq %rcx, %r14
movl %edx, %esi
testb $0x1, %r11b
movl $0x0, %r11d
jne 0x1749
testl %r9d, %r9d
je 0x17af
movl %r9d, 0x1000(%rax)
movzbl 0x8148(%rdi), %eax
cmpl $0x3, %eax
je 0x17a5
cmpl $0x1, %eax
jne 0x17af
movl $0xa28, %eax            # imm = 0xA28
jmp 0x17aa
movl $0x1a28, %eax           # imm = 0x1A28
orb $0x2, 0x1(%rdi,%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x17ee
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
orb $0x1, 0x20(%rax)
callq 0x17ef
movq 0x8130(%rbx), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x1b05
movq %rbx, %rdi
movl %eax, %esi
callq 0x1b5e
movq $0x0, 0x8008(%rbx)
cmpb $0x1, 0x8138(%rbx)
jne 0x1a38
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1361
movb $0x0, 0x8138(%rbx)
movq $0x0, 0x8140(%rbx)
movq %rbx, %rdi
callq 0x1637
movq 0x8130(%rbx), %rax
cmpl $0x1234, 0x1c(%rax)     # imm = 0x1234
je 0x1a6a
orb $0x1, 0x20(%rax)
movq %rbx, %rdi
callq 0x17ef
movq 0x8130(%rbx), %rax
movl $0x1234, 0x1c(%rax)     # imm = 0x1234
movq 0x8120(%rbx), %rcx
incq 0x10(%rcx)
movq $-0x89, %rdx
andq 0x1a28(%rbx), %rdx
movl (%rcx), %ecx
andl $0x1, %ecx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x1a28(%rbx)
movl 0x20(%rax), %esi
movq 0x8118(%rbx), %rax
movb 0x2(%rax), %cl
testb $0x1, %cl
je 0x1ab0
cmpb $0x0, (%rax)
je 0x1ab0
movb $0x1, %cl
movb $0x4, %dl
jmp 0x1abf
testb $0x2, %cl
je 0x1abb
cmpb $0x0, 0x1(%rax)
je 0x1aff
movb $0xf, %dl
xorl %ecx, %ecx
andl $0x1, %esi
movb %dl, 0x3(%rax)
movzbl %cl, %edx
movq %rbx, %rdi
callq 0x16dc
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x153f
testb %al, %al
je 0x1afa
cmpb $0x1, 0x8138(%rbx)
jne 0x1afa
movb $0x0, 0x8138(%rbx)
movq $0x0, 0x8140(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
movb $0x1, %cl
movb $0x2, %dl
jmp 0x1abf
// File: /workspace/github_c_makefile_star2_O3/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 0x2a23
cmpb $0x0, 0x8138(%rbx)
jne 0x1b52
movq %rax, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x27e9
movzbl %al, %eax
movl %r12d, %ecx
shll %cl, %eax
orl %eax, %r14d
addq $0x8, %r12
incq %r15
cmpq $0x20, %r12
jne 0x1b2f
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x1d99
cmpb $0x0, (%rcx)
je 0x1d99
movb $0x1, %al
movb $0x4, %dl
jmp 0x1da7
testb $0x2, %al
je 0x1da3
cmpb $0x0, 0x1(%rcx)
je 0x1dac
movb $0xf, %dl
xorl %eax, %eax
movb %dl, 0x3(%rcx)
popq %rbp
retq
movb $0x1, %al
movb $0x2, %dl
jmp 0x1da7
// File: /workspace/github_c_makefile_star2_O3/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 0x1e1f
movb %dl, 0x1(%rax)
andb $-0x21, 0x6(%rax)
jmp 0x1e38
testb %cl, %cl
setns %cl
cmpq $0x1, %rsi
sete %dil
andb %cl, %dil
cmpb $0x1, %dil
jne 0x1e3a
movb %dl, 0x2(%rax)
popq %rbp
retq
cmpq $0x7, %rsi
je 0x1e56
cmpq $0x4, %rsi
je 0x1e51
cmpq $0x3, %rsi
jne 0x1e38
movb %dl, 0x4(%rax)
jmp 0x1e38
movb %dl, 0x5(%rax)
jmp 0x1e38
movb %dl, 0x8(%rax)
jmp 0x1e38
// File: /workspace/github_c_makefile_star2_O3/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 0x1e89
movb (%rcx), %al
movb $0x0, (%rcx)
andb $-0x2, 0x6(%rcx)
jmp 0x1ea2
testb %al, %al
setns %dl
cmpq $0x1, %rsi
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x1ea4
movb 0x2(%rcx), %al
popq %rbp
retq
addq $-0x2, %rsi
cmpq $0x5, %rsi
ja 0x1ed7
leaq 0x61c3(%rip), %rdx      # 0x8078
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movb 0x3(%rcx), %al
jmp 0x1ea2
movb 0x7(%rcx), %al
jmp 0x1ea2
movb 0x5(%rcx), %al
jmp 0x1ea2
movb 0x6(%rcx), %al
jmp 0x1ea2
movb 0x8(%rcx), %al
jmp 0x1ea2
xorl %eax, %eax
jmp 0x1ea2
// File: /workspace/github_c_makefile_star2_O3/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 0x1f0e
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 0x1f83
movq %rcx, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1f55
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1f83
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 0x1f83
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_O3/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 0x1f9a
movq 0x8120(%rdi), %rax
movl (%rax), %eax
jmp 0x1fc9
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0xbff8, %rax           # imm = 0xBFF8
je 0x1fbe
cmpq $0x4000, %rax           # imm = 0x4000
jne 0x1fd3
movq 0x8120(%rdi), %rax
movq 0x8(%rax), %rax
jmp 0x1fc9
movq 0x8120(%rdi), %rax
movq 0x10(%rax), %rax
shll $0x3, %esi
movl %esi, %ecx
shrq %cl, %rax
popq %rbp
retq
xorl %eax, %eax
jmp 0x1fd1
// File: /workspace/github_c_makefile_star2_O3/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 0x2022
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 0x20e1
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x2069
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 0x20e1
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x20b0
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x20e1
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 0x20e1
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_O3/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 0x210a
movq 0x8128(%rdi), %rcx
andq $-0x4, %rax
movl (%rcx,%rax), %eax
shll $0x3, %esi
andb $0x18, %sil
jmp 0x2150
movq %rsi, %rax
andq $-0x8, %rax
cmpq $0x2080, %rax           # imm = 0x2080
jne 0x2129
movq 0x8128(%rdi), %rax
movq 0x1008(%rax), %rax
jmp 0x214d
movq %rsi, %rax
andq $-0x4, %rax
cmpq $0x201004, %rax         # imm = 0x201004
je 0x2157
cmpq $0x201000, %rax         # imm = 0x201000
jne 0x216d
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 0x2150
xorl %eax, %eax
jmp 0x2155
// File: /workspace/github_c_makefile_star2_O3/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 0x25be
shll $0x3, %esi
movl $0x74726976, %eax       # imm = 0x74726976
movl %esi, %ecx
jmp 0x25d4
cmpq $0x7, %rsi
ja 0x25d9
leaq -0x20(,%rsi,8), %rcx
xorl %eax, %eax
testq %rcx, %rcx
sete %al
shrq %cl, %rax
popq %rbp
retq
cmpq $0xb, %rsi
ja 0x25e9
shll $0x3, %esi
movl $0x2, %eax
jmp 0x25ba
cmpq $0xf, %rsi
ja 0x25fd
shll $0x3, %esi
addb $-0x60, %sil
movl $0x554d4551, %eax       # imm = 0x554D4551
jmp 0x25ba
cmpq $0x13, %rsi
ja 0x2611
movq 0x8130(%rdi), %rax
movl (%rax), %eax
shll $0x3, %esi
jmp 0x25ba
movq %rsi, %rcx
andq $-0x4, %rcx
xorl %eax, %eax
cmpq $0x5f, %rcx
jg 0x2638
cmpq $0x34, %rcx
je 0x2650
cmpq $0x40, %rcx
jne 0x25d7
movq 0x8130(%rdi), %rax
movl 0x18(%rax), %eax
jmp 0x260c
cmpq $0x60, %rcx
je 0x266c
cmpq $0x70, %rcx
jne 0x25d7
movq 0x8130(%rdi), %rax
movl 0x28(%rax), %eax
jmp 0x260c
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
andq %rax, %rsi
cmpq $0x35, %rsi
sete %al
shlb $0x5, %al
jmp 0x25d7
movq 0x8130(%rdi), %rax
movl 0x20(%rax), %eax
jmp 0x260c
// File: /workspace/github_c_makefile_star2_O3/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 0x269d
addq $-0x10000000, %rsi      # imm = 0xF0000000
movzbl %dl, %edx
popq %rbp
jmp 0x1df2
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x26be
addq $-0x2000000, %rsi       # imm = 0xFE000000
movzbl %dl, %edx
popq %rbp
jmp 0x1edb
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x26df
addq $-0xc000000, %rsi       # imm = 0xF4000000
movzbl %dl, %edx
popq %rbp
jmp 0x1fd7
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x2700
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
movzbl %dl, %edx
popq %rbp
jmp 0x23c4
movq %rsi, %rax
shrq $0x1f, %rax
je 0x2719
movq 0x8108(%rdi), %rax
movb %dl, -0x80000000(%rax,%rsi)
jmp 0x272b
movb $0x1, 0x8138(%rdi)
movq $0xf, 0x8140(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x280b
addq $-0x10000000, %rsi      # imm = 0xF0000000
popq %rbp
jmp 0x1e5b
movq %rsi, %rax
andq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x2829
addq $-0x2000000, %rsi       # imm = 0xFE000000
popq %rbp
jmp 0x1f85
movq %rsi, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0xc000000, %rax        # imm = 0xC000000
jne 0x2847
addq $-0xc000000, %rsi       # imm = 0xF4000000
popq %rbp
jmp 0x20e3
movq %rsi, %rax
andq $-0x1000, %rax          # imm = 0xF000
cmpq $0x10001000, %rax       # imm = 0x10001000
jne 0x2865
addq $-0x10001000, %rsi      # imm = 0xEFFFF000
popq %rbp
jmp 0x25a8
movq %rsi, %rax
shrq $0x1f, %rax
je 0x287e
movq 0x8108(%rdi), %rax
movb -0x80000000(%rax,%rsi), %al
jmp 0x2892
movb $0x1, 0x8138(%rdi)
movq $0xd, 0x8140(%rdi)
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movb $0x1, %r13b
xorl %r12d, %r12d
xorl %r15d, %r15d
leaq (%r12,%rbx), %rsi
movq %r14, %rdi
callq 0x27e9
movzbl %al, %eax
shll $0x3, %r12d
movl %r12d, %ecx
shll %cl, %eax
orl %eax, %r15d
movl $0x1, %r12d
testb $0x1, %r13b
movl $0x0, %r13d
jne 0x28b1
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x27e9
movzbl %al, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, %r12d
addq $0x8, %r15
incq %rbx
cmpq $0x20, %r15
jne 0x2907
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x27e9
movzbl %al, %eax
movl %r15d, %ecx
shlq %cl, %rax
orq %rax, %r12
incq %rbx
addq $0x8, %r15
cmpq $0x40, %r15
jne 0x294d
movq %r12, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq