// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq 0x8(%rdi), %rcx
cmpq $0xb, %rcx
jb 0x4052be
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178e27(%rip), %rsi    # 0x57e0db
movl $0x2e, %edx
jmp 0x4053e3
cmpq $0x1, %rcx
ja 0x4052dc
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178e38(%rip), %rsi    # 0x57e10a
movl $0x2d, %edx
jmp 0x4053e3
movq %rdi, %rbx
movq (%rdi), %rax
cmpb $0x2e, -0x2(%rax,%rcx)
jne 0x4053d0
movq %rsi, %r15
addq $-0x2, %rcx
leaq -0x90(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x477f90
movl $0x8, %esi
movq %r14, %rdi
movl $0x20, %edx
callq 0x4763f0
movq 0x8(%rbx), %rdx
decq %rdx
leaq -0xb0(%rbp), %rdi
movl $0x1, %ecx
movq %rbx, %rsi
callq 0x477f90
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407170
movq %rax, %r13
leaq -0xc0(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x4062f4
leaq -0xd0(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl $0xa0000, %edx          # imm = 0xA0000
callq 0x4045d8
movl %eax, %r15d
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x405395
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x406430
testl %r15d, %r15d
jle 0x405423
movabsq $0x5249414c434e4953, %rax # imm = 0x5249414C434E4953
cmpq %rax, (%r13)
je 0x40546e
cmpl $0xa0000, %r15d         # imm = 0xA0000
sete %cl
cmpb $0x10, 0x8e7(%r13)
sete %al
andb %cl, %al
addb %al, %al
jmp 0x405470
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178d5a(%rip), %rsi    # 0x57e138
movl $0x27, %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 $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46dfc0
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178bf9(%rip), %rsi    # 0x57e02a
movl $0xf, %edx
movq %rbx, %rdi
callq 0x46eef0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq $0x5ec460, %rdi         # imm = 0x5EC460
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
jmp 0x40562a
movb $0x1, %al
cmpb $0x1, %al
movq %r13, -0x30(%rbp)
je 0x405532
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x4055e4
cmpb $0x0, (%r13)
je 0x40562a
xorl %r14d, %r14d
leaq -0x50(%rbp), %r15
movq %r13, %r12
movq -0x90(%rbp), %rdi
movl $0x8, %edx
movq %r12, %rsi
callq 0x401070
testl %eax, %eax
jne 0x405514
movzbl 0xf(%r12), %r14d
movzbl 0xe(%r12), %r13d
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4062f4
shll $0xc, %r14d
shll $0x8, %r13d
addl %r14d, %r13d
movq -0x30(%rbp), %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %r15, %rcx
callq 0x404704
movq -0x50(%rbp), %rdi
movb $-0x80, %r14b
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x405514
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x406430
cmpb $0x0, 0x10(%r12)
je 0x40562a
addq $0x10, %r12
incb %r14b
jns 0x40549d
jmp 0x40562a
cmpb $0x0, 0x8(%r13)
je 0x40562a
movzbl 0x8(%r13), %r15d
leal (%r15,%r15), %eax
shll $0x4, %r15d
subl %eax, %r15d
addl $0x9, %r15d
movq %r13, %r14
addq $0x16, %r14
xorl %r12d, %r12d
leaq -0xd(%r14), %r13
movq -0x90(%rbp), %rdi
movl $0x8, %edx
movq %r13, %rsi
callq 0x401070
testl %eax, %eax
jne 0x4055c3
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r12
movq %r12, %rdi
callq 0x4062f4
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0x404704
movq -0x70(%rbp), %rdi
movb $-0x80, %r12b
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x4055c3
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x406430
movzbl (%r14), %eax
shll $0x8, %eax
addl %eax, %r15d
incb %r12b
addq $0xe, %r14
movq -0x30(%rbp), %rax
cmpb 0x8(%rax), %r12b
jb 0x40555b
jmp 0x40562a
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178ad4(%rip), %rsi    # 0x57e0c6
movl $0x14, %edx
movq %rbx, %rdi
callq 0x46eef0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x450040
movsbl %al, %esi
movq $0x5ec460, %rdi         # imm = 0x5EC460
callq 0x46e9f0
movq %rax, %rdi
callq 0x46dfc0
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x405649
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x406430
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x405662
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x406430
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4056b7
jmp 0x4056b7
jmp 0x40567a
movq %rax, %rbx
jmp 0x4056d9
jmp 0x4056b7
jmp 0x4056b7
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x4056ba
movq -0x60(%rbp), %rsi
jmp 0x4056ad
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4056ba
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x406430
jmp 0x4056ba
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4056d9
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x406430
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4056f2
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x406430
movq %rbx, %rdi
callq 0x4a6e60