// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/sfmtcvt/sfmtcvt.c
// Function: main
int main (int argc, char *argv[])
{
int i, d, d1, j, k, astrt, dstrt, addr, maxaddr[MAXR];
int numr, numf;
unsigned char data[MAXR][MAXA];
char *s, *ppos, *cptr, line[256], oname[256];
FILE *ifile, *ofile;

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: verb file [file...]\n");
	exit (0);  }

s = argv[1];
if ((s != NULL) && (*s++ == '-')) {
	++argv; --argc;
	switch (*s) {
 	case '1':
	    numr = 1; break;
	case '2':
	    numr = 2; break;
	case '4':
	    numr = 4; break;
	default:
	    fprintf (stderr, "Bad option %c\n", *s);
	return 0;  }
	}
else numr = 1;

for (i = 1, numf = 0; i < argc; i++) {
	ifile = fopen (argv[i], "r");
	if (ifile == NULL) {
		printf ("Error opening file: %s\n", argv[i]);
		exit (0);  }

	printf ("Processing file %s\n", argv[i]);
	astrt = 4;
	maxaddr[numf] = 0;
	for (;;) {
		cptr = fgets (line, 256, ifile);
		if (cptr == NULL) break;
		if (line[0] != 'S') continue;
		if (line[1] == '1') dstrt = 8;
		else if (line[1] == '2') dstrt = 10;
		else continue;
		for (k = astrt, addr = 0; k < dstrt; k++) {
			d = HEX (line[k]);
			addr = (addr << 4) + d;  }
		if (addr >= MAXA) {
			printf ("Address %o out of range\n", addr);
			break;  }
		for (k = dstrt; k < (dstrt + 32); k = k + 2, addr++) {
			d = HEX (line[k]);
			d1 = HEX (line[k+1]);
			data[numf][addr] = (d << 4) + d1;  }
		if (addr > maxaddr[numf]) maxaddr[numf] = addr;
		}
	fclose (ifile);
	numf++;
	if (numf >= numr) {
	    for (k = 0; k < numr; k++) {
		if (maxaddr[k] != maxaddr[0]) {
		    printf ("Rom lengths don't match, file 1 = %d, file %d = %d\n",
			maxaddr[0], k, maxaddr[k]);
		    return 0;  }  }
	    strcpy (oname, argv[i]);
            if (ppos = strrchr (oname, '.')) strcpy (ppos, ".bin");
            else strcat (oname, ".bin");
	    ofile = fopen (oname, "wb");
	    if (ofile == NULL) {
		printf ("Error opening file: %s\n", oname);
		exit (0);  }
	    printf ("Output file: %s, ROM size is %d\n", oname, maxaddr[0]);
	    for (k = 0; k < maxaddr[0]; k++) {
		for (j = numr - 1; j >= 0; j--) {
		    fwrite (&data[j][k], 1, 1, ofile);  }  }
	    fclose (ofile);
	    numf = 0;
	    }
	}
