LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/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 0x29b0
cmpl $0x1, %esi
je 0x29a3
testl %esi, %esi
jne 0x29bd
movq $0x1, 0x8140(%rdi)
jmp 0x29bb
movq $0x5, 0x8140(%rdi)
jmp 0x29bb
movq $0x7, 0x8140(%rdi)
popq %rbp
retq
movzbl %sil, %esi
leaq 0x58c7(%rip), %rdi      # 0x828f
xorl %eax, %eax
popq %rbp
jmp 0x6c10
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: PageFault
void PageFault(State *state, uint8_t access_type) {
    state->excepted = true;
    switch (access_type) {
    case AccessInstruction:
        state->exception_code = InstructionPageFault;
        break;
    case AccessLoad:
        state->exception_code = LoadPageFault;
        break;
    case AccessStore:
        state->exception_code = StoreAMOPageFault;
        break;
    default:
        Error("Unknown access type: %d", access_type);
        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb $0x1, 0x8138(%rdi)
cmpl $0x2, %esi
je 0x2a03
cmpl $0x1, %esi
je 0x29f6
testl %esi, %esi
jne 0x2a10
movq $0xc, 0x8140(%rdi)
jmp 0x2a0e
movq $0xd, 0x8140(%rdi)
jmp 0x2a0e
movq $0xf, 0x8140(%rdi)
popq %rbp
retq
movzbl %sil, %esi
leaq 0x5874(%rip), %rdi      # 0x828f
xorl %eax, %eax
popq %rbp
jmp 0x6c10
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: Require
bool Require(State *state, uint8_t mode) {
    if (state->mode == MACHINE) {
        if (mode == MACHINE || mode == SUPERVISOR || mode == USER) {
            return true;
        }
    } else if (state->mode == SUPERVISOR) {
        if (mode == SUPERVISOR || mode == USER) {
            return true;
        }
    } else if (state->mode == USER) {
        if (mode == USER) {
            return true;
        }
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x8148(%rdi), %eax
cmpl $0x1, %eax
je 0x2d95
cmpl $0x3, %eax
jne 0x2d9f
cmpb $0x3, %sil
ja 0x2da4
movzbl %sil, %ecx
movb $0x1, %al
cmpl $0x2, %ecx
jne 0x2dbc
jmp 0x2da4
movb $0x1, %al
cmpb $0x2, %sil
jae 0x2da4
jmp 0x2dbc
orb %sil, %al
je 0x2dba
movb $0x1, 0x8138(%rdi)
movq $0x2, 0x8140(%rdi)
xorl %eax, %eax
jmp 0x2dbc
movb $0x1, %al
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecOpImmInstr
void ExecOpImmInstr(State *state, uint32_t instr) {
    uint8_t funct3 = (instr >> 12) & SetNBits(3);
    uint8_t funct7 = (instr >> 25) & SetNBits(7);
    uint8_t funct6 = (instr >> 26) & SetNBits(6);

    switch (funct3) {
    case 0x0:
        ExecAddi(state, instr);
        break;
    case 0x1:
        ExecSlli(state, instr);
        break;
    case 0x2:
        ExecSlti(state, instr);
        break;
    case 0x3:
        ExecSltiu(state, instr);
        break;
    case 0x4:
        ExecXori(state, instr);
        break;
    case 0x5:
        if (funct6 == 0x00) {
            ExecSrli(state, instr);
        } else if (funct6 == 0x10) {
            ExecSrai(state, instr);
        }
        break;
    case 0x6:
        ExecOri(state, instr);
        break;
    case 0x7:
        ExecAndi(state, instr);
        break;
    default:
        Error("Unknown OP_IMM instruction: %2x", funct3);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0xc, %eax
movl %eax, %ecx
andl $0x7, %ecx
leaq 0x509b(%rip), %rdx      # 0x8090
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
leaq -0x1000(%rcx), %r8
testl %esi, %esi
cmovnsq %rcx, %r8
addq 0x8008(%rdi,%rax), %r8
jmp 0x30cb
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
leaq -0x1000(%rcx), %r8
testl %esi, %esi
cmovnsq %rcx, %r8
xorq 0x8008(%rdi,%rax), %r8
jmp 0x30cb
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
leaq -0x1000(%rcx), %r8
testl %esi, %esi
cmovnsq %rcx, %r8
xorl %ecx, %ecx
cmpq %r8, 0x8008(%rdi,%rax)
setl %cl
jmp 0x3098
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
leaq -0x1000(%rcx), %r8
testl %esi, %esi
cmovnsq %rcx, %r8
xorl %ecx, %ecx
cmpq %r8, 0x8008(%rdi,%rax)
setb %cl
shrl $0x4, %esi
andl %edx, %esi
movq %rcx, 0x8008(%rdi,%rsi)
jmp 0x3171
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
leaq -0x1000(%rcx), %r8
testl %esi, %esi
cmovnsq %rcx, %r8
andq 0x8008(%rdi,%rax), %r8
shrl $0x4, %esi
andl %edx, %esi
movq %r8, 0x8008(%rdi,%rsi)
jmp 0x3171
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movq 0x8008(%rdi,%rax), %rax
shlq %cl, %rax
jmp 0x3164
movl %esi, %ecx
shrl $0x1a, %ecx
cmpl $0x10, %ecx
je 0x314d
testl %ecx, %ecx
jne 0x3171
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movq 0x8008(%rdi,%rax), %rax
shrq %cl, %rax
jmp 0x3164
movl %esi, %ecx
shrl $0x14, %ecx
leaq -0x1000(%rcx), %rdx
testl %esi, %esi
cmovnsq %rcx, %rdx
movl $0xf8, %ecx
andl %ecx, %eax
orq 0x8008(%rdi,%rax), %rdx
shrl $0x4, %esi
andl %ecx, %esi
movq %rdx, 0x8008(%rdi,%rsi)
jmp 0x3171
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movq 0x8008(%rdi,%rax), %rax
sarq %cl, %rax
shrl $0x4, %esi
andl %edx, %esi
movq %rax, 0x8008(%rdi,%rsi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecDiv
void ExecDiv(State *state, uint32_t instr) {
    uint8_t rd = (instr >> 7) & SetNBits(5);
    uint8_t rs1 = (instr >> 15) & SetNBits(5);
    uint8_t rs2 = (instr >> 20) & SetNBits(5);

    if (state->x[rs2] == 0) {
        state->x[rd] = -1;
    } else if (state->x[rs1] == -((int64_t)1 << 63) && state->x[rs2] == -1) {
        state->x[rd] = -((int64_t)1 << 63);
    } else {
        state->x[rd] = state->x[rs1] / state->x[rs2];
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0x11, %eax
andl $0xf8, %eax
movq 0x8008(%rdi,%rax), %r8
testq %r8, %r8
je 0x346e
movl %esi, %eax
shrl $0xc, %eax
andl $0xf8, %eax
movq 0x8008(%rdi,%rax), %rcx
cmpq $-0x1, %r8
jne 0x3464
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, %rcx
je 0x3475
movq %rcx, %rax
cqto
idivq %r8
jmp 0x3475
movq $-0x1, %rax
shrl $0x4, %esi
andl $0xf8, %esi
movq %rax, 0x8008(%rdi,%rsi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecLoadInstr
void ExecLoadInstr(State *state, uint32_t instr) {
    uint8_t funct3 = (instr >> 12) & SetNBits(3);

    switch (funct3) {
    case 0x0:
        ExecLb(state, instr);
        break;
    case 0x1:
        ExecLh(state, instr);
        break;
    case 0x2:
        ExecLw(state, instr);
        break;
    case 0x3:
        ExecLd(state, instr);
        break;
    case 0x4:
        ExecLbu(state, instr);
        break;
    case 0x5:
        ExecLhu(state, instr);
        break;
    case 0x6:
        ExecLwu(state, instr);
        break;
    default:
        Error("Unimplemented Load Instruction: funct3=0x%x", funct3);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %eax
shrl $0xc, %eax
movl %eax, %esi
andl $0x7, %esi
leaq 0x42f0(%rip), %rcx      # 0x80d0
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq %r14, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3b2f
movl %ebx, %ecx
shrl $0x14, %ecx
movl $0xf8, %r15d
andl %r15d, %eax
leaq -0x1000(%rcx), %rsi
testl %ebx, %ebx
cmovnsq %rcx, %rsi
addq 0x8008(%r14,%rax), %rsi
movq %r14, %rdi
callq 0x22f4
movzbl %al, %eax
jmp 0x3f3c
movl %ebx, %ecx
shrl $0x14, %ecx
movl $0xf8, %r15d
andl %r15d, %eax
leaq -0x1000(%rcx), %rsi
testl %ebx, %ebx
cmovnsq %rcx, %rsi
addq 0x8008(%r14,%rax), %rsi
movq %r14, %rdi
callq 0x2298
movl %eax, %ecx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
orq %rcx, %rdx
testl %eax, %eax
cmovnsq %rcx, %rdx
shrl $0x4, %ebx
andl %r15d, %ebx
movq %rdx, 0x8008(%r14,%rbx)
jmp 0x3f4a
movl %ebx, %ecx
shrl $0x14, %ecx
movl $0xf8, %r15d
andl %r15d, %eax
leaq -0x1000(%rcx), %rsi
testl %ebx, %ebx
cmovnsq %rcx, %rsi
addq 0x8008(%r14,%rax), %rsi
movq %r14, %rdi
callq 0x2239
jmp 0x3f3c
leaq 0x44a2(%rip), %rdi      # 0x835c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6c10
movq %r14, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3b94
movl %ebx, %ecx
shrl $0x14, %ecx
movl $0xf8, %r15d
andl %r15d, %eax
leaq -0x1000(%rcx), %rsi
testl %ebx, %ebx
cmovnsq %rcx, %rsi
addq 0x8008(%r14,%rax), %rsi
movq %r14, %rdi
callq 0x21c5
movzwl %ax, %eax
jmp 0x3f3c
movl %ebx, %ecx
shrl $0x14, %ecx
movl $0xf8, %r15d
andl %r15d, %eax
leaq -0x1000(%rcx), %rsi
testl %ebx, %ebx
cmovnsq %rcx, %rsi
addq 0x8008(%r14,%rax), %rsi
movq %r14, %rdi
callq 0x2298
movl %eax, %eax
shrl $0x4, %ebx
andl %r15d, %ebx
movq %rax, 0x8008(%r14,%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecStoreInstr
void ExecStoreInstr(State *state, uint32_t instr) {
    uint8_t funct3 = (instr >> 12) & SetNBits(3);

    switch (funct3) {
    case 0x0:
        ExecSb(state, instr);
        break;
    case 0x1:
        ExecSh(state, instr);
        break;
    case 0x2:
        ExecSw(state, instr);
        break;
    case 0x3:
        ExecSd(state, instr);
        break;
    default:
        Error("Unimplemented Store Instruction: funct3=0x%x", funct3);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0xc, %eax
andl $0x7, %eax
cmpb $0x3, %al
ja 0x40c8
leaq 0x4049(%rip), %rcx      # 0x80f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
popq %rbp
jmp 0x3f55
popq %rbp
jmp 0x3ff3
popq %rbp
jmp 0x4041
popq %rbp
jmp 0x3fa4
leaq 0x42b9(%rip), %rdi      # 0x8388
movl %eax, %esi
xorl %eax, %eax
popq %rbp
jmp 0x6c10
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecBeq
void ExecBeq(State *state, uint32_t instr) {
    uint8_t rs1 = (instr >> 15) & SetNBits(5);
    uint8_t rs2 = (instr >> 20) & SetNBits(5);
    int32_t offset = Sext(((instr >> 31 & SetNBits(1)) << 12) |
                              ((instr >> 7 & SetNBits(1)) << 11) |
                              ((instr >> 25 & SetNBits(6)) << 5) |
                              ((instr >> 8 & SetNBits(4)) << 1),
                          12);

    if (state->x[rs1] == state->x[rs2])
        state->pc += offset;
    else
        state->pc += sizeof(instr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0x14, %eax
movl %esi, %ecx
shrl $0xc, %ecx
andl $0xf8, %ecx
movq 0x8008(%rdi,%rcx), %rdx
movl %eax, %r8d
andl $0x1f, %r8d
movl $0x4, %ecx
cmpq 0x8008(%rdi,%r8,8), %rdx
jne 0x4140
andl $0x7e0, %eax            # imm = 0x7E0
movl %esi, %ecx
shrl $0x7, %ecx
andl $0x1e, %ecx
orl %eax, %ecx
movl %esi, %eax
shrl $0x13, %eax
andl $0x1000, %eax           # imm = 0x1000
movl %esi, %edx
shll $0x4, %edx
andl $0x800, %edx            # imm = 0x800
orl %ecx, %edx
orl %eax, %edx
leaq -0x2000(%rdx), %rcx
testl %esi, %esi
cmovnsq %rdx, %rcx
addq %rcx, (%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecBranchInstr
void ExecBranchInstr(State *state, uint32_t instr) {
    uint8_t funct3 = (instr >> 12) & SetNBits(3);

    switch (funct3) {
    case 0x0:
        ExecBeq(state, instr);
        break;
    case 0x1:
        ExecBne(state, instr);
        break;
    case 0x4:
        ExecBlt(state, instr);
        break;
    case 0x5:
        ExecBge(state, instr);
        break;
    case 0x6:
        ExecBltu(state, instr);
        break;
    case 0x7:
        ExecBgeu(state, instr);
        break;
    default:
        Error("Unimplemented Branch Instruction: funct3=0x%x", funct3);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0xc, %eax
andl $0x7, %eax
cmpb $0x7, %al
ja 0x4393
leaq 0x3d88(%rip), %rcx      # 0x8100
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
popq %rbp
jmp 0x40d9
popq %rbp
jmp 0x41b1
popq %rbp
jmp 0x42f5
leaq 0x401b(%rip), %rdi      # 0x83b5
movl %eax, %esi
xorl %eax, %eax
popq %rbp
jmp 0x6c10
popq %rbp
jmp 0x4145
popq %rbp
jmp 0x421d
popq %rbp
jmp 0x4289
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecOpImm32Instr
void ExecOpImm32Instr(State *state, uint32_t instr) {
    uint8_t funct3 = (instr >> 12) & SetNBits(3);
    uint8_t funct7 = (instr >> 25) & SetNBits(7);

    switch (funct3) {
    case 0x0:
        ExecAddiw(state, instr);
        break;
    case 0x1:
        ExecSlliw(state, instr);
        break;
    case 0x5:
        if (funct7 == 0x00) {
            ExecSrliw(state, instr);
        } else if (funct7 == 0x20) {
            ExecSraiw(state, instr);
        }
        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0xc, %eax
movl %eax, %ecx
andb $0x7, %cl
cmpb $0x5, %cl
je 0x4568
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x1, %ecx
je 0x453d
testl %ecx, %ecx
jne 0x45de
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
testl %esi, %esi
movl $0x80000000, %r8d       # imm = 0x80000000
leaq 0x7ffff000(%rcx,%r8), %r8
cmovnsq %rcx, %r8
addq 0x8008(%rdi,%rax), %r8
movl %r8d, %eax
movslq %r8d, %rcx
movabsq $-0x100000000, %r8      # imm = 0xFFFFFFFF00000000
andq %rcx, %r8
orq %rax, %r8
shrl $0x4, %esi
andl %edx, %esi
movq %r8, 0x8008(%rdi,%rsi)
jmp 0x45de
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movq 0x8008(%rdi,%rax), %rax
andb $0x1f, %cl
shlq %cl, %rax
cltq
shrl $0x4, %esi
andl %edx, %esi
movq %rax, 0x8008(%rdi,%rsi)
jmp 0x45de
movl %esi, %ecx
shrl $0x19, %ecx
cmpl $0x20, %ecx
je 0x45a7
testl %ecx, %ecx
jne 0x45de
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movl 0x8008(%rdi,%rax), %eax
andb $0x1f, %cl
shrq %cl, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
orq %rax, %rcx
testl $0x80000000, %eax       # imm = 0x80000000
cmoveq %rax, %rcx
jmp 0x45d1
movl %esi, %ecx
shrl $0x14, %ecx
movl $0xf8, %edx
andl %edx, %eax
movl 0x8008(%rdi,%rax), %eax
sarl %cl, %eax
cltq
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
orq %rax, %rcx
testl %eax, %eax
cmovnsq %rax, %rcx
shrl $0x4, %esi
andl %edx, %esi
movq %rcx, 0x8008(%rdi,%rsi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecDivw
void ExecDivw(State *state, uint32_t instr) {
    uint8_t rd = (instr >> 7) & SetNBits(5);
    uint8_t rs1 = (instr >> 15) & SetNBits(5);
    uint8_t rs2 = (instr >> 20) & SetNBits(5);

    if (state->x[rs2] == 0) {
        state->x[rd] = -1;
    } else if ((int32_t)(state->x[rs1] & SetNBits(32)) == -((int32_t)1 << 31) && (int32_t)(state->x[rs2] & SetNBits(32)) == -1) {
        state->x[rd] = -((int32_t)1 << 31);
    } else {
        state->x[rd] = Sext(((int32_t)(state->x[rs1] & SetNBits(32)) / (int32_t)(state->x[rs2] & SetNBits(32))), 31);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0x11, %eax
andl $0xf8, %eax
movq 0x8008(%rdi,%rax), %rcx
testq %rcx, %rcx
je 0x4769
movl %esi, %eax
shrl $0xc, %eax
andl $0xf8, %eax
movl 0x8008(%rdi,%rax), %eax
cmpl $-0x1, %ecx
jne 0x474f
movq $-0x80000000, %rdx      # imm = 0x80000000
cmpl $0x80000000, %eax       # imm = 0x80000000
je 0x4770
cltd
idivl %ecx
cltq
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
orq %rax, %rdx
testl %eax, %eax
cmovnsq %rax, %rdx
jmp 0x4770
movq $-0x1, %rdx
shrl $0x4, %esi
andl $0xf8, %esi
movq %rdx, 0x8008(%rdi,%rsi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecDivuw
void ExecDivuw(State *state, uint32_t instr) {
    uint8_t rd = (instr >> 7) & SetNBits(5);
    uint8_t rs1 = (instr >> 15) & SetNBits(5);
    uint8_t rs2 = (instr >> 20) & SetNBits(5);

    if (state->x[rs2] == 0) {
        state->x[rd] = ~((uint64_t)0);
    } else {
        state->x[rd] = Sext((state->x[rs1] & SetNBits(32)) /
                                (state->x[rs2] & SetNBits(32)),
                            31);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0x11, %eax
andl $0xf8, %eax
movq 0x8008(%rdi,%rax), %rcx
testq %rcx, %rcx
je 0x4811
movl %esi, %eax
shrl $0xc, %eax
andl $0xf8, %eax
movl 0x8008(%rdi,%rax), %eax
xorl %edx, %edx
divl %ecx
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
orq %rax, %rcx
testl %eax, %eax
cmovnsq %rax, %rcx
jmp 0x4818
movq $-0x1, %rcx
shrl $0x4, %esi
andl $0xf8, %esi
movq %rcx, 0x8008(%rdi,%rsi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecCAddi
void ExecCAddi(State *state, uint16_t instr) {
    int32_t imm = Sext(
        ((instr >> 12 & SetNBits(1)) << 5) | (instr >> 2 & SetNBits(5)), 5);

    if (imm == 0) {
        Error("Invalid c.addi immediate");
    }
    uint8_t rd = instr >> 7 & SetNBits(5);

    state->x[rd] = state->x[rd] + imm;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl %esi, %r14d
shrl $0x7, %r14d
movl %r14d, %eax
andl $0x20, %eax
shrl $0x2, %esi
andl $0x1f, %esi
orl %eax, %esi
leaq -0x40(%rsi), %r15
testl %eax, %eax
cmoveq %rsi, %r15
testl %r15d, %r15d
jne 0x4d44
leaq 0x36a6(%rip), %rdi      # 0x83e3
xorl %eax, %eax
callq 0x6c10
andl $0x1f, %r14d
addq %r15, 0x8008(%rbx,%r14,8)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecCLui
void ExecCLui(State *state, uint16_t instr) {
    int32_t imm = Sext(((instr >> 12 & SetNBits(1)) << 17) |
                           ((instr >> 2 & SetNBits(5)) << 12),
                       17);
    uint8_t rd = (instr >> 7) & SetNBits(5);

    if (imm == 0)
        Error("Invalid c.lui operand");

    state->x[rd] = imm;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %eax
shll $0x5, %eax
andl $0x20000, %eax          # imm = 0x20000
movl %esi, %ecx
andl $0x7c, %ecx
shll $0xa, %ecx
orl %eax, %ecx
leaq -0x40000(%rcx), %r15
testl %eax, %eax
cmoveq %rcx, %r15
testl %r15d, %r15d
jne 0x4e62
leaq 0x35a1(%rip), %rdi      # 0x83fc
xorl %eax, %eax
callq 0x6c10
shrl $0x4, %ebx
andl $0xf8, %ebx
movq %r15, 0x8008(%r14,%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecCBeqz
void ExecCBeqz(State *state, uint16_t instr) {
    uint8_t rs1 = (instr >> 7) & SetNBits(3);
    int32_t imm = Sext(((instr >> 12 & SetNBits(1)) << 8) |
                           ((instr >> 5 & SetNBits(2)) << 6) |
                           ((instr >> 2 & SetNBits(1)) << 5) |
                           ((instr >> 10 & SetNBits(2)) << 3) |
                           ((instr >> 3 & SetNBits(2)) << 1),
                       8);

    if (state->x[8 + rs1] == 0)
        state->pc += imm;
    else
        state->pc += sizeof(instr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
shrl $0x4, %eax
movl %eax, %edx
andl $0x38, %edx
movl $0x2, %ecx
cmpq $0x0, 0x8048(%rdi,%rdx)
jne 0x4fc9
movl %esi, %ecx
shrl $0x7, %ecx
andl $0x100, %eax            # imm = 0x100
andl $0x18, %ecx
movl %esi, %edx
shrl $0x2, %edx
andl $0x6, %edx
orl %ecx, %edx
movl %esi, %ecx
andl $0x60, %ecx
andl $0x4, %esi
leal (%rdx,%rsi,8), %edx
leal (%rdx,%rcx,2), %edx
orl %eax, %edx
leaq -0x200(%rdx), %rcx
testl %eax, %eax
cmoveq %rdx, %rcx
addq %rcx, (%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecEcall
void ExecEcall(State *state, uint32_t instr) {
    // printf("ecall: Exception: pc: 0x%llx\n", state->pc);
    // printf("ecall: a0: %llx, a1: %llx, a7: %llx\n", state->x[10], state->x[11], state->x[17]);
    state->excepted = true;
    int exception_code;
    if (state->mode == 0x3) {
        exception_code = EnvironmentCallFromMMode;
    } else if (state->mode == 0x1) {
        exception_code = EnvironmentCallFromSMode;
    } else if (state->mode == 0x0) {
        exception_code = EnvironmentCallFromUMode;
    } else {
        state->excepted = false;
        return;
    }

    state->exception_code = exception_code;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb $0x1, 0x8138(%rdi)
movzbl 0x8148(%rdi), %eax
testl %eax, %eax
je 0x5889
cmpl $0x3, %eax
je 0x5882
cmpl $0x1, %eax
jne 0x5897
movl $0x9, %eax
jmp 0x588e
movl $0xb, %eax
jmp 0x588e
movl $0x8, %eax
movq %rax, 0x8140(%rdi)
jmp 0x589e
movb $0x0, 0x8138(%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecWfi
void ExecWfi(State *state, uint32_t instr) {
    printf("wfi\n");
    PrintRegisters(state, false);
    exit(state->x[10]);
    while (true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x2c83(%rip), %rdi      # 0x854a
callq 0x1060
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6f31
movl 0x8058(%rbx), %edi
callq 0x11b0
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cpu.c
// Function: ExecScd
void ExecScd(State *state, uint32_t instr) {
    uint8_t rd = instr >> 7 & SetNBits(5);
    uint8_t rs1 = instr >> 15 & SetNBits(5);
    uint8_t rs2 = instr >> 20 & SetNBits(5);
    uint8_t rl = instr >> 25 & SetNBits(1);
    uint8_t aq = instr >> 26 & SetNBits(1);

    int64_t t = Read64(state, state->x[rs1]);
    Write64(state, state->x[rs1], (uint64_t)(state->x[rs2]));
    state->x[rd] = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %r15d
shrl $0xc, %r15d
movl $0xf8, %r12d
andl %r12d, %r15d
movq 0x8008(%rdi,%r15), %rsi
callq 0x2239
movq 0x8008(%r14,%r15), %rsi
movl %ebx, %eax
shrl $0x11, %eax
andl %r12d, %eax
movq 0x8008(%r14,%rax), %rdx
movq %r14, %rdi
callq 0x2d15
shrl $0x4, %ebx
andl %r12d, %ebx
movq $0x0, 0x8008(%r14,%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cutils.c
// Function: GrowVec
void GrowVec(Vec *v, int n) {
    int size = (v->len + n) * sizeof(void *);
    if (v->cap >= size)
        return;

    while (v->cap < size)
        v->cap *= 2;
    v->data = realloc(v->data, v->cap);
    if (v->data == NULL)
        Error("Failed to allocate memory");
}

// Assembly:
addl 0x4(%rdi), %esi
shll $0x3, %esi
movl (%rdi), %eax
cmpl %esi, %eax
jge 0x6a5b
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
addl %eax, %eax
cmpl %esi, %eax
jl 0x6a37
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
movslq %eax, %rsi
callq 0x1170
movq %rax, 0x8(%rbx)
testq %rax, %rax
leaq 0x8(%rsp), %rsp
popq %rbx
popq %rbp
je 0x6a5c
retq
leaq 0x1aeb(%rip), %rdi      # 0x854e
xorl %eax, %eax
jmp 0x6c10
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/cutils.c
// Function: SetVec
void SetVec(Vec *v, int idx, void *item) {
    if (v->len <= idx || idx < 0) {
        Error("Index out of range in SetVec: %d", idx);
    }

    free(v->data[idx]);
    v->data[idx] = item;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
testl %esi, %esi
js 0x6aec
cmpl %r15d, 0x4(%r14)
jg 0x6afd
leaq 0x1a93(%rip), %rdi      # 0x8586
movl %r15d, %esi
xorl %eax, %eax
callq 0x6c10
movq 0x8(%r14), %rax
movslq %r15d, %r15
movq (%rax,%r15,8), %rdi
callq 0x1040
movq 0x8(%r14), %rax
movq %rbx, (%rax,%r15,8)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/elf.c
// Function: LoadElf
uint64_t LoadElf(State *state, size_t size, uint8_t *bin) {
    Elf64_Ehdr *ehdr = (Elf64_Ehdr *)bin;

    if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
        Error("Not an ELF file");
    } else if (ehdr->e_type != ET_EXEC) {
        Error("Not an executable ELF file");
    }

    uint64_t sh_size = sizeof(Elf64_Shdr);
    Elf64_Shdr *shstrtab =
        (Elf64_Shdr *)(bin + ehdr->e_shoff + (sh_size * ehdr->e_shstrndx));

    char *strtab = (char *)(bin + shstrtab->sh_offset);

    uint64_t text_addr;
    bool tohost;
    for (uint64_t i = 0; i < sh_size * ehdr->e_shnum; i += sh_size) {
        Elf64_Shdr *shdr = (Elf64_Shdr *)(bin + ehdr->e_shoff + i);
        if (shdr->sh_type == SHT_PROGBITS) {
            uint64_t virtual_addr = shdr->sh_addr;
            if (virtual_addr == 0)
                continue;

            uint8_t *text = (uint8_t *)(bin + shdr->sh_offset);
            size_t text_size = shdr->sh_size;
            char *name = (strtab + shdr->sh_name);
            printf("%s: 0x%llx\n", name, virtual_addr);
            if (!strcmp(name, ".text")) {
                text_addr = virtual_addr;
            }

            LoadBinaryIntoMemory(state, text, text_size, virtual_addr - DRAM_BASE);
        }
    }

    return ehdr->e_entry;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, -0x38(%rbp)
cmpl $0x464c457f, (%rdx)     # imm = 0x464C457F
je 0x6b49
leaq 0x1a65(%rip), %rdi      # 0x85ac
jmp 0x6b57
cmpw $0x2, 0x10(%rbx)
je 0x6b5e
leaq 0x1a65(%rip), %rdi      # 0x85bc
xorl %eax, %eax
callq 0x6c10
movzwl 0x3c(%rbx), %eax
testw %ax, %ax
je 0x6bfc
movq 0x28(%rbx), %rcx
addq %rbx, %rcx
movzwl 0x3e(%rbx), %edx
shll $0x6, %edx
movq 0x18(%rdx,%rcx), %rcx
addq %rbx, %rcx
movq %rcx, -0x30(%rbp)
leaq 0x20(%rbx), %r15
xorl %r14d, %r14d
movq 0x28(%rbx), %rcx
addq %r15, %rcx
cmpl $0x1, -0x1c(%r14,%rcx)
jne 0x6bed
movq -0x10(%r14,%rcx), %r12
testq %r12, %r12
je 0x6bed
movq -0x8(%r14,%rcx), %r13
addq %rbx, %r13
movq (%r14,%rcx), %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rcx,%r14), %esi
addq -0x30(%rbp), %rsi
leaq 0x1a12(%rip), %rdi      # 0x85d7
movq %r12, %rdx
xorl %eax, %eax
callq 0x10b0
addq $-0x80000000, %r12      # imm = 0x80000000
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movq -0x40(%rbp), %rdx
movq %r12, %rcx
callq 0x6e4e
movzwl 0x3c(%rbx), %eax
addq $0x40, %r14
movzwl %ax, %ecx
shll $0x6, %ecx
cmpq %rcx, %r14
jb 0x6b8c
movq 0x18(%rbx), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/main.c
// Function: Error
void Error(const char *fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    va_end(ap);
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
leaq -0xe0(%rbp), %rdi
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %r8, 0x20(%rdi)
movq %r9, 0x28(%rdi)
testb %al, %al
je 0x6c6b
movaps %xmm0, -0xb0(%rbp)
movaps %xmm1, -0xa0(%rbp)
movaps %xmm2, -0x90(%rbp)
movaps %xmm3, -0x80(%rbp)
movaps %xmm4, -0x70(%rbp)
movaps %xmm5, -0x60(%rbp)
movaps %xmm6, -0x50(%rbp)
movaps %xmm7, -0x40(%rbp)
leaq -0x30(%rbp), %r14
movq %rdi, 0x10(%r14)
leaq 0x10(%rbp), %rax
movq %rax, 0x8(%r14)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%r14)
movq 0x6369(%rip), %r15      # 0xcff8
movq (%r15), %rcx
leaq 0x194a(%rip), %rdi      # 0x85e3
movl $0x7, %esi
movl $0x1, %edx
callq 0x11c0
movq (%r15), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1190
movq (%r15), %rsi
movl $0xa, %edi
callq 0x10f0
movl $0x1, %edi
callq 0x11b0
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/main.c
// Function: NewUart
Uart *NewUart() {
    Uart *uart = calloc(1, sizeof(Uart));
    WINDOW *w = initscr();
    cbreak();
    nodelay(w, true);
    noecho();
    scrollok(w, true);
    uart->lsr |= 0x20;
    return uart;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl $0x1, %edi
movl $0x10b, %esi            # imm = 0x10B
callq 0x1100
movq %rax, %rbx
callq 0x10d0
movq %rax, %r14
callq 0x1140
movq %r14, %rdi
movl $0x1, %esi
callq 0x1030
callq 0x10a0
movq %r14, %rdi
movl $0x1, %esi
callq 0x1050
movb $0x20, 0x6(%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/main.c
// Function: ReadBinaryFile
size_t ReadBinaryFile(const char *name, uint8_t **buf) {
    FILE *fp = fopen(name, "rb");
    if (fp == NULL) {
        Error("Can't open the file: %s.", name);
    }

    fseek(fp, 0, SEEK_END);
    size_t size = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    uint8_t *result = malloc(size);
    fread(result, size, 1, fp);
    *buf = result;
    fclose(fp);
    return size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x1771(%rip), %rsi      # 0x85eb
callq 0x1180
testq %rax, %rax
je 0x6ee2
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1160
movq %r14, %rdi
callq 0x1120
movq %rax, %r15
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1160
movq %r15, %rdi
callq 0x1150
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x1070
movq %r12, (%rbx)
movq %r14, %rdi
callq 0x1090
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1705(%rip), %rdi      # 0x85ee
movq %r15, %rsi
xorl %eax, %eax
callq 0x6c10
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/main.c
// Function: CPUMain
void CPUMain(State *state, uint64_t start_addr, size_t code_size,
             bool is_debug) {
    uint64_t count = 0;
    state->pc = start_addr;
    for (;;) {
        uint64_t bpc = state->pc;
        count++;
        if (is_debug && count >= 10000)
            return;
        
        // printf("pc: %llx\n", state->pc);
        Tick(state);
        if (state->pc == 0) {
            // printf("pc: %llx -> 0, sp: %llx\n", Translate(state, bpc, AccessInstruction), state->x[2]);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdi, %r14
movq %rsi, (%rdi)
movl $0x2, %r15d
movq %r14, %rdi
callq 0x19e1
cmpq $0x2710, %r15           # imm = 0x2710
setae %al
andb %bl, %al
incq %r15
cmpb $0x1, %al
jne 0x6f0b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/main.c
// Function: main
int main(int argc, char **argv) {
    if (argc < 2) {
        Error("Missing argument, at least 1 argument required.");
    }

    int prog_name_idx = 1;
    bool is_debug = false;
    if (!strcmp(argv[1], "--debug")) {
        is_debug = true;
        prog_name_idx++;
    } else if (!strcmp(argv[1], "--test")) {
        RunTest();
        return 0;
    }

    uint8_t *bin;
    size_t size = ReadBinaryFile(argv[prog_name_idx++], &bin);
    State *state = NewState(0x9000000/*0x7A12000*/);
    ResetState(state);

    if (argc > prog_name_idx && !strcmp(argv[prog_name_idx], "--disk")) {
        char *name = argv[++prog_name_idx];
        uint8_t *data;
        ReadBinaryFile(name, &data);
        SetDisk(state, data);
        prog_name_idx += 2;
    }

    uint64_t addr = LoadElf(state, size, bin);

    state->x[1] = (uint64_t)(-2);

    CPUMain(state, addr, size, is_debug);

    PrintRegisters(state, is_debug);
    int32_t result;
    result = state->x[10];

    free(bin);
    free(state->mem);
    free(state);
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x1, %edi
jle 0x7109
movq %rsi, %r15
movl %edi, %r12d
movq 0x8(%rsi), %r14
leaq 0x1690(%rip), %rsi      # 0x864d
movq %r14, %rdi
callq 0x1110
movl %eax, %ebx
testl %eax, %eax
je 0x6ff2
leaq 0x1683(%rip), %rsi      # 0x8655
movq %r14, %rdi
callq 0x1110
movl $0x1, %r13d
testl %eax, %eax
jne 0x6ff8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x71ba
jmp 0x70f8
movl $0x2, %r13d
movl %r13d, %eax
incl %r13d
movq %rax, -0x30(%rbp)
movq (%r15,%rax,8), %rdi
leaq -0x40(%rbp), %rsi
callq 0x6e62
movq %rax, -0x38(%rbp)
movl $0x1, %edi
movl $0x8150, %esi           # imm = 0x8150
callq 0x1100
movq %rax, %r14
movl $0x1, %edi
movl $0x9000000, %esi        # imm = 0x9000000
callq 0x1100
movq %rax, 0x8108(%r14)
movq %r14, %rdi
callq 0x6da1
cmpl %r12d, %r13d
jae 0x7082
movl %r13d, %eax
movq (%r15,%rax,8), %rdi
leaq 0x1606(%rip), %rsi      # 0x865c
callq 0x1110
testl %eax, %eax
jne 0x7082
movq -0x30(%rbp), %rax
movq 0x10(%r15,%rax,8), %rdi
leaq -0x48(%rbp), %r15
movq %r15, %rsi
callq 0x6e62
movq (%r15), %rax
movq 0x8130(%r14), %rcx
movq %rax, 0x40(%rcx)
movq -0x40(%rbp), %r15
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movq %r15, %rdx
callq 0x6b20
movq $-0x2, 0x8010(%r14)
movq %rax, (%r14)
movl $0x2, %r12d
testl %ebx, %ebx
sete %r13b
movq %r14, %rdi
callq 0x19e1
cmpq $0x2710, %r12           # imm = 0x2710
setae %al
andb %r13b, %al
incq %r12
cmpb $0x1, %al
jne 0x70a9
movq %r14, %rdi
xorl %esi, %esi
callq 0x6f31
movl 0x8058(%r14), %ebx
movq %r15, %rdi
callq 0x1040
movq 0x8108(%r14), %rdi
callq 0x1040
movq %r14, %rdi
callq 0x1040
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x150d(%rip), %rdi      # 0x861d
xorl %eax, %eax
callq 0x6c10
nop
// File: /workspace/github_c_makefile_star2_O3/hobo0xcc[P]rve/src/test.c
// Function: RunTest
void RunTest() {
    State *state = NewState(1000);
    ResetState(state);

    state->csr[MSTATUS] = 0;
    WriteCSR(state, MSTATUS, 0, 1, 3);
    assert(state->csr[MSTATUS] == 3);

    state->csr[MSTATUS] = 0;
    WriteCSR(state, MSTATUS, 2, 2, 1);
    assert(state->csr[MSTATUS] == 4);

    state->csr[MSTATUS] = 0;
    WriteCSR(state, MSTATUS, 0, 63, 20);
    assert(ReadCSR(state, MSTATUS, 0, 4) == 20);

    Write8(state, CLINT_BASE, 0x0e);
    assert(Read8(state, CLINT_BASE) == 0x0e);

    assert(GetRange(10, 2, 3) == 2);

    state->x[1] = 0xffffffff80000000;
    state->x[2] = 0xffffffffffff8000;
    printf("a: %lld\n", mulhsu(state->x[1], state->x[2]));
    uint32_t instr = 0x0220a733;
    ExecMulhsu(state, instr);
    printf("%lld, %lld, %lld\n", state->x[1], state->x[2], state->x[14]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x6d69
movq %rax, %rbx
movq %rax, %rdi
callq 0x6da1
movq $0x0, 0x1808(%rbx)
movl $0x3, %r8d
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
movl $0x1, %ecx
callq 0x14d4
cmpq $0x3, 0x1808(%rbx)
jne 0x7327
movq $0x0, 0x1808(%rbx)
movl $0x1, %r8d
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
movl $0x2, %edx
movl $0x2, %ecx
callq 0x14d4
cmpq $0x4, 0x1808(%rbx)
jne 0x7346
movq $0x0, 0x1808(%rbx)
movl $0x14, %r8d
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
movl $0x3f, %ecx
callq 0x14d4
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
movl $0x4, %ecx
callq 0x1475
cmpq $0x14, %rax
jne 0x7365
movl $0x2000000, %esi        # imm = 0x2000000
movq %rbx, %rdi
movl $0xe, %edx
callq 0x232a
movl $0x2000000, %esi        # imm = 0x2000000
movq %rbx, %rdi
callq 0x22f4
cmpb $0xe, %al
jne 0x7384
movl $0xa, %edi
movl $0x2, %esi
movl $0x3, %edx
callq 0x12ff
cmpq $0x2, %rax
jne 0x73a3
movq $-0x80000000, 0x8010(%rbx) # imm = 0x80000000
movq $-0x8000, 0x8018(%rbx) # imm = 0x8000
leaq 0x1429(%rip), %rdi      # 0x870c
movq $-0x80000000, %rsi      # imm = 0x80000000
xorl %eax, %eax
callq 0x10b0
movq %rbx, %rdi
movl $0x220a733, %esi        # imm = 0x220A733
callq 0x332a
movq 0x8010(%rbx), %rsi
movq 0x8018(%rbx), %rdx
movq 0x8078(%rbx), %rcx
leaq 0x13fb(%rip), %rdi      # 0x8715
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x10b0
leaq 0x1335(%rip), %rdi      # 0x8663
leaq 0x1347(%rip), %rsi      # 0x867c
leaq 0x134b(%rip), %rcx      # 0x8687
movl $0x27, %edx
callq 0x10c0
leaq 0x1349(%rip), %rdi      # 0x8696
leaq 0x1328(%rip), %rsi      # 0x867c
leaq 0x132c(%rip), %rcx      # 0x8687
movl $0x2b, %edx
callq 0x10c0
leaq 0x1343(%rip), %rdi      # 0x86af
leaq 0x1309(%rip), %rsi      # 0x867c
leaq 0x130d(%rip), %rcx      # 0x8687
movl $0x2f, %edx
callq 0x10c0
leaq 0x1348(%rip), %rdi      # 0x86d3
leaq 0x12ea(%rip), %rsi      # 0x867c
leaq 0x12ee(%rip), %rcx      # 0x8687
movl $0x32, %edx
callq 0x10c0
leaq 0x134a(%rip), %rdi      # 0x86f4
leaq 0x12cb(%rip), %rsi      # 0x867c
leaq 0x12cf(%rip), %rcx      # 0x8687
movl $0x34, %edx
callq 0x10c0
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/benchmark.c
// Function: finished_single_op
void finished_single_op() {
  if (FLAGS_histogram || FLAGS_raw) {
    double now = now_micros() * 1e-6;
    double micros = (now - last_op_finish_) * 1e6;
    if (FLAGS_histogram) {
      histogram_add(&hist_, micros);
      if (micros > 20000) {
        fprintf(stderr, "long op: %.1f micros%30s\r", micros, "");
        fflush(stderr);
      }
    }
    if (FLAGS_raw) {
      raw_add(&raw_, micros);
    }
    last_op_finish_ = now;
  }

  done_++;
  if (done_ >= next_report_) {
    if      (next_report_ < 1000)   next_report_ += 100;
    else if (next_report_ < 5000)   next_report_ += 500;
    else if (next_report_ < 10000)  next_report_ += 1000;
    else if (next_report_ < 50000)  next_report_ += 5000;
    else if (next_report_ < 100000) next_report_ += 10000;
    else if (next_report_ < 500000) next_report_ += 50000;
    else                            next_report_ += 100000;
    fprintf(stderr, "... finished %d ops%30s\r", done_, "");
    fflush(stderr);
  }
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
movq $0x5a4854, %rbx         # imm = 0x5A4854
cmpb $0x0, (%rbx)
jne 0x402ca9
movq $0x5a4855, %rax         # imm = 0x5A4855
cmpb $0x1, (%rax)
jne 0x402d3f
callq 0x47c898
movq %rax, %xmm0
punpckldq 0x147355(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14735d(%rip), %xmm0   # 0x54a020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x147359(%rip), %xmm1   # 0x54a030
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
subsd 0x1a15e7(%rip), %xmm0   # 0x5a42d0
mulsd 0x147347(%rip), %xmm0   # 0x54a038
cmpb $0x1, (%rbx)
jne 0x402d1a
leaq 0x1a15db(%rip), %rdi    # 0x5a42d8
movapd %xmm0, (%rsp)
movaps (%rsp), %xmm0
callq 0x4037b1
movapd (%rsp), %xmm0
ucomisd 0x147328(%rip), %xmm0   # 0x54a040
ja 0x402d64
movq $0x5a4855, %rax         # imm = 0x5A4855
cmpb $0x1, (%rax)
jne 0x402d32
leaq 0x1a1aa3(%rip), %rdi    # 0x5a47d0
callq 0x4042c0
movaps 0x10(%rsp), %xmm0
movsd %xmm0, 0x1a1591(%rip)   # 0x5a42d0
movl 0x1a1aa3(%rip), %esi    # 0x5a47e8
incl %esi
movl %esi, 0x1a1a9b(%rip)    # 0x5a47e8
movl 0x1a1a99(%rip), %edi    # 0x5a47ec
cmpl %edi, %esi
jge 0x402d5d
addq $0x20, %rsp
popq %rbx
retq
callq 0x401926
jmp 0x402d57
movaps (%rsp), %xmm0
callq 0x4018fd
movapd (%rsp), %xmm0
jmp 0x402d1a
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/benchmark.c
// Function: benchmark_init
void benchmark_init() {
  db_ = NULL;
  db_num_ = 0;
  num_ = FLAGS_num;
  reads_ = FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads;
  bytes_ = 0;
  rand_gen_init(&gen_, FLAGS_compression_ratio);
  rand_init(&rand_, 301);;

  struct dirent* ep;
  DIR* test_dir = opendir(FLAGS_db);
  if (!FLAGS_use_existing_db) {
    while ((ep = readdir(test_dir)) != NULL) {
      if (starts_with(ep->d_name, "dbbench_sqlite3")) {
        char file_name[1000];
        strcpy(file_name, FLAGS_db);
        strcat(file_name, ep->d_name);
        remove(file_name);
      }
    }
  }
  closedir(test_dir);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f0, %rsp            # imm = 0x3F0
xorl %eax, %eax
movq %rax, 0x1a1a63(%rip)    # 0x5a47f0
movl $0x0, 0x1a1a61(%rip)    # 0x5a47f8
movq $0x5a4848, %rcx         # imm = 0x5A4848
movl (%rcx), %ecx
movl %ecx, 0x1a1a56(%rip)    # 0x5a47fc
movq $0x5a484c, %rdx         # imm = 0x5A484C
movl (%rdx), %edx
testl %edx, %edx
cmovsl %ecx, %edx
movl %edx, 0x1a1a46(%rip)    # 0x5a4800
movq %rax, 0x1a1a47(%rip)    # 0x5a4808
movq $0x5a4858, %rax         # imm = 0x5A4858
movsd (%rax), %xmm0
leaq 0x1a1a3d(%rip), %rdi    # 0x5a4810
callq 0x4040ca
leaq 0x1a1a49(%rip), %rdi    # 0x5a4828
movl $0x12d, %esi            # imm = 0x12D
callq 0x404060
movq $0x5a4870, %r13         # imm = 0x5A4870
movq (%r13), %rdi
callq 0x4e3cd0
movq %rax, %rbx
movq $0x5a4868, %rax         # imm = 0x5A4868
cmpb $0x0, (%rax)
jne 0x402e64
movq %rbx, %rdi
callq 0x4e3f30
testq %rax, %rax
je 0x402e64
movq %rax, %r12
leaq 0x147264(%rip), %r14    # 0x54a083
movq %rsp, %r15
addq $0x13, %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x47c8bb
testb %al, %al
je 0x402e54
movq (%r13), %rsi
movq %r15, %rdi
callq 0x401020
movq %r15, %rdi
movq %r12, %rsi
callq 0x401068
movq %r15, %rdi
callq 0x486b70
movq %rbx, %rdi
callq 0x4e3f30
movq %rax, %r12
testq %rax, %rax
jne 0x402e22
movq %rbx, %rdi
callq 0x4e3f00
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/benchmark.c
// Function: start
static void start() {
  start_ =  now_micros() * 1e-6;
  bytes_ = 0;
  message_ = malloc(sizeof(char) * 10000);
  strcpy(message_, "");
  last_op_finish_ = start_;
  histogram_clear(&hist_);
  raw_clear(&raw_);
  done_ = 0;
  next_report_ = 100;
}

// Assembly:
subq $0x18, %rsp
callq 0x47c898
movq %rax, %xmm0
punpckldq 0x146f5c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x146f64(%rip), %xmm0   # 0x54a020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x146f60(%rip), %xmm1   # 0x54a030
movapd %xmm1, (%rsp)
movsd %xmm1, 0x1a175b(%rip)   # 0x5a4838
movq $0x0, 0x1a1720(%rip) # 0x5a4808
movl $0x2710, %edi           # imm = 0x2710
callq 0x4a7390
movq %rax, 0x1a1737(%rip)    # 0x5a4830
movb $0x0, (%rax)
movaps (%rsp), %xmm0
movsd %xmm0, 0x1a11c8(%rip)   # 0x5a42d0
leaq 0x1a11c9(%rip), %rdi    # 0x5a42d8
callq 0x403794
leaq 0x1a16b5(%rip), %rdi    # 0x5a47d0
callq 0x40428c
movl $0x0, 0x1a16be(%rip)    # 0x5a47e8
movl $0x64, 0x1a16b8(%rip)   # 0x5a47ec
addq $0x18, %rsp
retq
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/histogram.c
// Function: histogram_add
void histogram_add(Histogram* hist_, double value) {
  int b = 0;
  while (b < kNumBuckets - 1 && bucket_limit[b] <= value) {
    b++;
  }
  hist_->buckets_[b] += 1.0;
  if (hist_->min_ > value) hist_->min_ = value;
  if (hist_->max_ < value) hist_->max_ = value;
  hist_->num_++;
  hist_->sum_ += value;
  hist_->sum_squares_ += (value * value);
}

// Assembly:
leaq 0x146d58(%rip), %rcx    # 0x54a510
xorl %eax, %eax
ucomisd (%rcx), %xmm0
jb 0x4037d4
incq %rax
addq $0x8, %rcx
cmpq $0x99, %rax
jne 0x4037ba
movl $0x99, %eax
movl %eax, %eax
movsd 0x28(%rdi,%rax,8), %xmm1
addsd 0x146cfc(%rip), %xmm1   # 0x54a4e0
movsd %xmm1, 0x28(%rdi,%rax,8)
movsd (%rdi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4037f8
movsd %xmm0, (%rdi)
ucomisd 0x8(%rdi), %xmm0
jbe 0x403804
movsd %xmm0, 0x8(%rdi)
movupd 0x10(%rdi), %xmm1
movapd 0x146cef(%rip), %xmm2   # 0x54a500
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
addpd %xmm1, %xmm2
movupd %xmm2, 0x10(%rdi)
mulsd %xmm0, %xmm0
addsd 0x20(%rdi), %xmm0
movsd %xmm0, 0x20(%rdi)
retq
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/histogram.c
// Function: histogram_merge
void histogram_merge(Histogram* hist_, const Histogram* other_) {
  if (other_->min_ < hist_->min_) hist_->min_ = other_->min_;
  if (other_->max_ > hist_->max_) hist_->max_ = other_->max_;
  hist_->num_ += other_->num_;
  hist_->sum_ += other_->sum_;
  hist_->sum_squares_ += other_->sum_squares_;
  for (int b = 0; b < kNumBuckets; b++) {
    hist_->buckets_[b] += other_->buckets_[b];
  }
}

// Assembly:
movsd (%rsi), %xmm0
movsd (%rdi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x40383f
movsd %xmm0, (%rdi)
movsd 0x8(%rsi), %xmm0
ucomisd 0x8(%rdi), %xmm0
jbe 0x403850
movsd %xmm0, 0x8(%rdi)
movupd 0x10(%rsi), %xmm0
movupd 0x10(%rdi), %xmm1
addpd %xmm0, %xmm1
movupd %xmm1, 0x10(%rdi)
movsd 0x20(%rsi), %xmm0
addsd 0x20(%rdi), %xmm0
movsd %xmm0, 0x20(%rdi)
movl $0x5, %eax
movsd (%rsi,%rax,8), %xmm0
addsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%rdi,%rax,8)
incq %rax
cmpq $0x9f, %rax
jne 0x403877
retq
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/random.c
// Function: rand_init
void rand_init(Random* rand_, uint32_t s) {
  rand_->seed_ = s & 0x7fffffffu;
  /* Avoid bad seeds. */
  if (rand_->seed_ == 0 || rand_->seed_ == 2147483647L) {
    rand_->seed_ = 1;
  }
}

// Assembly:
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %esi
movl %esi, (%rdi)
cmpl %eax, %esi
je 0x404071
testl %esi, %esi
jne 0x404077
movl $0x1, (%rdi)
retq
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/random.c
// Function: rand_gen_init
void rand_gen_init(RandomGenerator* gen_, double compression_ratio) {
  Random rnd;
  char* piece;
  
  gen_->data_ = malloc(sizeof(char) * 1048576);
  gen_->data_size_ = 0;
  gen_->pos_ = 0;
  (gen_->data_)[0] = '\0';

  rand_init(&rnd, 301);
  while (gen_->data_size_ < 1048576) {
    piece = compressible_string(&rnd, compression_ratio, 100);
    strcat(gen_->data_, piece);
    gen_->data_size_ += strlen(piece);
  }

  free(piece);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
movl $0x100000, %edi         # imm = 0x100000
callq 0x4a7390
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movq %rbx, 0x10(%rsp)
movl $0x0, 0x10(%rbx)
movsd 0x8(%rsp), %xmm0
mulsd 0x1463e0(%rip), %xmm0   # 0x54a4f0
cvttsd2si %xmm0, %ecx
cmpl $0x2, %ecx
movl $0x1, %ebp
cmovgel %ecx, %ebp
movb $0x0, (%rax)
leal 0x1(%rbp), %eax
movq %rax, 0x8(%rsp)
movl $0x12d, %r14d           # imm = 0x12D
movq 0x8(%rsp), %rdi
callq 0x4a7390
movq %rax, %r15
xorl %eax, %eax
movl %r14d, %ecx
imulq $0x41a7, %rcx, %rcx     # imm = 0x41A7
movq %rcx, %rdx
shrq $0x1f, %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leal (%rdx,%rcx), %r14d
addl $0x80000001, %r14d      # imm = 0x80000001
addl %ecx, %edx
cmovnsl %edx, %r14d
imulq $0x58ed2309, %r14, %rcx # imm = 0x58ED2309
shrq $0x20, %rcx
movl %r14d, %edx
subl %ecx, %edx
shrl %edx
addl %ecx, %edx
shrl $0x6, %edx
imull $0x5f, %edx, %ecx
movl %r14d, %edx
subl %ecx, %edx
addb $0x20, %dl
movb %dl, (%r15,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x40413f
xorl %ebx, %ebx
movb %bl, (%r15,%rbp)
movq %r15, %rdi
callq 0x401100
movq %rax, %r13
movl $0x65, %edi
callq 0x4a7390
movq %rax, %r12
movb %bl, (%rax)
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x401068
addl %r13d, %ebx
movslq %ebx, %rbx
cmpq $0x64, %rbx
jb 0x4041b7
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x401068
movq %r12, %rdi
callq 0x401100
addq 0x8(%rbx), %rax
movq %rax, 0x8(%rbx)
cmpq $0x100000, %rax         # imm = 0x100000
jb 0x404130
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4a76d0
// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/random.c
// Function: rand_gen_generate
char* rand_gen_generate(RandomGenerator* gen_, int len) {
  if (gen_->pos_ + len > gen_->data_size_) {
    gen_->pos_ = 0;
    assert(len < gen_->data_size_);
  }
  gen_->pos_ += len;
  char* substr = malloc(sizeof(char) * (len + 1));
  strncpy(substr, (gen_->data_) + gen_->pos_ - len, len);

  return substr;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x10(%rdi), %r15d
leal (%r15,%rsi), %eax
movslq %eax, %rcx
movq 0x8(%rdi), %rax
cmpq %rcx, %rax
jae 0x40425d
movl $0x0, 0x10(%rbx)
movslq %esi, %r14
xorl %r15d, %r15d
cmpq %r14, %rax
ja 0x404260
leaq 0x146f36(%rip), %rdi    # 0x54b17b
leaq 0x146f46(%rip), %rsi    # 0x54b192
leaq 0x146f48(%rip), %rcx    # 0x54b19b
movl $0x5b, %edx
callq 0x47f6a0
movslq %esi, %r14
addl %esi, %r15d
movl %r15d, 0x10(%rbx)
incl %esi
movslq %esi, %rdi
callq 0x4a7390
movslq %r15d, %rsi
addq (%rbx), %rsi
subq %r14, %rsi
movq %rax, %rdi
movq %r14, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x401098
nop