// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mktrd/mktrd.cpp
// Function: extract(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void extract(const string fextra, const string aname) {
	if (fextra.size()>10) {cout<<"Filename is too long ('filename.C' is maximum)"<<endl; return;}
	if (fextra.size()<2) {cout<<"Filename is too short (must be '.C' at least)"<<endl; return;}
	if (fextra.at(fextra.size()-2)!='.') {cout<<"Filename must be in 'fileneme.e' format"<<endl; return;}
	string fname(fextra,0,fextra.size()-2); fname.resize(8,0x20);	// filename (8 chars)
	string fext(fextra,fextra.size()-1,1);				// extension (1 char)
	unsigned char *buf = new unsigned char[0xa0000];
	int len=readfile(aname,buf);
	if (len<1) {cout<<"Can't read file"<<endl; return;}
	int mode=testsig(buf,len);
	unsigned char* ptr = buf;
	unsigned char i=0;
	int fpos;
	switch (mode) {
		case 1:
			ptr+=9; fpos=9+*(buf+8)*14;		// begin of data
			for(;i<*(buf+8);i++) {
				if (strncmp(fname.c_str(),(const char*)ptr,8)==0) {
					extractfile(buf,ptr,fpos,fextra); i=128;
				}
				fpos+=(*(ptr+13)<<8); ptr+=14;
			}
			break;
		case 2:
			while(*ptr!=0 && i<128) {
				if (strncmp(fname.c_str(),(const char*)ptr,8)==0) {
					int fpos=(*(ptr+15)<<12)+(*(ptr+14)<<8);	// position of begin of file in buf
					extractfile(buf,ptr,fpos,fextra); i=128;
				}
				ptr+=16; i++;
			}
			break;
		default: cout<<"Unknown image format"<<endl; break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x100(%rbp)
movq %rsi, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x476780
cmpq $0xa, %rax
jbe 0x405823
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x1798d1(%rip), %rsi    # 0x57f0db
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x405d07
movq -0x100(%rbp), %rdi
callq 0x476780
cmpq $0x2, %rax
jae 0x40585c
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x1798c7(%rip), %rsi    # 0x57f10a
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x405d07
movq -0x100(%rbp), %rdi
callq 0x476780
movq -0x100(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x476ab0
movsbl (%rax), %eax
cmpl $0x2e, %eax
je 0x4058aa
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x1798a7(%rip), %rsi    # 0x57f138
callq 0x470190
movq %rax, %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x405d07
movq -0x100(%rbp), %rdi
callq 0x476780
movq -0x100(%rbp), %rsi
movq %rax, %rcx
addq $-0x2, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x30(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x478dd0
movq -0x108(%rbp), %rdi
movl $0x8, %esi
movl $0x20, %edx
callq 0x477160
jmp 0x4058f0
movq -0x100(%rbp), %rdi
callq 0x476780
movq -0x100(%rbp), %rsi
movq %rax, %rdx
decq %rdx
leaq -0x60(%rbp), %rdi
movl $0x1, %ecx
callq 0x478dd0
jmp 0x405919
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407e80
movq %rax, -0x110(%rbp)
jmp 0x40592c
movq -0xf8(%rbp), %rsi
movq -0x110(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x478cf0
jmp 0x40594c
movq -0x68(%rbp), %rsi
leaq -0x90(%rbp), %rdi
movl $0xa0000, %edx          # imm = 0xA0000
callq 0x404740
movl %eax, -0x114(%rbp)
jmp 0x405969
leaq -0x90(%rbp), %rdi
callq 0x476560
movl -0x114(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x1, -0x6c(%rbp)
jge 0x405a03
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x179698(%rip), %rsi    # 0x57f02a
callq 0x470190
movq %rax, -0x120(%rbp)
jmp 0x4059a0
movq -0x120(%rbp), %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x4059b5
movl $0x1, -0x94(%rbp)
jmp 0x405cf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x405d19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x405d10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x476560
jmp 0x405d10
movq -0x68(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x404860
movzbl %al, %eax
movl %eax, -0x98(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
movb $0x0, -0xa1(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x124(%rbp)
subl $0x1, %eax
je 0x405a51
jmp 0x405a3d
movl -0x124(%rbp), %eax
subl $0x2, %eax
je 0x405b86
jmp 0x405cb8
movq -0xa0(%rbp), %rax
addq $0x9, %rax
movq %rax, -0xa0(%rbp)
movq -0x68(%rbp), %rax
movzbl 0x8(%rax), %eax
imull $0xe, %eax, %eax
addl $0x9, %eax
movl %eax, -0xa8(%rbp)
movzbl -0xa1(%rbp), %eax
movq -0x68(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jge 0x405b81
leaq -0x30(%rbp), %rdi
callq 0x477fa0
movq %rax, %rdi
movq -0xa0(%rbp), %rsi
movl $0x8, %edx
callq 0x401070
cmpl $0x0, %eax
jne 0x405b42
movq -0x100(%rbp), %rsi
movq -0x68(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x128(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x478cf0
jmp 0x405aee
movl -0x128(%rbp), %edx
movq -0x130(%rbp), %rsi
movq -0x138(%rbp), %rdi
leaq -0xc8(%rbp), %rcx
callq 0x4048d0
jmp 0x405b10
leaq -0xc8(%rbp), %rdi
callq 0x476560
movb $-0x80, -0xa1(%rbp)
jmp 0x405b42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x476560
jmp 0x405d10
movq -0xa0(%rbp), %rax
movzbl 0xd(%rax), %eax
shll $0x8, %eax
addl -0xa8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
addq $0xe, %rax
movq %rax, -0xa0(%rbp)
movb -0xa1(%rbp), %al
addb $0x1, %al
movb %al, -0xa1(%rbp)
jmp 0x405a77
jmp 0x405ceb
jmp 0x405b88
movq -0xa0(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x139(%rbp)
je 0x405bb4
movzbl -0xa1(%rbp), %eax
cmpl $0x80, %eax
setl %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x405bc3
jmp 0x405cb6
leaq -0x30(%rbp), %rdi
callq 0x477fa0
movq %rax, %rdi
movq -0xa0(%rbp), %rsi
movl $0x8, %edx
callq 0x401070
cmpl $0x0, %eax
jne 0x405c91
movq -0x100(%rbp), %rsi
movq -0xa0(%rbp), %rcx
movzbl 0xf(%rcx), %eax
shll $0xc, %eax
movzbl 0xe(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0xcc(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x148(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x140(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x478cf0
jmp 0x405c40
movl -0x140(%rbp), %edx
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdi
leaq -0xf0(%rbp), %rcx
callq 0x4048d0
jmp 0x405c62
leaq -0xf0(%rbp), %rdi
callq 0x476560
movb $-0x80, -0xa1(%rbp)
jmp 0x405c91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x476560
jmp 0x405d10
movq -0xa0(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xa0(%rbp)
movb -0xa1(%rbp), %al
addb $0x1, %al
movb %al, -0xa1(%rbp)
jmp 0x405b88
jmp 0x405ceb
movq $0x5ed460, %rdi         # imm = 0x5ED460
leaq 0x179400(%rip), %rsi    # 0x57f0c6
callq 0x470190
movq %rax, -0x158(%rbp)
jmp 0x405cd4
movq -0x158(%rbp), %rdi
movq $0x46fa70, %rsi         # imm = 0x46FA70
callq 0x46ec80
jmp 0x405ce9
jmp 0x405ceb
movl $0x0, -0x94(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x476560
leaq -0x30(%rbp), %rdi
callq 0x476560
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x476560
leaq -0x30(%rbp), %rdi
callq 0x476560
movq -0x38(%rbp), %rdi
callq 0x4a85a0
nopl (%rax,%rax)