// File: /workspace/github_c_makefile_star2_O1/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 $0x10148, %rsp          # imm = 0x10148
movl $0x0, 0xc(%rsp)
cmpl $0x2, %edi
jl 0x14ec
cmpq $0x0, (%rsi)
je 0x14ec
movl %edi, %eax
movq %rax, 0x38(%rsp)
movl $0x1, %eax
leaq 0x40(%rsp), %rbx
leaq 0xc(%rsp), %r13
movq %rsi, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq (%rsi,%rax,8), %rsi
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
je 0x1252
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
jmp 0x1267
movq %rbx, %rdi
callq 0x1070
movl $0x77656e2e, 0x40(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x44(%rsp,%rax)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd8d(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x14c0
movq %rax, %r15
leaq 0x40(%rsp), %rdi
leaq 0xd8b(%rip), %rsi       # 0x2024
callq 0x10b0
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x14d7
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd66(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x4, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x1050
testl %eax, %eax
je 0x146f
movl $0x1, %ebx
xorl %ebp, %ebp
movq %r15, 0x28(%rsp)
movl %ebp, 0x14(%rsp)
movl %ebx, 0x10(%rsp)
movzbl 0xf(%rsp), %ebx
shll $0x18, %ebx
movzbl 0xe(%rsp), %ebp
shll $0x10, %ebp
movslq %ebx, %rax
orq %rbp, %rax
movzbl 0xd(%rsp), %r12d
shll $0x8, %r12d
addq %r12, %rax
movzbl 0xc(%rsp), %r14d
leaq (%r14,%rax), %r15
movl $0x1, %esi
movl $0x4, %edx
movq %r13, %rdi
movq 0x30(%rsp), %rcx
callq 0x10d0
testl %r15d, %r15d
je 0x1416
leaq 0xcee(%rip), %rdi       # 0x203b
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x10001, %r15d         # imm = 0x10001
jge 0x14a0
leal 0x1(%r15), %r13d
andl $-0x2, %r13d
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %r15, %rdx
movq 0x28(%rsp), %r15
movq %r15, %rcx
callq 0x1050
cmpl %eax, %r13d
jle 0x13bb
movslq %eax, %rcx
leaq (%rsp,%rcx), %rdi
addq $0x140, %rdi            # imm = 0x140
orl %ebp, %ebx
orl %r12d, %ebx
leal (%r14,%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
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x1050
movslq %r13d, %rdx
movq %rbx, %r13
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x10d0
movl 0x14(%rsp), %ebp
incl %ebp
movl 0x10(%rsp), %ebx
jmp 0x1452
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x1439
leaq 0xc28(%rip), %rdi       # 0x204d
movl 0x10(%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
movq 0x28(%rsp), %r15
jmp 0x144e
leaq 0xc30(%rip), %rdi       # 0x2070
callq 0x1040
movq 0x28(%rsp), %r15
movl 0x10(%rsp), %ebx
incl %ebx
xorl %ebp, %ebp
movl $0x1, %esi
movl $0x4, %edx
movq %r13, %rdi
movq %r15, %rcx
callq 0x1050
testl %eax, %eax
jne 0x12f1
movq %r15, %rdi
callq 0x1060
movq 0x30(%rsp), %rdi
callq 0x1060
movq 0x20(%rsp), %rax
incq %rax
cmpq 0x38(%rsp), %rax
movq 0x18(%rsp), %rsi
leaq 0x40(%rsp), %rbx
jne 0x1223
jmp 0x14ac
leaq 0xbd5(%rip), %rdi       # 0x207c
callq 0x1040
xorl %eax, %eax
addq $0x10148, %rsp          # imm = 0x10148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xb37(%rip), %rdi       # 0x200c
jmp 0x14e3
leaq 0xb2e(%rip), %rdi       # 0x200c
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
jmp 0x14f8
leaq 0xb98(%rip), %rdi       # 0x208b
callq 0x1040
xorl %edi, %edi
callq 0x10c0