// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10150, %rsp          # imm = 0x10150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x1080
cmpl $0x2, -0x8(%rbp)
jl 0x1209
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x121e
leaq 0xdf4(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x14ed
leaq -0x10140(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1030
leaq -0x10140(%rbp), %rdi
movl $0x2e, %esi
callq 0x1070
movq %rax, -0x10038(%rbp)
cmpq $0x0, %rax
je 0x127c
movq -0x10038(%rbp), %rdi
leaq 0xdae(%rip), %rsi       # 0x2023
callq 0x1030
jmp 0x128f
leaq -0x10140(%rbp), %rdi
leaq 0xd99(%rip), %rsi       # 0x2023
callq 0x10a0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd86(%rip), %rsi       # 0x2028
callq 0x1090
movq %rax, -0x10148(%rbp)
cmpq $0x0, -0x10148(%rbp)
jne 0x12d9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd60(%rip), %rdi       # 0x202b
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
leaq -0x10140(%rbp), %rdi
leaq 0xd5c(%rip), %rsi       # 0x2043
callq 0x1090
movq %rax, -0x10150(%rbp)
cmpq $0x0, -0x10150(%rbp)
jne 0x1319
leaq -0x10140(%rbp), %rsi
leaq 0xd20(%rip), %rdi       # 0x202b
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd1a(%rip), %rdi       # 0x2046
movb $0x0, %al
callq 0x1060
movl $0x1, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x2c(%rbp), %rdi
movq -0x10148(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x1040
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x1369
jmp 0x14c7
movzbl -0x29(%rbp), %eax
shll $0x18, %eax
movzbl -0x2a(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x2b(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x2c(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
andl $-0x2, %eax
movl %eax, -0x20(%rbp)
leaq -0x2c(%rbp), %rdi
movq -0x10150(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
cmpl $0x0, -0x1c(%rbp)
je 0x1488
movl -0x1c(%rbp), %esi
leaq 0xc95(%rip), %rdi       # 0x205a
movb $0x0, %al
callq 0x1060
cmpl $0x10000, -0x1c(%rbp)   # imm = 0x10000
jle 0x13ef
leaq 0xc90(%rip), %rdi       # 0x206c
movb $0x0, %al
callq 0x1060
movl $0x0, -0x4(%rbp)
jmp 0x14f4
leaq -0x10030(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movq -0x10148(%rbp), %rcx
movl $0x1, %esi
callq 0x1040
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x142d
movslq -0x18(%rbp), %rax
movb $0x0, -0x10030(%rbp,%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x140e
leaq -0x2c(%rbp), %rdi
movq -0x10148(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x1040
leaq -0x10030(%rbp), %rdi
movslq -0x20(%rbp), %rdx
movq -0x10150(%rbp), %rcx
movl $0x1, %esi
callq 0x10c0
leaq -0x2c(%rbp), %rdi
movq -0x10150(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x14c2
cmpl $0x0, -0x28(%rbp)
je 0x14a4
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
leaq 0xbe1(%rip), %rdi       # 0x207c
movb $0x0, %al
callq 0x1060
jmp 0x14b2
leaq 0xbf4(%rip), %rdi       # 0x209f
movb $0x0, %al
callq 0x1060
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
jmp 0x1341
movq -0x10148(%rbp), %rdi
callq 0x1050
movq -0x10150(%rbp), %rdi
callq 0x1050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1225
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10150, %rsp          # imm = 0x10150
popq %rbp
retq