// File: /workspace/github_c_makefile_star2_O3/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 0x4052d9
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178e0c(%rip), %rsi    # 0x57e0db
movl $0x2e, %edx
jmp 0x405455
cmpq $0x1, %rcx
ja 0x4052f7
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178e1d(%rip), %rsi    # 0x57e10a
movl $0x2d, %edx
jmp 0x405455
movq %rdi, %rbx
movq (%rdi), %rax
cmpb $0x2e, -0x2(%rax,%rcx)
jne 0x405442
movq %rsi, %r15
addq $-0x2, %rcx
leaq -0x90(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x477fa0
movl $0x8, %esi
movq %r14, %rdi
movl $0x20, %edx
callq 0x476400
movq 0x8(%rbx), %rdx
decq %rdx
leaq -0xb0(%rbp), %rdi
movl $0x1, %ecx
movq %rbx, %rsi
callq 0x477fa0
movl $0xa0000, %edi          # imm = 0xA0000
callq 0x407180
movq %rax, -0x30(%rbp)
leaq -0xc0(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x4062fa
leaq -0xd0(%rbp), %r12
movq %r12, %rdi
movq -0x30(%rbp), %r13
movq %r13, %rsi
movl $0xa0000, %edx          # imm = 0xA0000
callq 0x4045d8
movl %eax, %r15d
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x4053b5
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x406440
testl %r15d, %r15d
jle 0x405495
movabsq $0x5249414c434e4953, %rax # imm = 0x5249414C434E4953
cmpq %rax, (%r13)
je 0x4054e0
cmpl $0xa0000, %r15d         # imm = 0xA0000
jne 0x405591
cmpb $0x10, 0x8e7(%r13)
jne 0x405591
cmpb $0x0, (%r13)
je 0x4055d7
leaq -0x60(%rbp), %r14
movb $0x1, %r13b
movq -0x90(%rbp), %r12
movq -0x30(%rbp), %r15
movl $0x8, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x401070
testl %eax, %eax
je 0x405621
cmpb $0x0, 0x10(%r15)
je 0x4055d7
addq $0x10, %r15
leal 0x1(%r13), %eax
testb %r13b, %r13b
movl %eax, %r13d
jns 0x40540a
jmp 0x4055d7
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178ce8(%rip), %rsi    # 0x57e138
movl $0x27, %edx
movq %rbx, %rdi
callq 0x46ef00
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x450050
movsbl %al, %esi
movq %rbx, %rdi
callq 0x46ea00
movq %rax, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46dfd0
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178b87(%rip), %rsi    # 0x57e02a
movl $0xf, %edx
movq %rbx, %rdi
callq 0x46ef00
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x450050
movsbl %al, %esi
movq $0x5ec460, %rdi         # imm = 0x5EC460
callq 0x46ea00
movq %rax, %rdi
callq 0x46dfd0
jmp 0x4055d7
movzbl 0x8(%r13), %r15d
testl %r15d, %r15d
je 0x4055d7
leal (%r15,%r15), %eax
shll $0x4, %r15d
subl %eax, %r15d
addl $0x9, %r15d
movq -0x30(%rbp), %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 0x405570
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
callq 0x4062fa
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0x404704
movq -0x50(%rbp), %rdi
movb $-0x80, %r12b
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x405570
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x406440
movzbl (%r14), %eax
shll $0x8, %eax
addl %eax, %r15d
incb %r12b
addq $0xe, %r14
movq -0x30(%rbp), %rax
cmpb 0x8(%rax), %r12b
jb 0x405508
jmp 0x4055d7
movq $0x5ec460, %rbx         # imm = 0x5EC460
leaq 0x178b27(%rip), %rsi    # 0x57e0c6
movl $0x14, %edx
movq %rbx, %rdi
callq 0x46ef00
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x450050
movsbl %al, %esi
movq $0x5ec460, %rdi         # imm = 0x5EC460
callq 0x46ea00
movq %rax, %rdi
callq 0x46dfd0
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4055f6
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x406440
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x40560f
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x406440
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0xf(%r15), %r13d
movzbl 0xe(%r15), %r12d
leaq -0x70(%rbp), %rdi
movq %r14, (%rdi)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
callq 0x4062fa
shll $0xc, %r13d
shll $0x8, %r12d
addl %r13d, %r12d
leaq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x404704
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x4055d7
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x406440
jmp 0x4055d7
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x4056bf
movq -0x60(%rbp), %rsi
jmp 0x4056b2
jmp 0x4056bc
jmp 0x4056bc
jmp 0x4056bc
jmp 0x405697
movq %rax, %rbx
jmp 0x4056de
jmp 0x4056bc
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4056bf
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x406440
jmp 0x4056bf
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4056de
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x406440
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4056f7
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x406440
movq %rbx, %rdi
callq 0x4a6e70