// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/mtcvtfix/mtcvtfix.c
// Function: main
int main (int argc, char *argv[])
{
int i, fc, rc;
unsigned int k, tbc;
unsigned char bc[4] = { 0 };
unsigned char bceof[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];
	    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 < tbc; k++) buf[k] = 0;
		fread (bc, sizeof (char), 4, ifile);
		if (tbc > 1) {
		    fwrite (bc, sizeof (char), 4, ofile);
		    fwrite (buf, sizeof (char), tbc, ofile);
		    fwrite (bc, sizeof (char), 4, ofile);
		    rc++;  }
		else {
		    printf ("Record length = 1, ignored\n");
		    }  }
	    else {
		fwrite (bceof, sizeof (char), 4, ofile);
		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
xorl %eax, %eax
movl %eax, (%rsp)
movl %eax, 0x34(%rsp)
cmpl $0x2, %edi
jl 0x14fb
cmpq $0x0, (%rsi)
je 0x14fb
movl %edi, %eax
movq %rax, 0x38(%rsp)
movl $0x1, %eax
leaq 0x40(%rsp), %rbx
movq %rsp, %r14
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 0x1251
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
jmp 0x1266
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 0xd8e(%rip), %rsi       # 0x2009
callq 0x10b0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x14cf
leaq 0x40(%rsp), %rdi
leaq 0xd8a(%rip), %rsi       # 0x2024
callq 0x10b0
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x14e6
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd65(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq 0x8(%rsp), %rcx
callq 0x1050
testl %eax, %eax
je 0x147c
movl $0x0, 0x4(%rsp)
movl $0x1, %ebp
movzbl 0x3(%rsp), %ebx
shll $0x18, %ebx
movzbl 0x2(%rsp), %r12d
shll $0x10, %r12d
leal (%r12,%rbx), %r13d
movzbl 0x1(%rsp), %r15d
shll $0x8, %r15d
orl %r15d, %r13d
movzbl (%rsp), %r14d
orl %r14d, %r13d
je 0x13c0
leaq 0xd0e(%rip), %rdi       # 0x203b
movl %r13d, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x10001, %r13d         # imm = 0x10001
jae 0x14af
movl %ebp, 0x14(%rsp)
movl %r13d, %ebp
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
callq 0x1050
cmpl %eax, %r13d
jbe 0x1392
movl %eax, %ecx
leaq (%rsp,%rcx), %rdi
addq $0x140, %rdi            # imm = 0x140
addl %r12d, %ebx
addl %r14d, %r15d
addl %ebx, %r15d
notl %eax
addl %r15d, %eax
incq %rax
xorl %esi, %esi
movq %rax, %rdx
callq 0x10a0
movl $0x1, %esi
movl $0x4, %edx
movq %rsp, %r14
movq %r14, %rdi
movq 0x8(%rsp), %rcx
callq 0x1050
cmpl $0x1, %r13d
jne 0x13f3
leaq 0xcc3(%rip), %rdi       # 0x207c
callq 0x1040
jmp 0x143e
movl $0x1, %esi
movl $0x4, %edx
leaq 0x34(%rsp), %rdi
movq 0x28(%rsp), %rcx
callq 0x10d0
movl 0x4(%rsp), %edx
testl %edx, %edx
je 0x1444
leaq 0xc65(%rip), %rdi       # 0x204d
movl %ebp, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x1450
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
callq 0x10d0
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x10d0
incl 0x4(%rsp)
movl 0x14(%rsp), %ebp
jmp 0x145d
leaq 0xc25(%rip), %rdi       # 0x2070
callq 0x1040
movq %rsp, %r14
incl %ebp
movl $0x0, 0x4(%rsp)
movl $0x1, %esi
movl $0x4, %edx
movq %r14, %rdi
movq 0x8(%rsp), %rcx
callq 0x1050
testl %eax, %eax
jne 0x12f5
movq 0x8(%rsp), %rdi
callq 0x1060
movq 0x28(%rsp), %rdi
callq 0x1060
movq 0x20(%rsp), %rax
incq %rax
cmpq 0x38(%rsp), %rax
movq 0x18(%rsp), %rsi
leaq 0x40(%rsp), %rbx
jne 0x1222
jmp 0x14bb
leaq 0xbe1(%rip), %rdi       # 0x2097
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 0xb28(%rip), %rdi       # 0x200c
jmp 0x14f2
leaq 0xb1f(%rip), %rdi       # 0x200c
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
jmp 0x1507
leaq 0xba4(%rip), %rdi       # 0x20a6
callq 0x1040
xorl %edi, %edi
callq 0x10c0