// File: /workspace/github_c_makefile_star2_O3/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, 0x14(%rsp)
movl $0x200, 0x10(%rsp)      # imm = 0x200
cmpl $0x2, %edi
jl 0x1416
cmpq $0x0, (%rsi)
je 0x1416
movl %edi, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %r12d
leaq 0x20(%rsp), %rbx
leaq 0x120(%rsp), %rbp
leaq 0x10(%rsp), %r15
leaq 0xe05(%rip), %r13       # 0x203b
movq %rsi, (%rsp)
movq (%rsi,%r12,8), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1030
movq %rbx, %rdi
movl $0x2e, %esi
callq 0x1090
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0x1274
movb $0x0, 0x4(%rax)
movl $0x7061742e, (%rax)     # imm = 0x7061742E
movq (%rsp), %rax
movq (%rax,%r12,8), %r14
jmp 0x1289
movq %rbx, %rdi
callq 0x1070
movl $0x7061742e, 0x20(%rsp,%rax) # imm = 0x7061742E
movb $0x0, 0x24(%rsp,%rax)
movq %r14, %rdi
leaq 0xd76(%rip), %rsi       # 0x2009
callq 0x10b0
testq %rax, %rax
je 0x13e6
movq %rax, %r12
leaq 0x20(%rsp), %rdi
leaq 0xd74(%rip), %rsi       # 0x2024
callq 0x10b0
testq %rax, %rax
je 0x13fc
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0xd52(%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 0x1333
testl %ebx, %ebx
je 0x1377
movq %r13, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
cmpl $0x1ff, %ebx            # imm = 0x1FF
jg 0x1333
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 0x12dc
movl $0x1, %esi
movl $0x4, %edx
leaq 0x14(%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 0x8(%rsp), %r12
incq %r12
cmpq 0x18(%rsp), %r12
movq (%rsp), %rsi
leaq 0x20(%rsp), %rbx
jne 0x123a
xorl %eax, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0xc12(%rip), %rdi       # 0x200c
jmp 0x1408
leaq 0xc09(%rip), %rdi       # 0x200c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
xorl %edi, %edi
callq 0x10c0
leaq 0xc36(%rip), %rdi       # 0x2053
callq 0x1040
jmp 0x140f