if (numf) printf ("Unprocessed files\n");
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20258, %rsp          # imm = 0x20258
cmpl $0x2, %edi
jl 0x1742
movq %rsi, %r15
cmpq $0x0, (%rsi)
je 0x1742
movl %edi, %r14d
movq 0x8(%r15), %rax
movl $0x1, %ebx
testq %rax, %rax
je 0x124d
cmpb $0x2d, (%rax)
jne 0x124d
movzbl 0x1(%rax), %eax
cmpl $0x31, %eax
je 0x123c
cmpl $0x34, %eax
je 0x1237
cmpl $0x32, %eax
jne 0x1725
movl $0x2, %ebx
jmp 0x123c
movl $0x4, %ebx
decl %r14d
cmpl $0x2, %r14d
jb 0x16fe
addq $0x8, %r15
leaq 0x8(%r15), %r12
movq 0x8(%r15), %rdi
leaq 0xe13(%rip), %rsi       # 0x206f
callq 0x10c0
testq %rax, %rax
je 0x16da
movq %rax, %rbp
movl %ebx, %r13d
movl %r14d, %eax
movq %rax, 0x18(%rsp)
leaq 0x1(%r13), %rax
movq %rax, 0x48(%rsp)
movl %r13d, %eax
shll $0xf, %eax
leaq 0x250(%rsp), %rcx
addq %rcx, %rax
addq $-0x8000, %rax          # imm = 0x8000
movq %rax, 0x38(%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movq %r12, 0x8(%rsp)
movq (%r12), %rsi
leaq 0xdcf(%rip), %rdi       # 0x2089
xorl %eax, %eax
callq 0x1070
movslq %r14d, %r12
movl $0x0, 0x20(%rsp,%r12,4)
leaq 0x50(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdx
callq 0x10a0
testq %rax, %rax
je 0x158c
xorl %ebx, %ebx
cmpb $0x53, 0x50(%rsp)
jne 0x1561
movzbl 0x51(%rsp), %eax
cmpl $0x31, %eax
je 0x130f
cmpl $0x32, %eax
jne 0x1561
movl $0xa, %eax
jmp 0x1314
movl $0x8, %eax
xorl %esi, %esi
movl $0x4, %ecx
movsbl 0x50(%rsp,%rcx), %edx
shll $0x4, %esi
cmpl $0x41, %edx
leal -0x37(%rsi,%rdx), %edi
leal -0x30(%rsi,%rdx), %esi
cmovgel %edi, %esi
incq %rcx
cmpq %rcx, %rax
jne 0x131b
cmpl $0x7fff, %esi           # imm = 0x7FFF
jg 0x157e
movslq %esi, %rcx
addl $0x10, %esi
movzbl 0x6e(%rsp,%rax), %edx
movd %edx, %xmm0
movzbl 0x6c(%rsp,%rax), %edx
movd %edx, %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
movzbl 0x6a(%rsp,%rax), %edx
movd %edx, %xmm0
movzbl 0x68(%rsp,%rax), %edx
movd %edx, %xmm2
punpcklbw %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3],xmm2[4],xmm0[4],xmm2[5],xmm0[5],xmm2[6],xmm0[6],xmm2[7],xmm0[7]
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movzbl 0x66(%rsp,%rax), %edx
movd %edx, %xmm0
movzbl 0x64(%rsp,%rax), %edx
movd %edx, %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
movzbl 0x62(%rsp,%rax), %edx
movd %edx, %xmm3
movzbl 0x60(%rsp,%rax), %edx
movd %edx, %xmm0
punpcklbw %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3],xmm0[4],xmm3[4],xmm0[5],xmm3[5],xmm0[6],xmm3[6],xmm0[7],xmm3[7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movzbl 0x5e(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x5c(%rsp,%rax), %edx
movd %edx, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl 0x5a(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x58(%rsp,%rax), %edx
movd %edx, %xmm3
punpcklbw %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3],xmm3[4],xmm1[4],xmm3[5],xmm1[5],xmm3[6],xmm1[6],xmm3[7],xmm1[7]
punpcklwd %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1],xmm3[2],xmm2[2],xmm3[3],xmm2[3]
movzbl 0x56(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x54(%rsp,%rax), %edx
movd %edx, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl 0x52(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x50(%rsp,%rax), %edx
movd %edx, %xmm4
punpcklbw %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1],xmm4[2],xmm1[2],xmm4[3],xmm1[3],xmm4[4],xmm1[4],xmm4[5],xmm1[5],xmm4[6],xmm1[6],xmm4[7],xmm1[7]
punpcklwd %xmm2, %xmm4    # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1],xmm4[2],xmm2[2],xmm4[3],xmm2[3]
punpckldq %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1]
punpcklqdq %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0]
movdqa %xmm4, %xmm0
movdqa 0xbed(%rip), %xmm6      # 0x2010
pcmpgtb %xmm6, %xmm0
movdqa %xmm0, %xmm1
pandn %xmm6, %xmm1
pand 0xbe9(%rip), %xmm0      # 0x2020
por %xmm1, %xmm0
paddb %xmm4, %xmm0
movzbl 0x6f(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x6d(%rsp,%rax), %edx
movd %edx, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl 0x6b(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x69(%rsp,%rax), %edx
movd %edx, %xmm3
punpcklbw %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3],xmm3[4],xmm1[4],xmm3[5],xmm1[5],xmm3[6],xmm1[6],xmm3[7],xmm1[7]
punpcklwd %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1],xmm3[2],xmm2[2],xmm3[3],xmm2[3]
movzbl 0x67(%rsp,%rax), %edx
movd %edx, %xmm1
movzbl 0x65(%rsp,%rax), %edx
movd %edx, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl 0x63(%rsp,%rax), %edx
movd %edx, %xmm4
movzbl 0x61(%rsp,%rax), %edx
movd %edx, %xmm1
punpcklbw %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1],xmm1[2],xmm4[2],xmm1[3],xmm4[3],xmm1[4],xmm4[4],xmm1[5],xmm4[5],xmm1[6],xmm4[6],xmm1[7],xmm4[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movzbl 0x5f(%rsp,%rax), %edx
movd %edx, %xmm2
movzbl 0x5d(%rsp,%rax), %edx
movd %edx, %xmm3
punpcklbw %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1],xmm3[2],xmm2[2],xmm3[3],xmm2[3],xmm3[4],xmm2[4],xmm3[5],xmm2[5],xmm3[6],xmm2[6],xmm3[7],xmm2[7]
movzbl 0x5b(%rsp,%rax), %edx
movd %edx, %xmm2
movzbl 0x59(%rsp,%rax), %edx
movd %edx, %xmm4
punpcklbw %xmm2, %xmm4    # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1],xmm4[2],xmm2[2],xmm4[3],xmm2[3],xmm4[4],xmm2[4],xmm4[5],xmm2[5],xmm4[6],xmm2[6],xmm4[7],xmm2[7]
punpcklwd %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1],xmm4[2],xmm3[2],xmm4[3],xmm3[3]
movzbl 0x57(%rsp,%rax), %edx
movd %edx, %xmm2
movzbl 0x55(%rsp,%rax), %edx
movd %edx, %xmm3
punpcklbw %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1],xmm3[2],xmm2[2],xmm3[3],xmm2[3],xmm3[4],xmm2[4],xmm3[5],xmm2[5],xmm3[6],xmm2[6],xmm3[7],xmm2[7]
movzbl 0x53(%rsp,%rax), %edx
movd %edx, %xmm2
movzbl 0x51(%rsp,%rax), %eax
movd %eax, %xmm5
punpcklbw %xmm2, %xmm5    # xmm5 = xmm5[0],xmm2[0],xmm5[1],xmm2[1],xmm5[2],xmm2[2],xmm5[3],xmm2[3],xmm5[4],xmm2[4],xmm5[5],xmm2[5],xmm5[6],xmm2[6],xmm5[7],xmm2[7]
punpcklwd %xmm3, %xmm5    # xmm5 = xmm5[0],xmm3[0],xmm5[1],xmm3[1],xmm5[2],xmm3[2],xmm5[3],xmm3[3]
punpckldq %xmm4, %xmm5    # xmm5 = xmm5[0],xmm4[0],xmm5[1],xmm4[1]
punpcklqdq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0]
movdqa %xmm5, %xmm1
pcmpgtb %xmm6, %xmm1
movdqa %xmm1, %xmm2
pandn 0xb11(%rip), %xmm2      # 0x2030
pand 0xb19(%rip), %xmm1      # 0x2040
por %xmm2, %xmm1
paddb %xmm5, %xmm1
psllw $0x4, %xmm0
pand 0xb14(%rip), %xmm0      # 0x2050
paddb %xmm1, %xmm0
movq %r12, %rax
shlq $0xf, %rax
addq %rsp, %rax
addq $0x250, %rax            # imm = 0x250
movdqu %xmm0, (%rcx,%rax)
cmpl %ebx, %esi
cmovlel %ebx, %esi
movl %esi, 0x20(%rsp,%r12,4)
movl %esi, %ebx
leaq 0x50(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbp, %rdx
callq 0x10a0
testq %rax, %rax
jne 0x12ea
jmp 0x158c
leaq 0xb18(%rip), %rdi       # 0x209d
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
callq 0x1050
incl %r14d
cmpl %r13d, %r14d
jge 0x15b4
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x18(%rsp), %rax
jne 0x16b5
jmp 0x1712
movl 0x20(%rsp), %ebp
xorl %edx, %edx
leaq 0x150(%rsp), %rbx
movq 0x8(%rsp), %rax
movl 0x20(%rsp,%rdx,4), %ecx
cmpl %ebp, %ecx
jne 0x16ee
incq %rdx
cmpq %rdx, %r13
jne 0x15c7
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x1030
movq %rbx, %rdi
movl $0x2e, %esi
callq 0x1080
testq %rax, %rax
je 0x1604
movb $0x0, 0x4(%rax)
movl $0x6e69622e, (%rax)     # imm = 0x6E69622E
jmp 0x161f
movq %rbx, %rdi
callq 0x1060
movl $0x6e69622e, 0x150(%rsp,%rax) # imm = 0x6E69622E
movb $0x0, 0x154(%rsp,%rax)
movq %r13, 0x40(%rsp)
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xabc(%rip), %rsi       # 0x20ef
callq 0x10c0
testq %rax, %rax
je 0x1755
movq %rax, %r12
leaq 0xaa7(%rip), %rdi       # 0x20f2
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
testl %ebp, %ebp
jle 0x1691
movq 0x38(%rsp), %r15
xorl %r14d, %r14d
movq %r15, %rbx
movq 0x48(%rsp), %r13
movsbl (%rbx), %edi
movq %r12, %rsi
callq 0x1090
decq %r13
addq $-0x8000, %rbx          # imm = 0x8000
cmpq $0x1, %r13
jg 0x166b
incq %r14
incq %r15
cmpq %rbp, %r14
jne 0x1663
movq %r12, %rdi
callq 0x1050
movq 0x10(%rsp), %rax
incq %rax
xorl %r14d, %r14d
cmpq 0x18(%rsp), %rax
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %r13
je 0x16fe
movq %rax, 0x10(%rsp)
leaq (%r15,%rax,8), %r12
movq (%r12), %rdi
leaq 0x9a6(%rip), %rsi       # 0x206f
callq 0x10c0
movq %rax, %rbp
testq %rax, %rax
jne 0x12aa
movq (%r12), %rsi
leaq 0x98c(%rip), %rdi       # 0x2071
xorl %eax, %eax
callq 0x1070
jmp 0x174e
leaq 0x9c1(%rip), %rdi       # 0x20b6
movl %ebp, %esi
xorl %eax, %eax
callq 0x1070
xorl %eax, %eax
addq $0x20258, %rsp          # imm = 0x20258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
je 0x16fe
leaq 0x9f5(%rip), %rdi       # 0x2113
callq 0x1040
jmp 0x16fe
movsbl %al, %edx
movq 0x28c9(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x927(%rip), %rsi       # 0x2060
xorl %eax, %eax
callq 0x10b0
jmp 0x16fe
leaq 0x9dc(%rip), %rdi       # 0x2125
callq 0x1040
xorl %edi, %edi
callq 0x10d0
leaq 0x915(%rip), %rdi       # 0x2071
leaq 0x150(%rsp), %rsi
jmp 0x16e5