// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/mtcvtodd/mtcvtodd.c
// Function: main
int main (int argc, char *argv[])
{
int i, k, tbc, ebc, fc, rc;
unsigned char bc[4] = { 0 };
unsigned char buf[FLPSIZ];
char *ppos, oname[256];
FILE *ifile, *ofile;

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: verb file [file...]\n");
	exit (0);  }

for (i = 1; i < argc; i++) {
	strcpy (oname, argv[i]);
        if (ppos = strrchr (oname, '.')) strcpy (ppos, ".new");
                else strcat (oname, ".new");
	ifile = fopen (argv[i], "rb");
	if (ifile == NULL) {
		printf ("Error opening file: %s\n", argv[i]);
		exit (0);  }
	ofile = fopen (oname, "wb");
	if (ofile == NULL) {
		printf ("Error opening file: %s\n", oname);
		exit (0);  }

	printf ("Processing file %s\n", argv[i]);
	fc = 1; rc = 0;
	for (;;) {
		k = fread (bc, sizeof (char), 4, ifile);
		if (k == 0) break;
		tbc = ((unsigned int) bc[3] << 24) | ((unsigned int) bc[2] << 16) |
			((unsigned int) bc[1] << 8) | (unsigned int) bc[0];
		ebc = (tbc + 1) & ~1;
		fwrite (bc, sizeof (char), 4, ofile);
		if (tbc) {
			printf ("Record size = %d\n", tbc);
			if (tbc > FLPSIZ) {
				printf ("Record too big\n");
				return 0;  }
			k = fread (buf, sizeof (char), tbc, ifile);
			for ( ; k < ebc; k++) buf[k] = 0;
			fread (bc, sizeof (char), 4, ifile);
			fwrite (buf, sizeof (char), ebc, ofile);
			fwrite (bc, sizeof (char), 4, ofile);
			rc++;  }
		else {	if (rc) printf ("End of file %d, record count = %d\n", fc, rc);
			else printf ("End of tape\n");
			fc++;
			rc = 0;  }
		}
	fclose (ifile);
	fclose (ofile);
	}

return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10138, %rsp          # imm = 0x10138
movl $0x0, (%rsp)
cmpl $0x2, %edi
jl 0x14bd
movq %rsi, %r14
cmpq $0x0, (%rsi)
je 0x14bd
movl %edi, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %r15d
leaq 0x30(%rsp), %r12
movq %r14, 0x20(%rsp)
movq (%r14,%r15,8), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1030
movq %r12, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
je 0x1252
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%r14,%r15,8), %rbx
jmp 0x1267
movq %r12, %rdi
callq 0x1070
movl $0x77656e2e, 0x30(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x34(%rsp,%rax)
movq %rbx, %rdi
leaq 0xd98(%rip), %rsi       # 0x2009
callq 0x10b0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x149b
movq %r12, %rdi
leaq 0xd96(%rip), %rsi       # 0x2024
callq 0x10b0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x14a8
movq %r15, 0x28(%rsp)
movq (%r14,%r15,8), %rsi
leaq 0xd76(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x4, %edx
movq %rsp, %r14
movq %r14, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rcx
callq 0x1050
testl %eax, %eax
je 0x144a
movl $0x1, %ebx
xorl %r13d, %r13d
movl %ebx, 0x4(%rsp)
movzwl 0x2(%rsp), %ebx
shll $0x10, %ebx
movzbl 0x1(%rsp), %ebp
shll $0x8, %ebp
movslq %ebx, %rax
orq %rbp, %rax
movzbl (%rsp), %r12d
leaq (%r12,%rax), %r15
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq 0x10(%rsp), %rcx
callq 0x10d0
testl %r15d, %r15d
je 0x13f0
leaq 0xd0c(%rip), %rdi       # 0x203b
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x10001, %r15d         # imm = 0x10001
jge 0x147b
leal 0x1(%r15), %r14d
andl $-0x2, %r14d
movl $0x1, %esi
leaq 0x130(%rsp), %rdi
movq %r15, %rdx
movq 0x8(%rsp), %r15
movq %r15, %rcx
callq 0x1050
cmpl %eax, %r14d
jle 0x139a
movslq %eax, %rcx
leaq (%rsp,%rcx), %rdi
addq $0x130, %rdi            # imm = 0x130
orl %ebp, %ebx
leal (%r12,%rbx), %ecx
incl %ecx
andl $-0x2, %ecx
notl %eax
addl %ecx, %eax
incq %rax
xorl %esi, %esi
movq %rax, %rdx
callq 0x10a0
movl $0x1, %esi
movl $0x4, %edx
movq %rsp, %rbx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x1050
movslq %r14d, %rdx
movq %rbx, %r14
movl $0x1, %esi
leaq 0x130(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x10d0
incl %r13d
movl 0x4(%rsp), %ebx
jmp 0x142d
testl %r13d, %r13d
je 0x1413
leaq 0xc51(%rip), %rdi       # 0x204d
movl 0x4(%rsp), %ebx
movl %ebx, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1080
movq 0x8(%rsp), %r15
jmp 0x1428
leaq 0xc56(%rip), %rdi       # 0x2070
callq 0x1040
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %ebx
incl %ebx
xorl %r13d, %r13d
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rcx
callq 0x1050
testl %eax, %eax
jne 0x12e5
movq %r15, %rdi
callq 0x1060
movq 0x10(%rsp), %rdi
callq 0x1060
movq 0x28(%rsp), %r15
incq %r15
cmpq 0x18(%rsp), %r15
movq 0x20(%rsp), %r14
leaq 0x30(%rsp), %r12
jne 0x1221
jmp 0x1487
leaq 0xbfa(%rip), %rdi       # 0x207c
callq 0x1040
xorl %eax, %eax
addq $0x10138, %rsp          # imm = 0x10138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14,%r15,8), %rsi
leaq 0xb66(%rip), %rdi       # 0x200c
jmp 0x14b4
leaq 0xb5d(%rip), %rdi       # 0x200c
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
jmp 0x14c9
leaq 0xbc7(%rip), %rdi       # 0x208b
callq 0x1040
xorl %edi, %edi
callq 0x10c0