// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mktrd/mctrd.c
// Function: sclPush
void sclPush(char* ipath, char* fpath) {
	char buf[0x10000];
	trdFile hd = prepareFile(fpath, buf);
	if (hd.name[0] == 0) return;
	FILE* file = fopen(ipath, "rb");
	if (!file) {
		printf("Can't open image '%s'\n", ipath);
		return;
	}
	char bufH[9];				// head
	fread(bufH, 9, 1, file);
	int cnt = bufH[8];
	int clen = cnt * 14;
	char* bufC = (char*)malloc(clen);	// catalog
	fread(bufC, clen, 1, file);
	int dsiz = 0;
	for (int i = 0; i < cnt; i++) {
		dsiz += bufC[14 * i + 13] & 0xff;
	}
	dsiz <<= 8;
	char* bufD = (char*)malloc(dsiz);	// data
	fread(bufD, dsiz, 1, file);
	fclose(file);
	if ((unsigned)bufH[8] > 127) {
		printf("Too much files in image\n");
	} else {
		bufH[8]++;
//		trdFile hd = makeDSC(fpath, ilen);
		file = fopen(ipath, "wb");
		if (!file) {
			printf("Can't open image '%s' for writing\n",ipath);
		} else {
			fwrite(bufH, 9, 1, file);		// header
			fwrite(bufC, clen, 1, file);		// old catalog
			fwrite((char*)&hd, 14, 1, file);	// new DSC
			fwrite(bufD, dsiz, 1, file);		// old data
			fwrite(buf, hd.slen << 8, 1, file);	// new data
			int crc = getSum(bufH, 9);
			crc += getSum(bufC, clen);
			crc += getSum((char*)&hd, 14);
			crc += getSum(bufD, dsiz);
			crc += getSum(buf, hd.slen << 8);
			fputi(file, crc);
			fclose(file);
		}
	}
	free(bufC);
	free(bufD);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10060, %rsp          # imm = 0x10060
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x10010(%rbp), %rsi
callq 0x402020
movq %rax, -0x10020(%rbp)
movq %rdx, -0x10018(%rbp)
movsbl -0x10020(%rbp), %eax
cmpl $0x0, %eax
jne 0x402902
jmp 0x402c18
movq -0x8(%rbp), %rdi
leaq 0x9c6f7(%rip), %rsi     # 0x49f004
callq 0x415510
movq %rax, -0x10028(%rbp)
cmpq $0x0, -0x10028(%rbp)
jne 0x40293a
movq -0x8(%rbp), %rsi
leaq 0x9c754(%rip), %rdi     # 0x49f082
movb $0x0, %al
callq 0x40eab0
jmp 0x402c18
leaq -0x10031(%rbp), %rdi
movq -0x10028(%rbp), %rcx
movl $0x9, %esi
movl $0x1, %edx
callq 0x415610
movsbl -0x10029(%rbp), %eax
movl %eax, -0x10038(%rbp)
imull $0xe, -0x10038(%rbp), %eax
movl %eax, -0x1003c(%rbp)
movslq -0x1003c(%rbp), %rdi
callq 0x424da0
movq %rax, -0x10048(%rbp)
movq -0x10048(%rbp), %rdi
movslq -0x1003c(%rbp), %rsi
movq -0x10028(%rbp), %rcx
movl $0x1, %edx
callq 0x415610
movl $0x0, -0x1004c(%rbp)
movl $0x0, -0x10050(%rbp)
movl -0x10050(%rbp), %eax
cmpl -0x10038(%rbp), %eax
jge 0x4029ff
movq -0x10048(%rbp), %rax
imull $0xe, -0x10050(%rbp), %ecx
addl $0xd, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
andl $0xff, %eax
addl -0x1004c(%rbp), %eax
movl %eax, -0x1004c(%rbp)
movl -0x10050(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10050(%rbp)
jmp 0x4029b7
movl -0x1004c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x1004c(%rbp)
movslq -0x1004c(%rbp), %rdi
callq 0x424da0
movq %rax, -0x10058(%rbp)
movq -0x10058(%rbp), %rdi
movslq -0x1004c(%rbp), %rsi
movq -0x10028(%rbp), %rcx
movl $0x1, %edx
callq 0x415610
movq -0x10028(%rbp), %rdi
callq 0x4150d0
movsbl -0x10029(%rbp), %eax
cmpl $0x7f, %eax
jbe 0x402a6b
leaq 0x9c71d(%rip), %rdi     # 0x49f17c
movb $0x0, %al
callq 0x40eab0
jmp 0x402c00
movb -0x10029(%rbp), %al
addb $0x1, %al
movb %al, -0x10029(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x9c5c4(%rip), %rsi     # 0x49f048
callq 0x415510
movq %rax, -0x10028(%rbp)
cmpq $0x0, -0x10028(%rbp)
jne 0x402ab1
movq -0x8(%rbp), %rsi
leaq 0x9c6f0(%rip), %rdi     # 0x49f195
movb $0x0, %al
callq 0x40eab0
jmp 0x402bfe
leaq -0x10031(%rbp), %rdi
movq -0x10028(%rbp), %rcx
movl $0x9, %esi
movl $0x1, %edx
callq 0x415860
movq -0x10048(%rbp), %rdi
movslq -0x1003c(%rbp), %rsi
movq -0x10028(%rbp), %rcx
movl $0x1, %edx
callq 0x415860
movq -0x10028(%rbp), %rcx
leaq -0x10020(%rbp), %rdi
movl $0xe, %esi
movl $0x1, %edx
callq 0x415860
movq -0x10058(%rbp), %rdi
movslq -0x1004c(%rbp), %rsi
movq -0x10028(%rbp), %rcx
movl $0x1, %edx
callq 0x415860
leaq -0x10010(%rbp), %rdi
movzbl -0x10013(%rbp), %eax
shll $0x8, %eax
movslq %eax, %rsi
movq -0x10028(%rbp), %rcx
movl $0x1, %edx
callq 0x415860
leaq -0x10031(%rbp), %rdi
movl $0x9, %esi
callq 0x401f10
movl %eax, -0x1005c(%rbp)
movq -0x10048(%rbp), %rdi
movl -0x1003c(%rbp), %esi
callq 0x401f10
addl -0x1005c(%rbp), %eax
movl %eax, -0x1005c(%rbp)
leaq -0x10020(%rbp), %rdi
movl $0xe, %esi
callq 0x401f10
addl -0x1005c(%rbp), %eax
movl %eax, -0x1005c(%rbp)
movq -0x10058(%rbp), %rdi
movl -0x1004c(%rbp), %esi
callq 0x401f10
addl -0x1005c(%rbp), %eax
movl %eax, -0x1005c(%rbp)
leaq -0x10010(%rbp), %rdi
movzbl -0x10013(%rbp), %esi
shll $0x8, %esi
callq 0x401f10
addl -0x1005c(%rbp), %eax
movl %eax, -0x1005c(%rbp)
movq -0x10028(%rbp), %rdi
movl -0x1005c(%rbp), %esi
callq 0x401d90
movq -0x10028(%rbp), %rdi
callq 0x4150d0
jmp 0x402c00
movq -0x10048(%rbp), %rdi
callq 0x4250e0
movq -0x10058(%rbp), %rdi
callq 0x4250e0
addq $0x10060, %rsp          # imm = 0x10060
popq %rbp
retq
nopw %cs:(%rax,%rax)