// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/gt7cvt/gt7cvt.c
// Function: main
int main (int argc, char *argv[])
{
int i, ch, bc, rc, fc;
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]);
	for (bc = rc = fc = 0;;) {
	    ch = fgetc (ifile);
	    if (ch == EOF) break;
	    if (ch & 0x80) {
		if (bc) {
		    if (dump_rec (ofile, bc, buf))
			printf ("End of file %d\n", ++fc);
		    else printf ("Record %d size %d\n", ++rc, bc);
		    }
		bc = 0;  }
	    buf[bc++] = ch & 0x3F;
	    }
	fclose (ifile);
	if (bc) dump_rec (ofile, bc, buf);
	fwrite (fzero, sizeof (char), 4, ofile);
	printf ("End of file %d\n", ++fc);
	fclose (ofile);	
	}

return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10128, %rsp          # imm = 0x10128
cmpl $0x2, %edi
jl 0x1461
movq %rsi, %r15
cmpq $0x0, (%rsi)
je 0x1461
movl %edi, %eax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r12
leaq 0x20(%rsp), %r14
movq %r15, 0x8(%rsp)
cmpq 0x10(%rsp), %r12
je 0x1426
movq (%r15,%r12,8), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1030
movq %r14, %rdi
pushq $0x2e
popq %rsi
callq 0x1080
testq %rax, %rax
je 0x12e7
movb $0x0, 0x4(%rax)
movl $0x7061742e, (%rax)     # imm = 0x7061742E
movq (%r15,%r12,8), %rbx
jmp 0x12fc
movq %r14, %rdi
callq 0x1060
movl $0x7061742e, 0x20(%rsp,%rax) # imm = 0x7061742E
movb $0x0, 0x24(%rsp,%rax)
movq %rbx, %rdi
leaq 0xd03(%rip), %rsi       # 0x2009
callq 0x10a0
testq %rax, %rax
je 0x143a
movq %rax, %r13
movq %r14, %rdi
leaq 0xd03(%rip), %rsi       # 0x2024
callq 0x10a0
testq %rax, %rax
je 0x1447
movq %rax, %r14
movq %r12, 0x18(%rsp)
movq (%r15,%r12,8), %rsi
xorl %r15d, %r15d
leaq 0xce2(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1070
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r13, %rdi
callq 0x1090
cmpl $-0x1, %eax
je 0x13c0
movl %eax, %r12d
testb %r12b, %r12b
jns 0x13ad
testl %ebp, %ebp
je 0x13ab
movq %r14, %rdi
movl %ebp, %esi
leaq 0x120(%rsp), %rdx
callq 0x11cc
testl %eax, %eax
je 0x1397
incl %r15d
xorl %ebp, %ebp
leaq 0xcb0(%rip), %rdi       # 0x203b
movl %r15d, %esi
xorl %eax, %eax
callq 0x1070
jmp 0x13ad
incl %ebx
leaq 0xcab(%rip), %rdi       # 0x204b
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
xorl %ebp, %ebp
andb $0x3f, %r12b
movslq %ebp, %rax
incl %ebp
movb %r12b, 0x120(%rsp,%rax)
jmp 0x1350
movq %r13, %rdi
callq 0x1050
testl %ebp, %ebp
je 0x13de
movq %r14, %rdi
movl %ebp, %esi
leaq 0x120(%rsp), %rdx
callq 0x11cc
leaq 0x2c94(%rip), %rdi      # 0x4079
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
movq %r14, %rcx
callq 0x10c0
incl %r15d
leaq 0xc3e(%rip), %rdi       # 0x203b
movl %r15d, %esi
xorl %eax, %eax
callq 0x1070
movq %r14, %rdi
callq 0x1050
movq 0x18(%rsp), %r12
incq %r12
movq 0x8(%rsp), %r15
leaq 0x20(%rsp), %r14
jmp 0x12ad
xorl %eax, %eax
addq $0x10128, %rsp          # imm = 0x10128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15,%r12,8), %rsi
leaq 0xbc7(%rip), %rdi       # 0x200c
jmp 0x1453
leaq 0xbbe(%rip), %rdi       # 0x200c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x10b0
leaq 0xbf6(%rip), %rdi       # 0x205e
callq 0x1040
jmp 0x145a