// File: /workspace/github_c_makefile_star2_O3/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, 0xc(%rsp)
movl %eax, 0x34(%rsp)
cmpl $0x2, %edi
jl 0x14e8
movq %rsi, %r14
cmpq $0x0, (%rsi)
je 0x14e8
movl %edi, %eax
movq %rax, 0x38(%rsp)
movl $0x1, %eax
leaq 0x40(%rsp), %r12
movq %r14, 0x18(%rsp)
movq (%r14,%rax,8), %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %r15
callq 0x1030
movq %r12, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
movq %r15, 0x20(%rsp)
je 0x125c
movb $0x0, 0x4(%rax)
movl $0x77656e2e, (%rax)     # imm = 0x77656E2E
movq (%r14,%r15,8), %rbx
jmp 0x1271
movq %r12, %rdi
callq 0x1070
movl $0x77656e2e, 0x40(%rsp,%rax) # imm = 0x77656E2E
movb $0x0, 0x44(%rsp,%rax)
movq %rbx, %rdi
leaq 0xd8e(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x14bc
movq %rax, %r14
leaq 0x40(%rsp), %rdi
leaq 0xd8c(%rip), %rsi       # 0x2024
callq 0x10b0
movq %rax, 0x28(%rsp)
testq %rax, %rax
leaq 0xc(%rsp), %rbx
je 0x14d3
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd62(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x1050
testl %eax, %eax
je 0x146b
movl $0x0, 0x10(%rsp)
movl $0x1, %ebp
movzwl 0xe(%rsp), %ebx
shll $0x10, %ebx
movzbl 0xd(%rsp), %r15d
shll $0x8, %r15d
leal (%r15,%rbx), %r13d
movzbl 0xc(%rsp), %r12d
orl %r12d, %r13d
je 0x13af
leaq 0xd19(%rip), %rdi       # 0x203b
movl %r13d, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x10001, %r13d         # imm = 0x10001
jae 0x149c
movl %ebp, 0x14(%rsp)
movl %r13d, %ebp
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x1050
cmpl %eax, %r13d
jbe 0x1381
movl %eax, %ecx
leaq (%rsp,%rcx), %rdi
addq $0x140, %rdi            # imm = 0x140
addl %r15d, %ebx
addl %r12d, %ebx
notl %eax
addl %ebx, %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 %r14, %rcx
callq 0x1050
cmpl $0x1, %r13d
jne 0x13e2
leaq 0xcd4(%rip), %rdi       # 0x207c
callq 0x1040
jmp 0x142d
movl $0x1, %esi
movl $0x4, %edx
leaq 0x34(%rsp), %rdi
movq 0x28(%rsp), %rcx
callq 0x10d0
movl 0x10(%rsp), %edx
testl %edx, %edx
je 0x1433
leaq 0xc76(%rip), %rdi       # 0x204d
movl %ebp, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x143f
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rdi
movq 0x28(%rsp), %r15
movq %r15, %rcx
callq 0x10d0
movl $0x1, %esi
leaq 0x140(%rsp), %rdi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x10d0
incl 0x10(%rsp)
movl 0x14(%rsp), %ebp
jmp 0x144e
leaq 0xc36(%rip), %rdi       # 0x2070
callq 0x1040
leaq 0xc(%rsp), %rbx
incl %ebp
movl $0x0, 0x10(%rsp)
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x1050
testl %eax, %eax
jne 0x12f6
movq %r14, %rdi
callq 0x1060
movq 0x28(%rsp), %rdi
callq 0x1060
movq 0x20(%rsp), %rax
incq %rax
cmpq 0x38(%rsp), %rax
movq 0x18(%rsp), %r14
leaq 0x40(%rsp), %r12
jne 0x1223
jmp 0x14a8
leaq 0xbf4(%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 0xb3b(%rip), %rdi       # 0x200c
jmp 0x14df
leaq 0xb32(%rip), %rdi       # 0x200c
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
jmp 0x14f4
leaq 0xbb7(%rip), %rdi       # 0x20a6
callq 0x1040
xorl %edi, %edi
callq 0x10c0