// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/mtcvt23/mtcvtv23.c
// Function: main
int main (int argc, char *argv[])
{
int i, k, wc, 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, ".tap");
                else strcat (oname, ".tap");
	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), 2, ifile);
		if (k == 0) break;
		wc = ((unsigned int) bc[1] << 8) | (unsigned int) bc[0];
		wc = (wc + 1) & ~1;
		fwrite (bc, sizeof (char), 4, ofile);
		if (wc) {
			k = fread (buf, sizeof (char), wc, ifile);
			for ( ; k < wc; k++) buf[k] =0;
			fwrite (buf, sizeof (char), wc, 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 0x146c
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x146c
movl %edi, %eax
movq %rax, 0x30(%rsp)
movl $0x1, %r14d
leaq 0x40(%rsp), %r15
leaq 0xc(%rsp), %r13
movq %rbx, 0x38(%rsp)
movq (%rbx,%r14,8), %rsi
movq %r15, %rdi
callq 0x1030
movq %r15, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
je 0x1251
movb $0x0, 0x4(%rax)
movl $0x7061742e, (%rax)     # imm = 0x7061742E
jmp 0x1266
movq %r15, %rdi
callq 0x1070
movl $0x7061742e, 0x40(%rsp,%rax) # imm = 0x7061742E
movb $0x0, 0x44(%rsp,%rax)
movq %r14, 0x18(%rsp)
movq (%rbx,%r14,8), %rdi
leaq 0xd93(%rip), %rsi       # 0x2009
callq 0x10b0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x1440
leaq 0x40(%rsp), %rdi
leaq 0xd8f(%rip), %rsi       # 0x2024
callq 0x10b0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x1452
movq 0x18(%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xd6f(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rdi
movq 0x10(%rsp), %rcx
callq 0x1050
testl %eax, %eax
je 0x13fb
movl $0x1, %r14d
xorl %ebx, %ebx
movzbl 0xd(%rsp), %ebp
shll $0x8, %ebp
movzbl 0xc(%rsp), %r12d
leal (%r12,%rbp), %r15d
incl %r15d
movl $0x1, %esi
movl $0x4, %edx
movq %r13, %rdi
movq 0x20(%rsp), %rcx
callq 0x10d0
andl $0x1fffe, %r15d         # imm = 0x1FFFE
je 0x13b2
movl %r14d, 0x2c(%rsp)
movq %r13, %r14
movl %r15d, %r13d
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0x1050
cmpl %eax, %r15d
jle 0x1374
movslq %eax, %rcx
leaq (%rsp,%rcx), %rdi
addq $0x140, %rdi            # imm = 0x140
leal (%r12,%rbp), %ecx
incl %ecx
andl $0x1fffe, %ecx          # imm = 0x1FFFE
notl %eax
addl %ecx, %eax
incq %rax
xorl %esi, %esi
movq %rax, %rdx
callq 0x10a0
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %r13, %rdx
movq 0x20(%rsp), %r15
movq %r15, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %r13
movq %r14, %rdi
movq %r15, %rcx
callq 0x10d0
incl %ebx
movl 0x2c(%rsp), %r14d
jmp 0x13dc
testl %ebx, %ebx
je 0x13cb
leaq 0xc7e(%rip), %rdi       # 0x203b
movl %r14d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1080
jmp 0x13d7
leaq 0xc8c(%rip), %rdi       # 0x205e
callq 0x1040
incl %r14d
xorl %ebx, %ebx
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rdi
movq 0x10(%rsp), %rcx
callq 0x1050
testl %eax, %eax
jne 0x12e6
movq 0x10(%rsp), %rdi
callq 0x1060
movq 0x20(%rsp), %rdi
callq 0x1060
movq 0x18(%rsp), %r14
incq %r14
cmpq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
leaq 0x40(%rsp), %r15
jne 0x1227
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 (%rbx,%rax,8), %rsi
leaq 0xbbc(%rip), %rdi       # 0x200c
jmp 0x145e
leaq 0xbb3(%rip), %rdi       # 0x200c
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
xorl %edi, %edi
callq 0x10c0
leaq 0xbf7(%rip), %rdi       # 0x206a
callq 0x1040
jmp 0x1465