// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0xc(%rsp)
cmpl $0x2, %edi
jl 0x145c
cmpq $0x0, (%rsi)
je 0x145c
movl %edi, %eax
pushq $0x1
popq %r14
leaq 0x30(%rsp), %r12
pushq $0x2e
popq %r15
leaq 0xc(%rsp), %r13
movq %r14, %rcx
movq %rsi, 0x18(%rsp)
movq %rax, 0x28(%rsp)
cmpq %rax, %rcx
je 0x1448
movq (%rsi,%rcx,8), %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq %rcx, %rbp
callq 0x1030
movq %r12, %rdi
movl %r15d, %esi
callq 0x1090
testq %rax, %rax
movq %rbp, 0x20(%rsp)
je 0x125e
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq 0x18(%rsp), %rax
movq %rax, %r15
movq (%rax,%rbp,8), %rbx
jmp 0x1278
movq 0x18(%rsp), %r15
movq %r12, %rdi
callq 0x1070
movl $0x77656e2e, 0x30(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x34(%rsp,%rax)
movq %rbx, %rdi
leaq 0xd87(%rip), %rsi       # 0x2009
callq 0x10a0
testq %rax, %rax
je 0x146a
movq %rax, %rbx
movq %r12, %rdi
leaq 0xd87(%rip), %rsi       # 0x2024
callq 0x10a0
testq %rax, %rax
je 0x147c
movq %rax, %rbp
movq 0x20(%rsp), %rax
movq (%r15,%rax,8), %rsi
leaq 0xd69(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
pushq $0x4
popq %r15
movl $0x0, 0x14(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1050
testl %eax, %eax
je 0x140c
movzwl 0xe(%rsp), %eax
shll $0x10, %eax
movzbl 0xd(%rsp), %ecx
shll $0x8, %ecx
cltq
orq %rcx, %rax
movzbl 0xc(%rsp), %r12d
orq %rax, %r12
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x10c0
testl %r12d, %r12d
je 0x13ce
leaq 0xd0b(%rip), %rdi       # 0x203b
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x10001, %r12d         # imm = 0x10001
jge 0x143c
movq %r14, %rsi
movq %r13, %r14
leal 0x1(%r12), %r13d
andl $-0x2, %r13d
leaq 0x130(%rsp), %rdi
movq %rsi, %r15
movq %r12, %rdx
movq %rbx, %rcx
callq 0x1050
cltq
movslq %r13d, %r12
movq %r14, %r13
cmpq %r12, %rax
jge 0x1386
movb $0x0, 0x130(%rsp,%rax)
incq %rax
jmp 0x1374
movq %r13, %rdi
movq %r15, %r14
movq %r15, %rsi
pushq $0x4
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1050
leaq 0x130(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x10c0
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x10c0
incl 0x14(%rsp)
jmp 0x12d8
movl 0x14(%rsp), %edx
testl %edx, %edx
je 0x13ee
leaq 0xc70(%rip), %rdi       # 0x204d
movl 0x10(%rsp), %r12d
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x13ff
leaq 0xc7b(%rip), %rdi       # 0x2070
callq 0x1040
movl 0x10(%rsp), %r12d
incl %r12d
movl %r12d, 0x10(%rsp)
jmp 0x12d0
movq %rbx, %rdi
callq 0x1060
movq %rbp, %rdi
callq 0x1060
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rax
leaq 0x30(%rsp), %r12
pushq $0x2e
popq %r15
jmp 0x1216
leaq 0xc39(%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
leaq 0xc28(%rip), %rdi       # 0x208b
callq 0x1040
jmp 0x148f
movq 0x20(%rsp), %rax
movq (%r15,%rax,8), %rsi
leaq 0xb92(%rip), %rdi       # 0x200c
jmp 0x1488
leaq 0xb89(%rip), %rdi       # 0x200c
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
xorl %edi, %edi
callq 0x10b0