// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/tp512cvt/tp512cvt.c
// Function: main
int main (int argc, char *argv[])
{
int i, k;
unsigned char buf[BLKSIZ];
unsigned char tef[4] = { 0, 0, 0, 0 };
unsigned char twc[4] = { 0, 2, 0, 0 };
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 (;;) {
	    k = fread (buf, sizeof (char), BLKSIZ, ifile);
	    if (k == 0) break;
	    if (k != BLKSIZ) {
	 	printf ("Short block, size = %d\n", k);
		for ( ; k < BLKSIZ; k++) buf[k] = 0;  }
	    fwrite (twc, sizeof (char), 4, ofile);
	    fwrite (buf, sizeof (char), BLKSIZ, ofile);
	    fwrite (twc, sizeof (char), 4, ofile);
	    }
	fwrite (tef, sizeof (char), 4, ofile);
	fwrite (tef, sizeof (char), 4, ofile);
	fclose (ifile);
	fclose (ofile);
	}

return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movl $0x0, 0xc(%rsp)
movl $0x200, 0x8(%rsp)       # imm = 0x200
cmpl $0x2, %edi
jl 0x1405
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x1405
movl %edi, %eax
movq %rax, 0x10(%rsp)
movl $0x1, %r14d
leaq 0x20(%rsp), %r12
leaq 0x120(%rsp), %rbp
leaq 0x8(%rsp), %r15
leaq 0xe02(%rip), %r13       # 0x203b
movq %rbx, 0x18(%rsp)
movq (%rbx,%r14,8), %rsi
movq %r12, %rdi
callq 0x1030
movq %r12, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
je 0x1268
movb $0x0, 0x4(%rax)
movl $0x7061742e, (%rax)     # imm = 0x7061742E
jmp 0x127d
movq %r12, %rdi
callq 0x1070
movl $0x7061742e, 0x20(%rsp,%rax) # imm = 0x7061742E
movb $0x0, 0x24(%rsp,%rax)
movq %r14, (%rsp)
movq (%rbx,%r14,8), %rdi
leaq 0xd7d(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x13da
movq %rax, %r12
leaq 0x20(%rsp), %rdi
leaq 0xd7b(%rip), %rsi       # 0x2024
callq 0x10b0
testq %rax, %rax
je 0x13eb
movq %rax, %r14
movq (%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xd5e(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %rbp, %rdi
movq %r12, %rcx
callq 0x1050
movq %rax, %rbx
cmpl $0x200, %ebx            # imm = 0x200
je 0x1327
testl %ebx, %ebx
je 0x136b
movq %r13, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x1ff, %ebx            # imm = 0x1FF
jg 0x1327
movslq %ebx, %rax
leaq (%rsp,%rax), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x1ff, %edx            # imm = 0x1FF
subl %eax, %edx
incq %rdx
xorl %esi, %esi
callq 0x10a0
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %rbp, %rdi
movq %r14, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x10d0
jmp 0x12d0
movl $0x1, %esi
movl $0x4, %edx
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x10d0
movl $0x1, %esi
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x10d0
movq %r12, %rdi
callq 0x1060
movq %r14, %rdi
callq 0x1060
movq (%rsp), %r14
incq %r14
cmpq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
leaq 0x20(%rsp), %r12
jne 0x123e
xorl %eax, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0xc23(%rip), %rdi       # 0x200c
jmp 0x13f7
leaq 0xc1a(%rip), %rdi       # 0x200c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
xorl %edi, %edi
callq 0x10c0
leaq 0xc47(%rip), %rdi       # 0x2053
callq 0x1040
jmp 0x13fe