LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/pi32cipher256v2/ref3/pi-cipher.c
// Function: pi32_encrypt_simple
void PI_ENCRYPT_SIMPLE(
        void *cipher,
        size_t *cipher_len_B,
        const void *msg,
        size_t msg_len_B,
        const void *ad,
        size_t ad_len_B,
        const void *nonce_secret,
        const void *nonce_public,
        size_t nonce_public_len_B,
        const void *key,
        size_t key_len_B
        )
{
    unsigned i;
    PI_CTX ctx;
    if (PI_INIT(&ctx, key, key_len_B, nonce_public, nonce_public_len_B)) {
        printf("ERROR! <%s %s %d>\n", __FILE__, __func__, __LINE__);
        return;
    }
    i = 1;
    while (ad_len_B >= PI_AD_BLOCK_LENGTH_BYTES) {
        PI_PROCESS_AD_BLOCK(&ctx, ad, i++);
        ad_len_B -= PI_AD_BLOCK_LENGTH_BYTES;
        ad = &((const uint8_t*)ad)[PI_AD_BLOCK_LENGTH_BYTES];
    }
    PI_PROCESS_AD_LAST_BLOCK(&ctx, ad, ad_len_B, i);
    *cipher_len_B = 0;
    if (nonce_secret) {
        PI_ENCRYPT_SMN(&ctx, cipher, nonce_secret);
        *cipher_len_B += PI_CT_BLOCK_LENGTH_BYTES;
        cipher = &((uint8_t*)cipher)[PI_CT_BLOCK_LENGTH_BYTES];
    }
    i = 1;
    while (msg_len_B >= PI_PT_BLOCK_LENGTH_BYTES) {
        PI_ENCRYPT_BLOCK(&ctx, cipher, msg, i++);
        msg = &((const uint8_t*)msg)[PI_PT_BLOCK_LENGTH_BYTES];
        cipher = &((uint8_t*)cipher)[PI_CT_BLOCK_LENGTH_BYTES];
        *cipher_len_B += PI_CT_BLOCK_LENGTH_BYTES;
        msg_len_B -= PI_PT_BLOCK_LENGTH_BYTES;
    }
    PI_ENCRYPT_LAST_BLOCK(&ctx, cipher, msg, msg_len_B, i);
    *cipher_len_B += msg_len_B;
    cipher = &((uint8_t*)cipher)[msg_len_B];
    PI_EXTRACT_TAG(&ctx, cipher);
    *cipher_len_B += PI_TAG_BYTES;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r13
movq %r8, %rbp
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
movq 0xb8(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x10(%rsp), %rdi
callq 0x1100
testl %eax, %eax
jne 0x1c20
movl $0x1, %ecx
cmpq $0x20, %r13
movq %r14, 0x8(%rsp)
jb 0x1b78
movl $0x1, %r14d
movl %r14d, %edx
incl %r14d
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x10c0
addq $-0x20, %r13
addq $0x20, %rbp
cmpq $0x1f, %r13
ja 0x1b4f
movl %r14d, %ecx
movq 0x8(%rsp), %r14
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1030
movq $0x0, (%r14)
movq 0xb0(%rsp), %rdx
testq %rdx, %rdx
je 0x1bb1
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x10a0
addq $0x20, (%r14)
addq $0x20, %r15
movl $0x1, %r8d
cmpq $0x20, %rbx
jb 0x1bf2
movl $0x1, %ebp
leaq 0x10(%rsp), %r13
movl %ebp, %ecx
incl %ebp
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1050
addq $0x20, %r12
addq $0x20, %r15
addq $0x20, (%r14)
addq $-0x20, %rbx
cmpq $0x1f, %rbx
ja 0x1bc7
movl %ebp, %r8d
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1070
movq 0x8(%rsp), %rax
addq %rbx, (%rax)
vmovups 0x40(%r14), %ymm0
vmovups %ymm0, (%r15,%rbx)
addq $0x20, (%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/pi32cipher256v2/ref3/pi-cipher.c
// Function: ast
static inline void mu(
        word_t dest[4],
        const word_t x[4])
{
    word_t sum;
    dest[0] = rotl(PI_MU_CONST_0 + x[0] + x[1] + x[2], PI_MU_ROT_CONST_0 );
    dest[1] = rotl(PI_MU_CONST_1 + x[0] + x[1] + x[3], PI_MU_ROT_CONST_1 );
    dest[2] = rotl(PI_MU_CONST_2 + x[0] + x[2] + x[3], PI_MU_ROT_CONST_2 );
    dest[3] = rotl(PI_MU_CONST_3 + x[1] + x[2] + x[3], PI_MU_ROT_CONST_3 );
    sum = dest[0] ^ dest[1] ^ dest[2] ^ dest[3];
    dest[0] ^= sum;
    dest[1] ^= sum;
    dest[2] ^= sum;
    dest[3] ^= sum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movl (%rsi), %r8d
movl 0x4(%rsi), %r9d
movl 0x8(%rsi), %r10d
leal (%r9,%r8), %eax
leal -0xf171b1e(%r10,%rax), %ecx
rorxl $0x1b, %ecx, %ecx
movl 0xc(%rsi), %r11d
addl %r11d, %eax
addl $0xe1d8d4d2, %eax       # imm = 0xE1D8D4D2
rorxl $0x15, %eax, %eax
addl %r10d, %r8d
leal (%r11,%r8), %esi
addl $0xd1cccac9, %esi       # imm = 0xD1CCCAC9
rorxl $0xf, %esi, %esi
addl %r9d, %r10d
leal (%r11,%r10), %r8d
addl $0xc6c5c3b8, %r8d       # imm = 0xC6C5C3B8
rorxl $0x9, %r8d, %r9d
movl %esi, %r8d
xorl %eax, %r8d
xorl %r8d, %ecx
movl 0x8(%rdx), %r10d
movl 0xc(%rdx), %ebx
movl (%rdx), %r14d
movl 0x4(%rdx), %r15d
leal (%r10,%r14), %r11d
leal (%rbx,%r11), %edx
addl $0xb4b2b1ac, %edx       # imm = 0xB4B2B1AC
rorxl $0x1d, %edx, %edx
addl %ebx, %r10d
addl %r15d, %r10d
addl $0xaaa9a6a5, %r10d      # imm = 0xAAA9A6A5
rorxl $0x16, %r10d, %r10d
addl %r15d, %r11d
addl $0xa39c9a99, %r11d      # imm = 0xA39C9A99
rorxl $0xd, %r11d, %r11d
addl %r14d, %ebx
addl %r15d, %ebx
addl $0x9695938e, %ebx       # imm = 0x9695938E
rorxl $0x3, %ebx, %ebx
movl %r10d, %ebp
xorl %r11d, %ebp
xorl %ebp, %edx
movl %edx, %r14d
xorl %ebx, %r14d
xorl %r14d, %r10d
addl %ecx, %r10d
xorl %r9d, %ecx
xorl %r9d, %r8d
xorl %ecx, %eax
xorl %esi, %ecx
xorl %ebx, %ebp
addl %ecx, %ebp
xorl %r11d, %r14d
addl %r8d, %r14d
movl %ebp, 0xc(%rdi)
movl %r10d, (%rdi)
movl %r14d, 0x4(%rdi)
addl %eax, %edx
movl %edx, 0x8(%rdi)
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: is_executable
int is_executable(const char *filename)
{
    struct stat st;

    if (stat(filename, &st) != 0) {
        fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
        return 0;
    }
    if (!(st.st_mode & S_IXUSR)) {
        fprintf(stderr, "[-] %s: not executable\n", filename);
        return 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
callq 0x1100
testl %eax, %eax
jne 0x1521
movl $0x1, %ebp
testb $0x40, 0x20(%rsp)
je 0x152d
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %rbp
retq
movq %rbx, %rdi
callq 0x11eb
xorl %ebp, %ebp
jmp 0x1515
movq 0x2ac4(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xad2(%rip), %rsi       # 0x2010
xorl %ebp, %ebp
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10f0
jmp 0x1515
// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: get_results
struct wcresults
get_results(int fd)
{
    struct wcresults results;

    results.line_count = get_integer(fd);
    results.word_count = get_integer(fd);
    results.char_count = get_integer(fd);

    return results;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %edi
callq 0x16be
movq %rax, (%r14)
movl %ebx, %edi
callq 0x16be
movq %rax, 0x8(%r14)
movl %ebx, %edi
callq 0x16be
movq %rax, 0x10(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: get_integer
static long
get_integer(int fd)
{
    int state = 0;
    long result = -1;

    for (;;) {
        char c;
        int count;

        count = read(fd, &c, 1);
        if (count <= 0)
            return -1;

        switch (state) {
        case 0:
            if (c == '\n')
                return -1;
            if (isspace(c))
                continue;
            if (isdigit(c)) {
                result = c - '0';
                state++;
                continue;
            }
            return -1;
        case 1:
            if (isspace(c))
                return result;
            if (!isdigit(c))
                return -1;
            result = result * 10 + (c - '0');
            break;
        }
    }
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
movq $-0x1, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0xf(%rsp), %r14
movq %rax, %r13
movl $0x1, %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x10d0
movl $0x1, %r12d
testl %eax, %eax
jle 0x1737
testl %ebp, %ebp
je 0x1729
callq 0x1190
movq (%rax), %rcx
movsbq 0xf(%rsp), %rax
movzwl (%rcx,%rax,2), %ecx
movl $0x1, %r12d
btl $0xd, %ecx
jb 0x1740
btl $0xb, %ecx
jb 0x1785
movl $0x1, %ebp
jmp 0x1737
movsbq 0xf(%rsp), %r15
xorl %ebp, %ebp
cmpq $0xa, %r15
jne 0x174c
movq $-0x1, %rax
jmp 0x17a1
movl $0x1, %ebp
movq 0x10(%rsp), %rax
jmp 0x17a1
callq 0x1190
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
btl $0xd, %eax
jb 0x177a
btl $0xb, %eax
movq $-0x1, %rax
jae 0x17a1
addq $-0x30, %r15
movl $0x1, %ebp
movq %r15, 0x10(%rsp)
movq %r13, %rax
movl $0x3, %r12d
jmp 0x17a1
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,2), %rax
addq $-0x30, %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movq %r13, %rax
testl %r12d, %r12d
je 0x16de
cmpl $0x3, %r12d
je 0x16de
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: word_count
long
word_count(const char *progname, const char *parms, const unsigned char *buf, size_t length)
{
    struct handles h;
    size_t offset = 0;
    struct wcresults results;


    h = my_spawn(progname, parms);
    if (h.child_stdin <= 0 || h.child_stdout <= 0) {
        fprintf(stderr, "[-] spawn failed\n");
        return -1;
    }

    /* keep writing until we've written the entire chunk */
    while (offset < length) {
        size_t count;
        count = write(h.child_stdin, buf+offset, length-offset);
        if (count == 0) {
            perror("write()");
            exit(1);
        }
        offset += count;
    }

    /* Close the handle, telling the child process that input has ended */
    close(h.child_stdin);

    /* Read the results from the child */
    results = get_results(h.child_stdout);

    close(h.child_stdout);
    close(h.child_stderr);
    cleanup_children();

    return results.word_count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %r12
callq 0x154c
movq %rax, %r13
testl %r13d, %r13d
jle 0x188b
movq %r13, %r14
shrq $0x20, %r14
testl %r14d, %r14d
jle 0x188b
movl %edx, %ebx
testq %r15, %r15
je 0x1821
xorl %ebp, %ebp
leaq (%r12,%rbp), %rsi
movq %r15, %rdx
subq %rbp, %rdx
movl %r13d, %edi
callq 0x1070
testq %rax, %rax
je 0x1899
addq %rax, %rbp
cmpq %r15, %rbp
jb 0x17fe
movl %r13d, %edi
callq 0x10b0
movl %r14d, %edi
callq 0x16be
movl %r14d, %edi
callq 0x16be
movq %rax, %r15
movl %r14d, %edi
callq 0x16be
movl %r14d, %edi
callq 0x10b0
movl %ebx, %edi
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movl $0x1, %edx
callq 0x1120
testl %eax, %eax
jg 0x1853
je 0x1879
cmpl $-0x1, %eax
jne 0x189e
callq 0x1040
cmpl $0xa, (%rax)
jne 0x189e
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x132b
movq $-0x1, %r15
jmp 0x1879
callq 0x1316
movl $0x1, %edi
callq 0x1150
// File: /workspace/github_c_makefile_star2_O1/robertdavidgraham[P]wc2/wcdiff.c
// Function: utf8_len
unsigned
utf8_len(unsigned char c)
{
    if (c < 0x80) {
        return 1;
    } else if ((c&0xE0) == 0xC0) {
        return  2;
    } else if ((c&0xF0) == 0xE0) {
        return 3;
    } else if ((c&0xF1) == 0xF0) {
        return 4;
    } else
        return 0;
}

// Assembly:
movl $0x1, %eax
testb %dil, %dil
js 0x18b3
retq
movl %edi, %ecx
andl $-0x20, %ecx
movl $0x2, %eax
cmpl $0xc0, %ecx
je 0x18b2
movl %edi, %ecx
andl $-0x10, %ecx
movl $0x3, %eax
cmpl $0xe0, %ecx
je 0x18b2
andl $-0xf, %edi
xorl %eax, %eax
cmpl $0xf0, %edi
sete %al
shll $0x2, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/codeplea[P]tinyexpr/tinyexpr.c
// Function: factor
static te_expr *factor(state *s) {
    /* <factor>    =    <power> {"^" <power>} */
    te_expr *ret = power(s);
    CHECK_NULL(ret);

    while (s->type == TOK_INFIX && (s->function == pow)) {
        te_fun2 t = s->function;
        next_token(s);
        te_expr *p = power(s);
        CHECK_NULL(p, te_free(ret));

        te_expr *prev = ret;
        ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, p);
        CHECK_NULL(ret, te_free(p), te_free(prev));

        ret->function = t;
    }

    return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
callq 0x24fd
testq %rax, %rax
je 0x24ed
movq %rax, %r14
movq 0x2b9e(%rip), %r13      # 0x4fd0
cmpl $0x20, 0x10(%rbx)
jne 0x24f0
cmpq %r13, 0x18(%rbx)
jne 0x24f0
movq %rbx, %rdi
callq 0x12eb
movq %rbx, %rdi
callq 0x24fd
testq %rax, %rax
je 0x2492
movq %rax, %r12
movl $0x20, %edi
callq 0x10a0
testq %rax, %rax
je 0x24ab
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %r14, 0x10(%rax)
movq %r12, 0x18(%rax)
movl $0x2a, (%rax)
movq $0x0, 0x8(%rax)
jmp 0x24ae
testq %r14, %r14
je 0x24a7
movq %r14, %rdi
callq 0x11e4
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x24e5
xorl %r15d, %r15d
testq %r15, %r15
je 0x24bb
movq %r13, 0x8(%r15)
movb $0x1, %al
jmp 0x24e2
movq %r12, %rdi
callq 0x11e4
movq %r12, %rdi
callq 0x1030
testq %r14, %r14
je 0x24e0
movq %r14, %rdi
callq 0x11e4
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
movq %r15, %r14
testb %al, %al
jne 0x2432
xorl %r14d, %r14d
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: readfile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned char*, int)
int readfile(const string fname,unsigned char* buf,int fmax=0xa0000) {
	FILE *infile=fopen(fname.c_str(),"rb");
	if (!infile) return -1;		// failed to open file
	fseek(infile,0,SEEK_END);
	int iflen = ftell(infile);
	rewind(infile);
	if (iflen < fmax+1) {
		rewind(infile);
		fread((char*)buf,1,iflen,infile);
	} else {
		iflen=0;
	}
	fclose(infile);
	return iflen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movq %rsi, %rbx
movq (%rdi), %rdi
leaq 0x179a0e(%rip), %rsi    # 0x57e004
callq 0x4d4620
testq %rax, %rax
je 0x404655
movq %rax, %r14
xorl %r15d, %r15d
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x4d8f90
movq %r14, %rdi
callq 0x4d4950
movq %rax, %r13
movq %r14, %rdi
callq 0x4d92d0
cmpl %r12d, %r13d
jg 0x40464b
movq %r14, %rdi
callq 0x4d92d0
movslq %r13d, %rdx
movl $0x1, %esi
movq %rbx, %rdi
movq %r14, %rcx
callq 0x4d4850
movl %r13d, %r15d
movq %r14, %rdi
callq 0x4d3ef0
jmp 0x40465b
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
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_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: savefile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned char*, int)
bool savefile(const string fname, unsigned char* buf, int len) {
	FILE *file=fopen(fname.c_str(),"wb");
	if (!file) return false;
	fwrite((char*)buf,1,len,file);
	fclose(file);
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r15d
movq %rsi, %r14
movq (%rdi), %rdi
leaq 0x179980(%rip), %rsi    # 0x57e007
callq 0x4d4620
movq %rax, %rbx
testq %rax, %rax
je 0x4046af
movslq %r15d, %rdx
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x4d4aa0
movq %rbx, %rdi
callq 0x4d3ef0
testq %rbx, %rbx
setne %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: extractfile(unsigned char*, unsigned char*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void extractfile(unsigned char* buf, unsigned char* ptr,int fpos,const string fname) {
	int len=*(ptr+11)+(*(ptr+12)<<8);
	unsigned char slen=*(ptr+13);
	unsigned char rlen=*(ptr+12); if (*(ptr+11)!=0) rlen++;
	if (slen!=rlen) len=(slen<<8);
	printf("%.8s\n",ptr);
	FILE *ofile=fopen(fname.c_str(),"wb");
	if (!ofile) {cout<<"Can't write file"<<endl; return;}
	fwrite(buf+fpos,1,len,ofile);
	fclose(ofile);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movl %edx, -0x2c(%rbp)
movq %rdi, %rbx
movzbl 0xb(%rsi), %r14d
movzbl 0xc(%rsi), %r12d
movzbl 0xd(%rsi), %r13d
leaq 0x1798e2(%rip), %rdi    # 0x57e013
xorl %eax, %eax
callq 0x4cd9a0
movq (%r15), %rdi
leaq 0x1798c5(%rip), %rsi    # 0x57e007
callq 0x4d4620
testq %rax, %rax
je 0x404799
movq %rax, %r15
cmpq $0x1, %r14
movl %r12d, %eax
sbbb $-0x1, %al
shll $0x8, %r12d
orq %r14, %r12
movl %r13d, %edx
shll $0x8, %edx
cmpb %al, %r13b
cmoveq %r12, %rdx
movslq -0x2c(%rbp), %rax
addq %rax, %rbx
movl $0x1, %esi
movq %rbx, %rdi
movq %r15, %rcx
callq 0x4d4aa0
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4d3ef0
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x179872(%rip), %rsi    # 0x57e019
movl $0x10, %edx
movq %rbx, %rdi
callq 0x46eef0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46e9f0
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46dfc0
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: makedsc(unsigned char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, unsigned char, unsigned short)
void makedsc(unsigned char* ptr, const string fname, const string fext, int len,unsigned char slen, unsigned short start=0) {
	strncpy((char*)ptr,fname.c_str(),8);
	*(ptr+8)=fext[0];
	// start
	*(ptr+9)=(start & 0xFF);
	*(ptr+10)=(start >> 8) & 0xFF;
	// len
	*(ptr+11)=(len&0xff);
	*(ptr+12)=((len&0xff00)>>8);
	// slen
	*(ptr+13)=slen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r13d
movl %r8d, %r14d
movl %ecx, %r12d
movq %rdx, %r15
movq %rdi, %rbx
movq (%rsi), %rsi
movl $0x8, %edx
callq 0x4010c8
movq (%r15), %rax
movb (%rax), %al
movb %al, 0x8(%rbx)
movl %r13d, %eax
movb %al, 0x9(%rbx)
movb %ah, 0xa(%rbx)
movl %r12d, %eax
movb %al, 0xb(%rbx)
movb %ah, 0xc(%rbx)
movb %r14b, 0xd(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: nlist(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void nlist(const string fname) {
	unsigned char *buf = new unsigned char[0xa0000];
	int len=readfile(fname,buf);
	if (len<1) {cout<<"Can't read file"<<endl; return;}
	int mode=testsig(buf,len);
	unsigned char* ptr = buf;
	unsigned char i=0;
	switch (mode) {
		case 1:
			ptr+=9;
			for(;i<*(buf+8);i++) {
				printf("%.8s.%.1s\n",ptr,ptr+8);
				ptr+=14;
			}
			break;
		case 2:
			while (*ptr!=0 && i<128) {
				if (*ptr!=1) printf("%.8s.%.1s\n",ptr,ptr+8);
				ptr+=16; i++;
			}
			break;
		default: cout<<"Unknown image format"<<endl; break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407170
movq %rax, %rbx
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x4062f4
movq %r15, %rdi
movq %rbx, %rsi
movl $0xa0000, %edx          # imm = 0xA0000
callq 0x4045d8
movl %eax, %r14d
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x40593a
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x406430
testl %r14d, %r14d
jle 0x405968
movabsq $0x5249414c434e4953, %rax # imm = 0x5249414C434E4953
cmpq %rax, (%rbx)
je 0x405980
cmpl $0xa0000, %r14d         # imm = 0xA0000
sete %cl
cmpb $0x10, 0x8e7(%rbx)
sete %al
andb %cl, %al
addb %al, %al
jmp 0x405982
movq $0x5ec460, %rdi         # imm = 0x5EC460
leaq 0x1786b4(%rip), %rsi    # 0x57e02a
movl $0xf, %edx
jmp 0x405a26
movb $0x1, %al
cmpb $0x1, %al
je 0x4059dc
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x405a13
movb (%rbx), %al
testb %al, %al
je 0x405a59
addq $0x8, %rbx
movb $0x1, %r15b
leaq 0x1787e4(%rip), %r14    # 0x57e18e
cmpb $0x1, %al
je 0x4059bf
leaq -0x8(%rbx), %rsi
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4cd9a0
movb 0x8(%rbx), %al
testb %al, %al
je 0x405a59
leal 0x1(%r15), %ecx
addq $0x10, %rbx
testb %r15b, %r15b
movl %ecx, %r15d
jns 0x4059aa
jmp 0x405a59
cmpb $0x0, 0x8(%rbx)
je 0x405a59
movq %rbx, %r14
addq $0x9, %r14
xorl %r12d, %r12d
leaq 0x17879b(%rip), %r15    # 0x57e18e
leaq 0x8(%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x4cd9a0
incb %r12b
addq $0xe, %r14
cmpb 0x8(%rbx), %r12b
jb 0x4059f3
jmp 0x405a59
movq $0x5ec460, %rdi         # imm = 0x5EC460
leaq 0x1786a5(%rip), %rsi    # 0x57e0c6
movl $0x14, %edx
callq 0x46eef0
movq $0x5ec460, %rbx         # imm = 0x5EC460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: createtrd(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void createtrd(const string fname) {
	unsigned char *buf = new unsigned char[0xa0000];
	*(buf+0x8e2)=0x01;
	*(buf+0x8e3)=0x16;
	*(buf+0x8e5)=0xf0;
	*(buf+0x8e6)=0x09;
	*(buf+0x8e7)=0x10;
	FILE *ofile = fopen(fname.c_str(),"wb");
	if (!ofile) {cout<<"Can't write to file"<<endl; return;}
	fwrite((char*)buf,1,0xa0000,ofile);
	fclose(ofile);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %r14
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407170
movq %rax, %rbx
movw $0x1601, 0x8e2(%rax)    # imm = 0x1601
movw $0x9f0, 0x8e5(%rax)     # imm = 0x9F0
movb $0x10, 0x8e7(%rax)
movq (%r14), %rdi
leaq 0x178567(%rip), %rsi    # 0x57e007
callq 0x4d4620
testq %rax, %rax
je 0x405ace
movq %rax, %r14
movl $0x1, %esi
movl $0xa0000, %edx          # imm = 0xA0000
movq %rbx, %rdi
movq %rax, %rcx
callq 0x4d4aa0
movq %r14, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x4d3ef0
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x1785ba(%rip), %rsi    # 0x57e096
movl $0x13, %edx
movq %rbx, %rdi
callq 0x46eef0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46e9f0
movq %rax, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x46dfc0
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: createscl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void createscl(const string fname) {
	char *buf = new char;
	strncpy(buf,"SINCLAIR\0",9);
	FILE *ofile = fopen(fname.c_str(),"wb");
	if (!ofile) {cout<<"Can't write to file"<<endl; return;}
	fwrite(buf,1,9,ofile);
	fclose(ofile);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %r14
movl $0x1, %edi
callq 0x407130
movq %rax, %rbx
movabsq $0x5249414c434e4953, %rax # imm = 0x5249414C434E4953
movq %rax, (%rbx)
movb $0x0, 0x8(%rbx)
movq (%r14), %rdi
leaq 0x1784c1(%rip), %rsi    # 0x57e007
callq 0x4d4620
testq %rax, %rax
je 0x405b74
movq %rax, %r14
movl $0x1, %esi
movl $0x9, %edx
movq %rbx, %rdi
movq %rax, %rcx
callq 0x4d4aa0
movq %r14, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x4d3ef0
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178514(%rip), %rsi    # 0x57e096
movl $0x13, %edx
movq %rbx, %rdi
callq 0x46eef0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46e9f0
movq %rax, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x46dfc0
// File: /workspace/github_c_makefile_star2_O1/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: help(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void help(const string pname) {
	cout<<"Usage:"<<endl;
	cout<<pname<<" list filename\t\t\tlist of files (formated)"<<endl;
	cout<<pname<<" nlist filename\t\t\tlist of files (name.ext only)"<<endl;
	cout<<pname<<" ctrd filename\t\t\tcreate new TRD"<<endl;
	cout<<pname<<" cscl filename\t\t\tcreate new SCL"<<endl;
	cout<<pname<<" add filename archname\t\tadd file to archive"<<endl;
	cout<<pname<<" pop filename archname\t\textract file from archive"<<endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq $0x5ec460, %r14         # imm = 0x5EC460
leaq 0x1785c4(%rip), %rsi    # 0x57e199
movl $0x6, %edx
movq %r14, %rdi
callq 0x46eef0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r14, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %r15
leaq 0x17857e(%rip), %rsi    # 0x57e1a0
movl $0x29, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r15, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %r15
leaq 0x17855b(%rip), %rsi    # 0x57e1ca
movl $0x2f, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r15, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %r15
leaq 0x17853e(%rip), %rsi    # 0x57e1fa
movl $0x1f, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r15, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %r15
leaq 0x178511(%rip), %rsi    # 0x57e21a
movl $0x1f, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r15, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %r15
leaq 0x1784e4(%rip), %rsi    # 0x57e23a
movl $0x2b, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %r15, %rdi
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x46eef0
movq %rax, %rbx
leaq 0x1784c3(%rip), %rsi    # 0x57e266
movl $0x31, %edx
movq %rax, %rdi
callq 0x46eef0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46e9f0
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x46dfc0
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/diskio.c
// Function: disk_initialize
DSTATUS disk_initialize (
	BYTE pdrv				/* Physical drive nmuber to identify the drive */
)
{
  printf("disk_initialize\n");
  if (fno == -1)
    fno = open("abc.dat", O_SYNC|O_RDWR, S_IRUSR|S_IWUSR);
  lseek(fno, 0, SEEK_SET);
  return RES_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x41e6(%rip), %rdi      # 0x546d
callq 0x1030
cmpl $-0x1, 0x5dcd(%rip)     # 0x7060
jne 0x12b3
leaq 0x418c(%rip), %rdi      # 0x5428
movl $0x101002, %esi         # imm = 0x101002
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x1090
movl %eax, 0x5dad(%rip)      # 0x7060
movl 0x5da7(%rip), %edi      # 0x7060
xorl %esi, %esi
xorl %edx, %edx
callq 0x1060
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/diskio.c
// Function: disk_read
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Start sector in LBA */
	UINT count		/* Number of sectors to read */
)
{
	DRESULT res;
	int result;

	printf("disk_read %d %ld %d\n", fno, sector, count);
	lseek(fno, sector*512, SEEK_SET);
	read(fno, buff, 512*count);

	return RES_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r15
movl 0x5d82(%rip), %esi      # 0x7060
leaq 0x414b(%rip), %rdi      # 0x5430
xorl %eax, %eax
callq 0x1050
movl 0x5d6e(%rip), %edi      # 0x7060
shlq $0x9, %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x1060
movl 0x5d5a(%rip), %edi      # 0x7060
shll $0x9, %ebx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1080
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/diskio.c
// Function: disk_write
DRESULT disk_write (
	BYTE pdrv,			/* Physical drive nmuber to identify the drive */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Start sector in LBA */
	UINT count			/* Number of sectors to write */
)
{
	DRESULT res;
	int result;
	printf("disk_write %d %ld %d\n", fno, sector, count);	
	lseek(fno, sector*512, SEEK_SET);
	write(fno, buff, 512*count);
	return RES_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r15
movl 0x5d27(%rip), %esi      # 0x7060
leaq 0x4105(%rip), %rdi      # 0x5445
xorl %eax, %eax
callq 0x1050
movl 0x5d13(%rip), %edi      # 0x7060
shlq $0x9, %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x1060
movl 0x5cff(%rip), %edi      # 0x7060
shll $0x9, %ebx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1040
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/diskio.c
// Function: disk_ioctl
DRESULT disk_ioctl (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE cmd,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
	DRESULT res;
	int result;

	printf("disk_ioctl %d %d\n", pdrv, cmd);
	if (cmd == 3) { // sector size
	  *((WORD*)buff) = 512;
	  return RES_OK;
	}
	if (cmd == 1) { // total count
	  *((DWORD*)buff) = SECCOUNT;
	  return RES_OK;	  
	}
	if (cmd == CTRL_SYNC) {
	  return RES_OK;	  
	}
	return RES_PARERR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdx, %r14
movl %esi, %ebx
movl %edi, %esi
leaq 0x40ca(%rip), %rdi      # 0x545b
movl %ebx, %edx
xorl %eax, %eax
callq 0x1050
testl %ebx, %ebx
je 0x13c0
cmpl $0x1, %ebx
je 0x13b0
cmpl $0x3, %ebx
jne 0x13bb
movw $0x200, (%r14)          # imm = 0x200
jmp 0x13b7
movq $0x80, (%r14)
xorl %ebx, %ebx
jmp 0x13c0
movl $0x4, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_mount
FRESULT f_mount (
	FATFS* fs,			/* Pointer to the filesystem object (NULL:unmount)*/
	const TCHAR* path,	/* Logical drive number to be mounted/unmounted */
	BYTE opt			/* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */
)
{
	FATFS *cfs;
	int vol;
	FRESULT res;
	const TCHAR *rp = path;


	/* Get logical drive number */
	vol = get_ldnumber(&rp);
	if (vol < 0) return FR_INVALID_DRIVE;
	cfs = FatFs[vol];					/* Pointer to fs object */

	if (cfs) {
#if FF_FS_LOCK != 0
		clear_lock(cfs);
#endif
#if FF_FS_REENTRANT						/* Discard sync object of the current volume */
		if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
#endif
		cfs->fs_type = 0;				/* Clear old fs object */
	}

	if (fs) {
		fs->fs_type = 0;				/* Clear new fs object */
#if FF_FS_REENTRANT						/* Create sync object for the new volume */
		if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
#endif
	}
	FatFs[vol] = fs;					/* Register new fs object */

	if (opt == 0) return FR_OK;			/* Do not mount now, it will be mounted later */

	res = find_volume(&path, &fs, 0);	/* Force mounted the volume */
	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x8(%rbp)
testq %rsi, %rsi
je 0x1420
xorl %eax, %eax
movb (%rsi,%rax), %r8b
incq %rax
cmpb $0x21, %r8b
jb 0x1402
cmpb $0x3a, %r8b
jne 0x13ef
xorl %ecx, %ecx
cmpb $0x3a, %r8b
jne 0x1425
cmpq $0x2, %rax
setne %al
cmpb $0x30, (%rsi)
setne %cl
orb %al, %cl
movzbl %cl, %ecx
negl %ecx
jmp 0x1425
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x145f
movl %ecx, %eax
leaq 0x5c3e(%rip), %rcx      # 0x7070
movq (%rcx,%rax,8), %rsi
testq %rsi, %rsi
je 0x143e
movb $0x0, (%rsi)
testq %rdi, %rdi
je 0x1446
movb $0x0, (%rdi)
movq %rdi, (%rcx,%rax,8)
testb %dl, %dl
je 0x1466
leaq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x146e
jmp 0x1468
movl $0xb, %eax
jmp 0x1468
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: move_window
static
FRESULT move_window (	/* Returns FR_OK or FR_DISK_ERR */
	FATFS* fs,			/* Filesystem object */
	DWORD sector		/* Sector number to make appearance in the fs->win[] */
)
{
	FRESULT res = FR_OK;


	if (sector != fs->winsect) {	/* Window offset changed? */
#if !FF_FS_READONLY
		res = sync_window(fs);		/* Write-back changes */
#endif
		if (res == FR_OK) {			/* Fill sector window with new data */
			if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK) {
				sector = 0xFFFFFFFF;	/* Invalidate window if read data is not valid */
				res = FR_DISK_ERR;
			}
			fs->winsect = sector;
		}
	}
	return res;
}

// Assembly:
xorl %eax, %eax
cmpq %rsi, 0x50(%rdi)
je 0x1fc0
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
callq 0x3796
testl %eax, %eax
jne 0x1fbc
movzbl 0x1(%rbx), %edi
leaq 0x58(%rbx), %rsi
movq %r14, %rdx
movl $0x1, %ecx
callq 0x12c6
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setne %al
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmoveq %r14, %rcx
movq %rcx, 0x50(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: validate
static
FRESULT validate (	/* Returns FR_OK or FR_INVALID_OBJECT */
	FFOBJID* obj,	/* Pointer to the FFOBJID, the 1st member in the FIL/DIR object, to check validity */
	FATFS** rfs		/* Pointer to pointer to the owner filesystem object to return */
)
{
	FRESULT res = FR_INVALID_OBJECT;


	if (obj && obj->fs && obj->fs->fs_type && obj->id == obj->fs->id) {	/* Test if the object is valid */
#if FF_FS_REENTRANT
		if (lock_fs(obj->fs)) {	/* Obtain the filesystem object */
			if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
				res = FR_OK;
			} else {
				unlock_fs(obj->fs, FR_OK);
			}
		} else {
			res = FR_TIMEOUT;
		}
#else
		if (!(disk_status(obj->fs->pdrv) & STA_NOINIT)) { /* Test if the phsical drive is kept initialized */
			res = FR_OK;
		}
#endif
	}
	*rfs = (res == FR_OK) ? obj->fs : 0;	/* Corresponding filesystem object */
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movl $0x9, %eax
testq %rdi, %rdi
je 0x2403
movq (%r14), %rcx
testq %rcx, %rcx
je 0x2403
cmpb $0x0, (%rcx)
je 0x2403
movzwl 0x8(%r14), %edx
cmpw 0x6(%rcx), %dx
jne 0x2403
movzbl 0x1(%rcx), %edi
callq 0x1274
testb $0x1, %al
sete %cl
movzbl %al, %eax
andl $0x1, %eax
leal (%rax,%rax,8), %eax
jmp 0x2405
xorl %ecx, %ecx
testb %cl, %cl
je 0x240e
movq (%r14), %rcx
jmp 0x2410
xorl %ecx, %ecx
movq %rcx, (%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: sync_fs
static
FRESULT sync_fs (	/* Returns FR_OK or FR_DISK_ERR */
	FATFS* fs		/* Filesystem object */
)
{
	FRESULT res;


	res = sync_window(fs);
	if (res == FR_OK) {
		if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) {	/* FAT32: Update FSInfo sector if needed */
			/* Create FSInfo structure */
			mem_set(fs->win, 0, SS(fs));
			st_word(fs->win + BS_55AA, 0xAA55);
			st_dword(fs->win + FSI_LeadSig, 0x41615252);
			st_dword(fs->win + FSI_StrucSig, 0x61417272);
			st_dword(fs->win + FSI_Free_Count, fs->free_clst);
			st_dword(fs->win + FSI_Nxt_Free, fs->last_clst);
			/* Write it into the FSInfo sector */
			fs->winsect = fs->volbase + 1;
			disk_write(fs->pdrv, fs->win, fs->winsect, 1);
			fs->fsi_flag = 0;
		}
		/* Make sure that no pending write process in the lower layer */
		if (disk_ioctl(fs->pdrv, CTRL_SYNC, 0) != RES_OK) res = FR_DISK_ERR;
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x3796
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x2a0e
cmpb $0x3, (%rbx)
jne 0x29f8
cmpb $0x1, 0x4(%rbx)
jne 0x29f8
leaq 0x58(%rbx), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x1070
movw $0xaa55, 0x256(%rbx)    # imm = 0xAA55
movl $0x41615252, 0x58(%rbx) # imm = 0x41615252
movl $0x61417272, 0x23c(%rbx) # imm = 0x61417272
movl 0x10(%rbx), %eax
movl 0x18(%rbx), %ecx
movl %ecx, 0x240(%rbx)
movl %eax, 0x244(%rbx)
movq 0x30(%rbx), %rdx
incq %rdx
movq %rdx, 0x50(%rbx)
movzbl 0x1(%rbx), %edi
movq %r14, %rsi
movl $0x1, %ecx
callq 0x1321
movb $0x0, 0x4(%rbx)
movzbl 0x1(%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x137c
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setne %al
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_opendir
FRESULT f_opendir (
	DIR* dp,			/* Pointer to directory object to create */
	const TCHAR* path	/* Pointer to the directory path */
)
{
	FRESULT res;
	FATFS *fs;
	DEF_NAMBUF


	if (!dp) return FR_INVALID_OBJECT;

	/* Get logical drive */
	res = find_volume(&path, &fs, 0);
	if (res == FR_OK) {
		dp->obj.fs = fs;
		INIT_NAMBUF(fs);
		res = follow_path(dp, path);			/* Follow the path to the directory */
		if (res == FR_OK) {						/* Follow completed */
			if (!(dp->fn[NSFLAG] & NS_NONAME)) {	/* It is not the origin directory itself */
				if (dp->obj.attr & AM_DIR) {		/* This object is a sub-directory */
#if FF_FS_EXFAT
					if (fs->fs_type == FS_EXFAT) {
						dp->obj.c_scl = dp->obj.sclust;							/* Get containing directory inforamation */
						dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
						dp->obj.c_ofs = dp->blk_ofs;
						init_alloc_info(fs, &dp->obj);	/* Get object allocation info */
					} else
#endif
					{
						dp->obj.sclust = ld_clust(fs, dp->dir);	/* Get object allocation info */
					}
				} else {						/* This object is a file */
					res = FR_NO_PATH;
				}
			}
			if (res == FR_OK) {
				dp->obj.id = fs->id;
				res = dir_sdi(dp, 0);			/* Rewind directory */
#if FF_FS_LOCK != 0
				if (res == FR_OK) {
					if (dp->obj.sclust != 0) {
						dp->obj.lockid = inc_lock(dp, 0);	/* Lock the sub directory */
						if (!dp->obj.lockid) res = FR_TOO_MANY_OPEN_FILES;
					} else {
						dp->obj.lockid = 0;	/* Root directory need not to be locked */
					}
				}
#endif
			}
		}
		FREE_NAMBUF();
		if (res == FR_NO_FILE) res = FR_NO_PATH;
	}
	if (res != FR_OK) dp->obj.fs = 0;		/* Invalidate the directory object if function faild */

	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, -0x18(%rbp)
testq %rdi, %rdi
je 0x2cf1
movq %rdi, %rbx
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x146e
movl %eax, %ecx
testl %eax, %eax
jne 0x2d3f
movq -0x20(%rbp), %r14
movq %r14, (%rbx)
movq -0x18(%rbp), %rsi
movq %rbx, %rdi
callq 0x1b33
testl %eax, %eax
jne 0x2d34
movb $0x1, %cl
cmpb $0x0, 0x4b(%rbx)
js 0x2d1d
testb $0x10, 0xa(%rbx)
jne 0x2cf8
movl $0x5, %eax
xorl %ecx, %ecx
jmp 0x2d1f
movl $0x9, %ecx
jmp 0x2d4a
movq 0x38(%rbx), %rdx
movzwl 0x1a(%rdx), %eax
cmpb $0x3, (%r14)
jne 0x2d19
movzbl 0x14(%rdx), %esi
movzbl 0x15(%rdx), %edx
shll $0x18, %edx
shll $0x10, %esi
orl %edx, %esi
orq %rsi, %rax
movq %rax, 0x10(%rbx)
xorl %eax, %eax
testb %cl, %cl
je 0x2d34
movzwl 0x6(%r14), %eax
movw %ax, 0x8(%rbx)
movq %rbx, %rdi
callq 0x2d55
cmpl $0x4, %eax
movl $0x5, %ecx
cmovnel %eax, %ecx
testl %ecx, %ecx
je 0x2d4a
movq $0x0, (%rbx)
movl %ecx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: dir_sdi
static
FRESULT dir_sdi (	/* FR_OK(0):succeeded, !=0:error */
	DIR* dp,		/* Pointer to directory object */
	DWORD ofs		/* Offset of directory table */
)
{
	DWORD csz, clst;
	FATFS *fs = dp->obj.fs;


	if (ofs >= (DWORD)((FF_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR) || ofs % SZDIRE) {	/* Check range of offset and alignment */
		return FR_INT_ERR;
	}
	dp->dptr = ofs;				/* Set current offset */
	clst = dp->obj.sclust;		/* Table start cluster (0:root) */
	if (clst == 0 && fs->fs_type >= FS_FAT32) {	/* Replace cluster# 0 with root cluster# */
		clst = fs->dirbase;
		if (FF_FS_EXFAT) dp->obj.stat = 0;	/* exFAT: Root dir has an FAT chain */
	}

	if (clst == 0) {	/* Static table (root-directory on the FAT volume) */
		if (ofs / SZDIRE >= fs->n_rootdir) return FR_INT_ERR;	/* Is index out of range? */
		dp->sect = fs->dirbase;

	} else {			/* Dynamic table (sub-directory or root-directory on the FAT32/exFAT volume) */
		csz = (DWORD)fs->csize * SS(fs);	/* Bytes per cluster */
		while (ofs >= csz) {				/* Follow cluster chain */
			clst = get_fat(&dp->obj, clst);				/* Get next cluster */
			if (clst == 0xFFFFFFFF) return FR_DISK_ERR;	/* Disk error */
			if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR;	/* Reached to end of table or internal error */
			ofs -= csz;
		}
		dp->sect = clst2sect(fs, clst);
	}
	dp->clust = clst;					/* Current cluster# */
	if (dp->sect == 0) return FR_INT_ERR;
	dp->sect += ofs / SS(fs);			/* Sector# of the directory entry */
	dp->dir = fs->win + (ofs % SS(fs));	/* Pointer to the entry in the win[] */

	return FR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %r14
movq 0x10(%rdi), %r15
movq $0x0, 0x20(%rdi)
testq %r15, %r15
jne 0x2d89
cmpb $0x3, (%r14)
jb 0x2d86
movq 0x40(%r14), %r15
jmp 0x2d89
xorl %r15d, %r15d
testq %r15, %r15
je 0x2dc5
movzwl 0xa(%r14), %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %r15, %rsi
testw %r12w, %r12w
jne 0x2dd6
movq %rbx, %rdi
callq 0x1fc1
cmpq %r13, %rax
je 0x2df6
movq %rax, %rsi
movl $0x2, %eax
cmpq $0x2, %rsi
jb 0x2e1d
cmpq 0x20(%r14), %rsi
jb 0x2d9c
jmp 0x2e1d
cmpw $0x0, 0x8(%r14)
je 0x2e18
movq 0x40(%r14), %rax
xorl %r15d, %r15d
jmp 0x2dff
leaq -0x2(%r15), %rax
movq 0x20(%r14), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jae 0x2dfd
movzwl 0xa(%r14), %ecx
imulq %rcx, %rax
addq 0x48(%r14), %rax
jmp 0x2dff
movl $0x1, %eax
jmp 0x2e1d
xorl %eax, %eax
movq %rax, 0x30(%rbx)
movq %r15, 0x28(%rbx)
testq %rax, %rax
je 0x2e18
addq $0x58, %r14
movq %r14, 0x38(%rbx)
xorl %eax, %eax
jmp 0x2e1d
movl $0x2, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_readdir
FRESULT f_readdir (
	DIR* dp,			/* Pointer to the open directory object */
	FILINFO* fno		/* Pointer to file information to return */
)
{
	FRESULT res;
	FATFS *fs;
	DEF_NAMBUF


	res = validate(&dp->obj, &fs);	/* Check validity of the directory object */
	if (res == FR_OK) {
		if (!fno) {
			res = dir_sdi(dp, 0);			/* Rewind the directory object */
		} else {
			INIT_NAMBUF(fs);
			res = dir_read_file(dp);		/* Read an item */
			if (res == FR_NO_FILE) res = FR_OK;	/* Ignore end of directory */
			if (res == FR_OK) {				/* A valid entry is found */
				get_fileinfo(dp, fno);		/* Get the object information */
				res = dir_next(dp, 0);		/* Increment index for next */
				if (res == FR_NO_FILE) res = FR_OK;	/* Ignore end of directory now */
			}
			FREE_NAMBUF();
		}
	}
	LEAVE_FF(fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x20(%rbp), %rsi
callq 0x23bb
testl %eax, %eax
je 0x2e78
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x2eb1
movq %rbx, %rdi
callq 0x2ec3
xorl %r15d, %r15d
cmpl $0x4, %eax
cmovel %r15d, %eax
testl %eax, %eax
jne 0x2e6d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2f56
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2fee
cmpl $0x4, %eax
cmovel %r15d, %eax
jmp 0x2e6d
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2d55
// File: /workspace/github_c_makefile_star2_O1/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: f_stat
FRESULT f_stat (
	const TCHAR* path,	/* Pointer to the file path */
	FILINFO* fno		/* Pointer to file information to return */
)
{
	FRESULT res;
	DIR dj;
	DEF_NAMBUF


	/* Get logical drive */
	res = find_volume(&path, &dj.obj.fs, 0);
	if (res == FR_OK) {
		INIT_NAMBUF(dj.obj.fs);
		res = follow_path(&dj, path);	/* Follow the file path */
		if (res == FR_OK) {				/* Follow completed */
			if (dj.fn[NSFLAG] & NS_NONAME) {	/* It is origin directory */
				res = FR_INVALID_NAME;
			} else {							/* Found an object */
				if (fno) get_fileinfo(&dj, fno);
			}
		}
		FREE_NAMBUF();
	}

	LEAVE_FF(dj.obj.fs, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rsi, %rbx
leaq -0x18(%rbp), %rax
movq %rdi, (%rax)
leaq -0x68(%rbp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x146e
testl %eax, %eax
jne 0x31b0
movq -0x18(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x1b33
testl %eax, %eax
je 0x31bf
movl %eax, %r14d
movl %r14d, %eax
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
cmpb $0x0, -0x1d(%rbp)
js 0x31db
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x31b3
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f56
jmp 0x31b3
movl $0x6, %r14d
jmp 0x31b3