// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10150, %rsp          # imm = 0x10150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x12e9
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x12fe
leaq 0xd14(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10a0
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1543
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 0x1060
movq %rax, -0x10038(%rbp)
cmpq $0x0, %rax
je 0x135c
movq -0x10038(%rbp), %rdi
leaq 0xcce(%rip), %rsi       # 0x2023
callq 0x1030
jmp 0x136f
leaq -0x10140(%rbp), %rdi
leaq 0xcb9(%rip), %rsi       # 0x2023
callq 0x1090
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xca6(%rip), %rsi       # 0x2028
callq 0x1080
movq %rax, -0x10148(%rbp)
cmpq $0x0, -0x10148(%rbp)
jne 0x13b9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xc80(%rip), %rdi       # 0x202b
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10a0
leaq -0x10140(%rbp), %rdi
leaq 0xc7c(%rip), %rsi       # 0x2043
callq 0x1080
movq %rax, -0x10150(%rbp)
cmpq $0x0, -0x10150(%rbp)
jne 0x13f9
leaq -0x10140(%rbp), %rsi
leaq 0xc40(%rip), %rdi       # 0x202b
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10a0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xc3a(%rip), %rdi       # 0x2046
movb $0x0, %al
callq 0x1050
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10148(%rbp), %rdi
callq 0x1070
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x1442
jmp 0x14cd
movl -0x18(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x14ac
cmpl $0x0, -0x1c(%rbp)
je 0x14a5
movq -0x10150(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x10030(%rbp), %rdx
callq 0x11c0
cmpl $0x0, %eax
je 0x1489
movl -0x24(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
leaq 0xbda(%rip), %rdi       # 0x205a
movb $0x0, %al
callq 0x1050
jmp 0x14a3
movl -0x20(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movl -0x1c(%rbp), %edx
leaq 0xbce(%rip), %rdi       # 0x206a
movb $0x0, %al
callq 0x1050
jmp 0x14a5
movl $0x0, -0x1c(%rbp)
movl -0x18(%rbp), %eax
andl $0x3f, %eax
movb %al, %cl
movl -0x1c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
cltq
movb %cl, -0x10030(%rbp,%rax)
jmp 0x1428
movq -0x10148(%rbp), %rdi
callq 0x1040
cmpl $0x0, -0x1c(%rbp)
je 0x14f5
movq -0x10150(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x10030(%rbp), %rdx
callq 0x11c0
movq -0x10150(%rbp), %rcx
leaq 0x2b6e(%rip), %rdi      # 0x4071
movl $0x1, %esi
movl $0x4, %edx
callq 0x10b0
movl -0x24(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
leaq 0xb38(%rip), %rdi       # 0x205a
movb $0x0, %al
callq 0x1050
movq -0x10150(%rbp), %rdi
callq 0x1040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1305
xorl %eax, %eax
addq $0x10150, %rsp          # imm = 0x10150
popq %rbp
retq