// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0x14(%rsp)
movl $0x200, 0x10(%rsp)      # imm = 0x200
cmpl $0x2, %edi
jl 0x13ed
cmpq $0x0, (%rsi)
je 0x13ed
movl %edi, %eax
movq %rax, 0x18(%rsp)
pushq $0x1
popq %r14
leaq 0x20(%rsp), %r15
leaq 0x10(%rsp), %r13
pushq $0x4
popq %rbp
movq %r14, %r12
movq %rsi, (%rsp)
cmpq 0x18(%rsp), %r12
je 0x13a9
movq (%rsi,%r12,8), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1030
movq %r15, %rdi
pushq $0x2e
popq %rsi
callq 0x1090
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0x125f
movb $0x0, 0x4(%rax)
movl $0x7061742e, (%rax)     # imm = 0x7061742E
movq (%rsp), %rax
movq (%rax,%r12,8), %rbx
jmp 0x1274
movq %r15, %rdi
callq 0x1070
movl $0x7061742e, 0x20(%rsp,%rax) # imm = 0x7061742E
movb $0x0, 0x24(%rsp,%rax)
movq %rbx, %rdi
leaq 0xd8b(%rip), %rsi       # 0x2009
callq 0x10a0
testq %rax, %rax
je 0x13bd
movq %rax, %rbx
movq %r15, %rdi
leaq 0xd8b(%rip), %rsi       # 0x2024
callq 0x10a0
testq %rax, %rax
je 0x13d3
movq %rax, %r15
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0xd69(%rip), %rdi       # 0x2027
xorl %eax, %eax
callq 0x1080
leaq 0x120(%rsp), %r12
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x1050
movq %rax, %r12
cmpl $0x200, %r12d           # imm = 0x200
je 0x131a
testl %r12d, %r12d
je 0x135c
leaq 0xd43(%rip), %rdi       # 0x203b
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
movslq %r12d, %rax
cmpq $0x1ff, %rax            # imm = 0x1FF
jg 0x131a
movb $0x0, 0x120(%rsp,%rax)
incq %rax
jmp 0x1305
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x10c0
movl $0x200, %edx            # imm = 0x200
leaq 0x120(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rcx
callq 0x10c0
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x10c0
jmp 0x12cd
leaq 0x14(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x10c0
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x10c0
movq %rbx, %rdi
callq 0x1060
movq %r15, %rdi
callq 0x1060
movq 0x8(%rsp), %r12
incq %r12
movq (%rsp), %rsi
leaq 0x20(%rsp), %r15
jmp 0x121c
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 0xc3b(%rip), %rdi       # 0x200c
jmp 0x13df
leaq 0xc32(%rip), %rdi       # 0x200c
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1080
xorl %edi, %edi
callq 0x10b0
leaq 0xc5f(%rip), %rdi       # 0x2053
callq 0x1040
jmp 0x13e6