// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x224(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x1080
movl 0xe02(%rip), %eax       # 0x2004
movl %eax, -0x228(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x1218
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x122d
leaq 0xde9(%rip), %rdi       # 0x2008
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1465
leaq -0x330(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1030
leaq -0x330(%rbp), %rdi
movl $0x2e, %esi
callq 0x1070
movq %rax, -0x230(%rbp)
cmpq $0x0, %rax
je 0x128b
movq -0x230(%rbp), %rdi
leaq 0xda3(%rip), %rsi       # 0x2027
callq 0x1030
jmp 0x129e
leaq -0x330(%rbp), %rdi
leaq 0xd8e(%rip), %rsi       # 0x2027
callq 0x10a0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd7b(%rip), %rsi       # 0x202c
callq 0x1090
movq %rax, -0x338(%rbp)
cmpq $0x0, -0x338(%rbp)
jne 0x12e8
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd55(%rip), %rdi       # 0x202f
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
leaq -0x330(%rbp), %rdi
leaq 0xd51(%rip), %rsi       # 0x2047
callq 0x1090
movq %rax, -0x340(%rbp)
cmpq $0x0, -0x340(%rbp)
jne 0x1328
leaq -0x330(%rbp), %rsi
leaq 0xd15(%rip), %rdi       # 0x202f
movb $0x0, %al
callq 0x1060
xorl %edi, %edi
callq 0x10b0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xd0f(%rip), %rdi       # 0x204a
movb $0x0, %al
callq 0x1060
leaq -0x220(%rbp), %rdi
movq -0x338(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1040
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x136d
jmp 0x1405
cmpl $0x200, -0x18(%rbp)     # imm = 0x200
je 0x13a9
movl -0x18(%rbp), %esi
leaq 0xcde(%rip), %rdi       # 0x205e
movb $0x0, %al
callq 0x1060
cmpl $0x200, -0x18(%rbp)     # imm = 0x200
jge 0x13a7
movslq -0x18(%rbp), %rax
movb $0x0, -0x220(%rbp,%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1387
jmp 0x13a9
leaq -0x228(%rbp), %rdi
movq -0x340(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
leaq -0x220(%rbp), %rdi
movq -0x340(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x10c0
leaq -0x228(%rbp), %rdi
movq -0x340(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
jmp 0x1342
leaq -0x224(%rbp), %rdi
movq -0x340(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
leaq -0x224(%rbp), %rdi
movq -0x340(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x10c0
movq -0x338(%rbp), %rdi
callq 0x1050
movq -0x340(%rbp), %rdi
callq 0x1050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1234
xorl %eax, %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq