LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/DeforaOS[P]libSystem/tests/parser.c
// Function: parser
static int _parser(String const * progname)
{
	int ret = 0;
	Parser * parser;
	String const * p;

	printf("%s: Testing parser_new()\n", progname);
	fflush(stdout);
	if((parser = parser_new(NULL)) != NULL)
		return -1;
	else
		error_print(progname);
	if((parser = parser_new("config-nonexistent.conf")) != NULL)
		return -1;
	else
		error_print(progname);
	if((parser = parser_new("config-empty.conf")) == NULL)
		return error_print(progname);
	if((p = parser_get_filename(parser)) == NULL)
		ret = error_print(progname);
	else if(string_compare(p, "config-empty.conf") != 0)
		ret = error_print(progname);
	if(parser_scan(parser) == 0)
		ret = error_set_print(progname, 2, "%s",
				"Should not be able to scan");
	parser_delete(parser);
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rsi
leaq 0xde6(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1060
movq 0x2db4(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x1070
xorl %eax, %eax
movl %eax, %edi
callq 0x10a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x1253
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1330
movq -0x10(%rbp), %rdi
callq 0x1090
leaq 0xdbb(%rip), %rdi       # 0x201e
callq 0x10a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x127e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1330
movq -0x10(%rbp), %rdi
callq 0x1090
leaq 0xda8(%rip), %rdi       # 0x2036
callq 0x10a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x12ae
movq -0x10(%rbp), %rdi
callq 0x1090
movl %eax, -0x4(%rbp)
jmp 0x1330
movq -0x20(%rbp), %rdi
callq 0x1080
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x12cf
movq -0x10(%rbp), %rdi
callq 0x1090
movl %eax, -0x14(%rbp)
jmp 0x12f2
movq -0x28(%rbp), %rdi
leaq 0xd5c(%rip), %rsi       # 0x2036
callq 0x1050
cmpl $0x0, %eax
je 0x12f0
movq -0x10(%rbp), %rdi
callq 0x1090
movl %eax, -0x14(%rbp)
jmp 0x12f2
movq -0x20(%rbp), %rdi
callq 0x1030
cmpl $0x0, %eax
jne 0x1321
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0xd38(%rip), %rdx       # 0x2048
leaq 0xd34(%rip), %rcx       # 0x204b
movb $0x0, %al
callq 0x1040
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rdi
callq 0x10b0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
callq 0x477fa0
movq %rax, %rdi
leaq 0x17a8a2(%rip), %rsi    # 0x57f004
callq 0x4d5d60
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x40477b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4047e6
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x4da530
movq -0x28(%rbp), %rdi
callq 0x4d6090
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4da870
movl -0x2c(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4047d0
movq -0x28(%rbp), %rdi
callq 0x4da870
movq -0x18(%rbp), %rdi
movslq -0x2c(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x4d5f90
jmp 0x4047d7
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4d5630
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
callq 0x477fa0
movq %rax, %rdi
leaq 0x17a7f5(%rip), %rsi    # 0x57f007
callq 0x4d5d60
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x404828
movb $0x0, -0x1(%rbp)
jmp 0x40484b
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x4d61e0
movq -0x28(%rbp), %rdi
callq 0x4d5630
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rcx, -0x38(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xc(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movb 0xd(%rax), %al
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
movb 0xc(%rax), %al
movb %al, -0x26(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
je 0x40492c
movb -0x26(%rbp), %al
addb $0x1, %al
movb %al, -0x26(%rbp)
movzbl -0x25(%rbp), %eax
movzbl -0x26(%rbp), %ecx
cmpl %ecx, %eax
je 0x404942
movzbl -0x25(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x17a6c6(%rip), %rdi    # 0x57f013
movb $0x0, %al
callq 0x4cf0e0
movq -0x38(%rbp), %rdi
callq 0x477fa0
movq %rax, %rdi
leaq 0x17a6a0(%rip), %rsi    # 0x57f007
callq 0x4d5d60
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x40499b
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x17a694(%rip), %rsi    # 0x57f019
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x4049c1
movq -0x8(%rbp), %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
movslq -0x24(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %esi
callq 0x4d61e0
movq -0x30(%rbp), %rdi
callq 0x4d5630
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movl %r8d, -0x40(%rbp)
movl %ecx, %eax
movl -0x40(%rbp), %ecx
movl %eax, -0x3c(%rbp)
movq %rdx, %rax
movl -0x3c(%rbp), %edx
movq %rax, -0x28(%rbp)
movq %rsi, %rax
movq -0x28(%rbp), %rsi
movq %rax, -0x38(%rbp)
movq %rdi, %r8
movq -0x38(%rbp), %rdi
movw %r9w, %ax
movq %r8, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movb %cl, -0x1d(%rbp)
movw %ax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
callq 0x477fa0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x4010c8
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x476a90
movb (%rax), %cl
movq -0x8(%rbp), %rax
movb %cl, 0x8(%rax)
movzwl -0x20(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x9(%rax)
movzwl -0x20(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0xa(%rax)
movl -0x1c(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0xb(%rax)
movl -0x1c(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0xc(%rax)
movb -0x1d(%rbp), %cl
movq -0x8(%rbp), %rax
movb %cl, 0xd(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x20(%rbp)
movq %rdi, -0x8(%rbp)
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407e80
movq -0x20(%rbp), %rdi
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x8e2(%rax)
movq -0x10(%rbp), %rax
movb $0x16, 0x8e3(%rax)
movq -0x10(%rbp), %rax
movb $-0x10, 0x8e5(%rax)
movq -0x10(%rbp), %rax
movb $0x9, 0x8e6(%rax)
movq -0x10(%rbp), %rax
movb $0x10, 0x8e7(%rax)
callq 0x477fa0
movq %rax, %rdi
leaq 0x178e3f(%rip), %rsi    # 0x57f007
callq 0x4d5d60
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4061fc
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x178eb0(%rip), %rsi    # 0x57f096
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x40621c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0xa0000, %edx          # imm = 0xA0000
callq 0x4d61e0
movq -0x18(%rbp), %rdi
callq 0x4d5630
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x20(%rbp)
movq %rdi, -0x8(%rbp)
movl $0x1, %edi
callq 0x407e40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1790f1(%rip), %rsi    # 0x57f34a
movl $0x9, %edx
callq 0x4010c8
movq -0x20(%rbp), %rdi
callq 0x477fa0
movq %rax, %rdi
leaq 0x178d91(%rip), %rsi    # 0x57f007
callq 0x4d5d60
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4062aa
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x178e02(%rip), %rsi    # 0x57f096
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x4062ca
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x9, %edx
callq 0x4d61e0
movq -0x18(%rbp), %rdi
callq 0x4d5630
addq $0x20, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x10, %rsp
movq %rdi, -0x10(%rbp)
movq %rdi, -0x8(%rbp)
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x178f21(%rip), %rsi    # 0x57f20f
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178efa(%rip), %rsi    # 0x57f216
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178ef6(%rip), %rsi    # 0x57f240
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178ef8(%rip), %rsi    # 0x57f270
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178eea(%rip), %rsi    # 0x57f290
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178edc(%rip), %rsi    # 0x57f2b0
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
movq -0x10(%rbp), %rsi
movq $0x5ed460, %rdi         # imm = 0x5ED460
callq 0x478f90
movq %rax, %rdi
leaq 0x178eda(%rip), %rsi    # 0x57f2dc
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x10, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
leaq 0x6027(%rip), %rdi      # 0x742c
movb $0x0, %al
callq 0x1040
cmpl $-0x1, 0x8c3d(%rip)     # 0xa050
jne 0x1433
leaq 0x6021(%rip), %rdi      # 0x743d
movl $0x101002, %esi         # imm = 0x101002
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x1070
movl %eax, 0x8c1d(%rip)      # 0xa050
movl 0x8c17(%rip), %edi      # 0xa050
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1050
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl 0x8be1(%rip), %esi      # 0xa050
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
leaq 0x5fc8(%rip), %rdi      # 0x7445
movb $0x0, %al
callq 0x1040
movl 0x8bc6(%rip), %edi      # 0xa050
movq -0x18(%rbp), %rsi
shlq $0x9, %rsi
xorl %edx, %edx
callq 0x1050
movl 0x8bb1(%rip), %edi      # 0xa050
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %eax
shll $0x9, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1060
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl 0x8b71(%rip), %esi      # 0xa050
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
leaq 0x5f6d(%rip), %rdi      # 0x745a
movb $0x0, %al
callq 0x1040
movl 0x8b56(%rip), %edi      # 0xa050
movq -0x18(%rbp), %rsi
shlq $0x9, %rsi
xorl %edx, %edx
callq 0x1050
movl 0x8b41(%rip), %edi      # 0xa050
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %eax
shll $0x9, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1030
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movb %sil, %al
movb %dil, %cl
movb %cl, -0x5(%rbp)
movb %al, -0x6(%rbp)
movq %rdx, -0x10(%rbp)
movzbl -0x5(%rbp), %esi
movzbl -0x6(%rbp), %edx
leaq 0x5f19(%rip), %rdi      # 0x7470
movb $0x0, %al
callq 0x1040
movzbl -0x6(%rbp), %eax
cmpl $0x3, %eax
jne 0x1579
movq -0x10(%rbp), %rax
movw $0x200, (%rax)          # imm = 0x200
movl $0x0, -0x4(%rbp)
jmp 0x15af
movzbl -0x6(%rbp), %eax
cmpl $0x1, %eax
jne 0x1596
movq -0x10(%rbp), %rax
movq $0x80, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x15af
movzbl -0x6(%rbp), %eax
cmpl $0x0, %eax
jne 0x15a8
movl $0x0, -0x4(%rbp)
jmp 0x15af
movl $0x4, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 $0x40, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1690
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x1618
movl $0xb, -0x4(%rbp)
jmp 0x1684
movslq -0x2c(%rbp), %rcx
leaq 0x8a3d(%rip), %rax      # 0xa060
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1639
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x10(%rbp)
je 0x1647
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdx
movslq -0x2c(%rbp), %rcx
leaq 0x8a0a(%rip), %rax      # 0xa060
movq %rdx, (%rax,%rcx,8)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x166c
movl $0x0, -0x4(%rbp)
jmp 0x1684
leaq -0x18(%rbp), %rdi
leaq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x1770
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: get_ldnumber
static
int get_ldnumber (		/* Returns logical drive number (-1:invalid drive) */
	const TCHAR** path	/* Pointer to pointer to the path name */
)
{
	const TCHAR *tp, *tt;
	UINT i;
	int vol = -1;
#if FF_STR_VOLUME_ID		/* Find string drive id */
	static const char* const volid[] = {FF_VOLUME_STRS};
	const char *sp;
	char c;
	TCHAR tc;
#endif


	if (*path != 0) {	/* If the pointer is not a null */
		for (tt = *path; (UINT)*tt >= (FF_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;	/* Find a colon in the path */
		if (*tt == ':') {	/* If a colon is exist in the path name */
			tp = *path;
			i = *tp++;
			if (IsDigit(i) && tp == tt) {	/* Is there a numeric drive id + colon? */
				if ((i -= '0') < FF_VOLUMES) {	/* If drive id is found, get the value and strip it */
					vol = (int)i;
					*path = ++tt;
				}
			}
#if FF_STR_VOLUME_ID
			 else {	/* No numeric drive number, find string drive id */
				i = 0; tt++;
				do {
					sp = volid[i]; tp = *path;
					do {	/* Compare a string drive id with path name */
						c = *sp++; tc = *tp++;
						if (IsLower(tc)) tc -= 0x20;
					} while (c && (TCHAR)c == tc);
				} while ((c || tp != tt) && ++i < FF_VOLUMES);	/* Repeat for each id until pattern match */
				if (i < FF_VOLUMES) {	/* If a drive id is found, get the value and strip it */
					vol = (int)i;
					*path = tt;
				}
			}
#endif
		} else {	/* No volume id and use default drive */
#if FF_FS_RPATH != 0 && FF_VOLUMES >= 2
			vol = CurrVol;	/* Current drive */
#else
			vol = 0;		/* Drive 0 */
#endif
		}
	}
	return vol;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1768
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x21, %ecx
movb %al, -0x21(%rbp)
jb 0x16d9
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x16e2
jmp 0x16f2
jmp 0x16e4
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x16b8
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x175f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x30, -0x1c(%rbp)
jb 0x175d
cmpl $0x39, -0x1c(%rbp)
ja 0x175d
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x175d
movl -0x1c(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1, %eax
jae 0x175b
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x175d
jmp 0x1766
movl $0x0, -0x20(%rbp)
jmp 0x1768
movl -0x20(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: ld_clust
static
DWORD ld_clust (	/* Returns the top cluster value of the SFN entry */
	FATFS* fs,		/* Pointer to the fs object */
	const BYTE* dir	/* Pointer to the key entry */
)
{
	DWORD cl;

	cl = ld_word(dir + DIR_FstClusLO);
	if (fs->fs_type == FS_FAT32) {
		cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16;
	}

	return cl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq $0x1a, %rdi
callq 0x4960
movzwl %ax, %eax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x266c
movq -0x10(%rbp), %rdi
addq $0x14, %rdi
callq 0x4960
movzwl %ax, %eax
shlq $0x10, %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: st_dword
static
void st_dword (BYTE* ptr, DWORD val)	/* Store a 4-byte word in little-endian */
{
	*ptr++ = (BYTE)val; val >>= 8;
	*ptr++ = (BYTE)val; val >>= 8;
	*ptr++ = (BYTE)val; val >>= 8;
	*ptr++ = (BYTE)val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
shrq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb %al, %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x50(%rcx), %rax
je 0x292a
movq -0x8(%rbp), %rdi
callq 0x4f30
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2928
movq -0x8(%rbp), %rax
movb 0x1(%rax), %al
movq -0x8(%rbp), %rsi
addq $0x58, %rsi
movq -0x10(%rbp), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x1450
cmpl $0x0, %eax
je 0x291c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x50(%rax)
jmp 0x292a
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: ld_dword
static
DWORD ld_dword (const BYTE* ptr)	/* Load a 4-byte little-endian word */
{
	DWORD rv;

	rv = ptr[3];
	rv = rv << 8 | ptr[2];
	rv = rv << 8 | ptr[1];
	rv = rv << 8 | ptr[0];
	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
shlq $0x8, %rax
movq -0x8(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
shlq $0x8, %rax
movq -0x8(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
shlq $0x8, %rax
movq -0x8(%rbp), %rcx
movzbl (%rcx), %ecx
orq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x9, -0x14(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3052
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3052
movq -0x8(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x3052
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movzwl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jne 0x3052
movq -0x8(%rbp), %rax
movq (%rax), %rax
movzbl 0x1(%rax), %edi
callq 0x13e0
movzbl %al, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3050
movl $0x0, -0x14(%rbp)
jmp 0x3052
cmpl $0x0, -0x14(%rbp)
jne 0x3065
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x306d
xorl %eax, %eax
movq %rax, -0x20(%rbp)
jmp 0x306d
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: mem_cpy
static
void mem_cpy (void* dst, const void* src, UINT cnt)
{
	BYTE *d = (BYTE*)dst;
	const BYTE *s = (const BYTE*)src;

	if (cnt != 0) {
		do {
			*d++ = *s++;
		} while (--cnt);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x30e9
jmp 0x30b7
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb (%rax), %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jne 0x30b7
jmp 0x30e9
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4f30
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x3ae4
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x3ac3
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
jne 0x3ac3
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x29a0
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
addq $0x1fe, %rdi            # imm = 0x1FE
movl $0xaa55, %esi           # imm = 0xAA55
callq 0x3960
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
movl $0x41615252, %esi       # imm = 0x41615252
callq 0x2680
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
addq $0x1e4, %rdi            # imm = 0x1E4
movl $0x61417272, %esi       # imm = 0x61417272
callq 0x2680
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
addq $0x1ec, %rdi            # imm = 0x1EC
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2680
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x8(%rbp), %rax
movb 0x1(%rax), %al
movq -0x8(%rbp), %rsi
addq $0x58, %rsi
movq -0x8(%rbp), %rcx
movq 0x50(%rcx), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x14c0
movq -0x8(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x8(%rbp), %rax
xorl %esi, %esi
xorl %ecx, %ecx
movl %ecx, %edx
movzbl 0x1(%rax), %edi
callq 0x1530
cmpl $0x0, %eax
je 0x3ae2
movl $0x1, -0xc(%rbp)
jmp 0x3ae4
movl -0xc(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3f43
movl $0x9, -0x4(%rbp)
jmp 0x4017
leaq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x1770
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x4000
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2440
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3ff1
movq -0x10(%rbp), %rax
movzbl 0x4b(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x3fc9
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x3fc0
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x2620
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x3fc7
movl $0x5, -0x1c(%rbp)
jmp 0x3fc9
cmpl $0x0, -0x1c(%rbp)
jne 0x3fef
movq -0x28(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4020
movl %eax, -0x1c(%rbp)
jmp 0x3ff1
cmpl $0x4, -0x1c(%rbp)
jne 0x3ffe
movl $0x5, -0x1c(%rbp)
jmp 0x4000
cmpl $0x0, -0x1c(%rbp)
je 0x4011
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2fe0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x428e
cmpq $0x0, -0x10(%rbp)
jne 0x423f
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4020
movl %eax, -0x14(%rbp)
jmp 0x428c
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x42a0
movl %eax, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jne 0x425a
movl $0x0, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x428a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x43a0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x44c0
movl %eax, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jne 0x4288
movl $0x0, -0x14(%rbp)
jmp 0x428a
jmp 0x428c
jmp 0x428e
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x68(%rbp), %rsi
leaq -0x8(%rbp), %rdi
xorl %edx, %edx
callq 0x1770
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x473f
movq -0x8(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x2440
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x473d
movzbl -0x1d(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x4725
movl $0x6, -0x14(%rbp)
jmp 0x473b
cmpq $0x0, -0x10(%rbp)
je 0x4739
movq -0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x43a0
jmp 0x473b
jmp 0x473d
jmp 0x473f
movl -0x14(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: sync_window
static
FRESULT sync_window (	/* Returns FR_OK or FR_DISK_ERR */
	FATFS* fs			/* Filesystem object */
)
{
	FRESULT res = FR_OK;


	if (fs->wflag) {	/* Is the disk access window dirty */
		if (disk_write(fs->pdrv, fs->win, fs->winsect, 1) == RES_OK) {	/* Write back the window */
			fs->wflag = 0;	/* Clear window dirty flag */
			if (fs->winsect - fs->fatbase < fs->fsize) {	/* Is it in the 1st FAT? */
				if (fs->n_fats == 2) disk_write(fs->pdrv, fs->win, fs->winsect + fs->fsize, 1);	/* Reflect it to 2nd FAT if needed */
			}
		} else {
			res = FR_DISK_ERR;
		}
	}
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x4fe2
movq -0x8(%rbp), %rax
movb 0x1(%rax), %al
movq -0x8(%rbp), %rsi
addq $0x58, %rsi
movq -0x8(%rbp), %rcx
movq 0x50(%rcx), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x14c0
cmpl $0x0, %eax
jne 0x4fd9
movq -0x8(%rbp), %rax
movb $0x0, 0x3(%rax)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0x38(%rcx), %rax
movq -0x8(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x4fd7
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x2, %eax
jne 0x4fd5
movq -0x8(%rbp), %rax
movb 0x1(%rax), %al
movq -0x8(%rbp), %rsi
addq $0x58, %rsi
movq -0x8(%rbp), %rcx
movq 0x50(%rcx), %rdx
movq -0x8(%rbp), %rcx
addq 0x28(%rcx), %rdx
movl $0x1, %ecx
movzbl %al, %edi
callq 0x14c0
jmp 0x4fd7
jmp 0x4fe0
movl $0x1, -0xc(%rbp)
jmp 0x4fe2
movl -0xc(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: dir_clear
static
FRESULT dir_clear (	/* Returns FR_OK or FR_DISK_ERR */
	FATFS *fs,		/* Filesystem object */
	DWORD clst		/* Directory table to clear */
)
{
	DWORD sect;
	UINT n, szb;
	BYTE *ibuf;


	if (sync_window(fs) != FR_OK) return FR_DISK_ERR;	/* Flush disk access window */
	sect = clst2sect(fs, clst);		/* Top of the cluster */
	fs->winsect = sect;				/* Set window to top of the cluster */
	mem_set(fs->win, 0, SS(fs));	/* Clear window buffer */
#if FF_USE_LFN == 3		/* Quick table clear by using multi-secter write */
	/* Allocate a temporary buffer */
	for (szb = ((DWORD)fs->csize * SS(fs) >= MAX_MALLOC) ? MAX_MALLOC : fs->csize * SS(fs); szb > SS(fs) && !(ibuf = ff_memalloc(szb)); szb /= 2) ;
	if (szb > SS(fs)) {		/* Buffer allocated? */
		mem_set(ibuf, 0, szb);
		szb /= SS(fs);		/* Bytes -> Sectors */
		for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ;	/* Fill the cluster with 0 */
		ff_memfree(ibuf);
	} else
#endif
	{
		ibuf = fs->win; szb = 1;	/* Use window buffer (single-sector writes may take a time) */
		for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ;	/* Fill the cluster with 0 */
	}
	return (n == fs->csize) ? FR_OK : FR_DISK_ERR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4f30
cmpl $0x0, %eax
je 0x501a
movl $0x1, -0x4(%rbp)
jmp 0x50d2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2bd0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x29a0
movq -0x10(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x31(%rbp)
jae 0x50a2
movq -0x10(%rbp), %rax
movb 0x1(%rax), %al
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
addq %rcx, %rdx
movl -0x28(%rbp), %ecx
movzbl %al, %edi
callq 0x14c0
cmpl $0x0, %eax
sete %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x50ab
jmp 0x50b8
jmp 0x50ad
movl -0x28(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x5065
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %esi
movl $0x1, %eax
xorl %ecx, %ecx
cmpl %esi, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: check_fs
static
BYTE check_fs (	/* 0:FAT, 1:exFAT, 2:Valid BS but not FAT, 3:Not a BS, 4:Disk error */
	FATFS* fs,	/* Filesystem object */
	DWORD sect	/* Sector# (lba) to load and check if it is an FAT-VBR or not */
)
{
	fs->wflag = 0; fs->winsect = 0xFFFFFFFF;		/* Invaidate window */
	if (move_window(fs, sect) != FR_OK) return 4;	/* Load boot record */

	if (ld_word(fs->win + BS_55AA) != 0xAA55) return 3;	/* Check boot record signature (always placed here even if the sector size is >512) */

#if FF_FS_EXFAT
	if (!mem_cmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT   ", 11)) return 1;	/* Check if exFAT VBR */
#endif
	if (fs->win[BS_JmpBoot] == 0xE9 || fs->win[BS_JmpBoot] == 0xEB || fs->win[BS_JmpBoot] == 0xE8) {	/* Valid JumpBoot code? */
		if (!mem_cmp(fs->win + BS_FilSysType, "FAT", 3)) return 0;		/* Is it an FAT VBR? */
		if (!mem_cmp(fs->win + BS_FilSysType32, "FAT32", 5)) return 0;	/* Is it an FAT32 VBR? */
	}
	return 2;	/* Valid BS but not FAT */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, 0x3(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x28b0
cmpl $0x0, %eax
je 0x61b0
movb $0x4, -0x1(%rbp)
jmp 0x625a
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
addq $0x1fe, %rdi            # imm = 0x1FE
callq 0x4960
movzwl %ax, %eax
cmpl $0xaa55, %eax           # imm = 0xAA55
je 0x61d7
movb $0x3, -0x1(%rbp)
jmp 0x625a
movq -0x10(%rbp), %rax
movzbl 0x58(%rax), %eax
cmpl $0xe9, %eax
je 0x6204
movq -0x10(%rbp), %rax
movzbl 0x58(%rax), %eax
cmpl $0xeb, %eax
je 0x6204
movq -0x10(%rbp), %rax
movzbl 0x58(%rax), %eax
cmpl $0xe8, %eax
jne 0x6256
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
addq $0x36, %rdi
leaq 0x12c5(%rip), %rsi      # 0x74dc
movl $0x3, %edx
callq 0x6270
cmpl $0x0, %eax
jne 0x622c
movb $0x0, -0x1(%rbp)
jmp 0x625a
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
addq $0x52, %rdi
leaq 0x12a1(%rip), %rsi      # 0x74e0
movl $0x5, %edx
callq 0x6270
cmpl $0x0, %eax
jne 0x6254
movb $0x0, -0x1(%rbp)
jmp 0x625a
jmp 0x6256
movb $0x2, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/gadget114514[P]fatfs-example/fatfs/source/ff.c
// Function: mem_cmp
static
int mem_cmp (const void* dst, const void* src, UINT cnt)	/* ZR:same, NZ:different */
{
	const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src;
	int r = 0;

	do {
		r = *d++ - *s++;
	} while (--cnt && r == 0);

	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movzbl (%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2d(%rbp)
je 0x62dc
cmpl $0x0, -0x2c(%rbp)
sete %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0x6296
movl -0x2c(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)