// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mktrd/mctrd.c
// Function: trdPop
void trdPop(char* ipath, char* fname, char* oname) {
	FILE* file = fopen(ipath, "rb");
	if (!file) {
		printf("Can't open image '%s'\n",ipath);
		return;
	}
	char nbuf[9];
	char xbuf[256];
	char buf[0x10000];
	int num = 0;
	makeName(fname, nbuf);
	trdFile hd;
	fseek(file, 0x8e3, SEEK_SET);
	int diskType = fgetc(file) & 0xff;	// 0x16:80ds, 17:40ds, 18:80ss, 19:40ss
	if (fname == NULL) {
		do {
			fseek(file, num << 4, SEEK_SET);
			fread(&hd, 16, 1, file);
			if (hd.name[0] > 31) {
				trd_get_data(file, buf, hd.trk, hd.sec, hd.slen, diskType);
				sprintf(xbuf,"%.3i_%.8s.%c",num,hd.name,hd.ext);
				// printf("%s\n",xbuf);
				saveoutput(xbuf, buf, hd);
			}
			num++;
		} while ((num < 128) && (hd.name[0] != 0x00));
	} else if (trdSeekFile(file, nbuf, &hd) < 0) {
		printf("Can't find file '%s' in image\n",fname);
	} else {
		trd_get_data(file, buf, hd.trk, hd.sec, hd.slen, diskType);
		saveoutput(oname, buf, hd);
	}
	fclose(file);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10150, %rsp          # imm = 0x10150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x9b802(%rip), %rsi     # 0x49f004
callq 0x415510
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x403829
movq -0x8(%rbp), %rsi
leaq 0x9b865(%rip), %rdi     # 0x49f082
movb $0x0, %al
callq 0x40eab0
jmp 0x4039ef
movl $0x0, -0x10134(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x401e00
movq -0x20(%rbp), %rdi
movl $0x8e3, %esi            # imm = 0x8E3
xorl %edx, %edx
callq 0x4195c0
movq -0x20(%rbp), %rdi
callq 0x4196a0
andl $0xff, %eax
movl %eax, -0x10148(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x40396c
jmp 0x403871
movq -0x20(%rbp), %rdi
movl -0x10134(%rbp), %eax
shll $0x4, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x4195c0
movq -0x20(%rbp), %rcx
leaq -0x10144(%rbp), %rdi
movl $0x10, %esi
movl $0x1, %edx
callq 0x415610
movsbl -0x10144(%rbp), %eax
cmpl $0x1f, %eax
jle 0x403926
movq -0x20(%rbp), %rdi
leaq -0x10130(%rbp), %rsi
movzbl -0x10135(%rbp), %edx
movzbl -0x10136(%rbp), %ecx
movzbl -0x10137(%rbp), %r8d
movl -0x10148(%rbp), %r9d
callq 0x4036e0
leaq -0x130(%rbp), %rdi
movl -0x10134(%rbp), %edx
leaq -0x10144(%rbp), %rcx
movsbl -0x1013c(%rbp), %r8d
leaq 0x9b8ba(%rip), %rsi     # 0x49f1b8
movb $0x0, %al
callq 0x40eb80
leaq -0x130(%rbp), %rdi
leaq -0x10130(%rbp), %rsi
movq -0x10144(%rbp), %rdx
movq -0x1013c(%rbp), %rcx
callq 0x4021a0
movl -0x10134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10134(%rbp)
xorl %eax, %eax
cmpl $0x80, -0x10134(%rbp)
movb %al, -0x10149(%rbp)
jge 0x40395c
movsbl -0x10144(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x10149(%rbp)
movb -0x10149(%rbp), %al
testb $0x1, %al
jne 0x403871
jmp 0x4039e6
movq -0x20(%rbp), %rdi
leaq -0x29(%rbp), %rsi
leaq -0x10144(%rbp), %rdx
callq 0x403610
cmpl $0x0, %eax
jge 0x403999
movq -0x10(%rbp), %rsi
leaq 0x9b909(%rip), %rdi     # 0x49f299
movb $0x0, %al
callq 0x40eab0
jmp 0x4039e4
movq -0x20(%rbp), %rdi
leaq -0x10130(%rbp), %rsi
movzbl -0x10135(%rbp), %edx
movzbl -0x10136(%rbp), %ecx
movzbl -0x10137(%rbp), %r8d
movl -0x10148(%rbp), %r9d
callq 0x4036e0
movq -0x18(%rbp), %rdi
leaq -0x10130(%rbp), %rsi
movq -0x10144(%rbp), %rdx
movq -0x1013c(%rbp), %rcx
callq 0x4021a0
jmp 0x4039e6
movq -0x20(%rbp), %rdi
callq 0x4150d0
addq $0x10150, %rsp          # imm = 0x10150
popq %rbp
retq
nopl (%rax,%rax)