// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/extracters/sdsdump/sdsdump.c
// Function: main
int main (int argc, char *argv[])
{
int i, k, wc, pos, cc, inrec, wd, op, tag, addr;
FILE *ifile;
char *opstr[] = {
	"HLT", "BRU", "EOM", NULL,  NULL,  NULL,  "EOD", NULL,
	"MIY", "BRI", "MIW", "POT", "ETR", NULL,  "MRG", "EOR",
	"NOP", NULL,  "OVF", "EXU", NULL,  NULL,  NULL,  NULL,
	"YIM", NULL,  "WIM", "PIN", NULL,  "STA", "STB", "STX",
	"SKS", "BRX", NULL,  "BRM", NULL,  NULL,  "CPY", NULL,
	"SKE", "BRR", "SKB", "SKN", "SUB", "ADD", "SUC", "ADC",
	"SKR", "MIN", "XMA", "ADM", "MUL", "DIV", "RSH", "LSH",
	"SKM", "LDX", "SKA", "SKG", "SKD", "LDB", "LDA", "EAX" };

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: verb file [file...]\n");
	exit (0);  }

for (i = 1; i < argc; i++) {
	ifile = fopen (argv[i], "rb");
	if (ifile == NULL) {
		printf ("Error opening file: %s\n", argv[i]);
		exit (0);  }
	printf ("Processing input file %s\n", argv[i]);
	inrec = 0; wc = 1;
	for (pos = wd = cc = 0; ;pos++) {
		if ((k = getfc (ifile)) < 0) {
			if (inrec) printf ("Format error\n");
			break;  }
		if (k == 0) {
			if (inrec && cc) printf ("Incomplete word\n");
			inrec = 0;
			continue;  }
		wd = (wd << 6) | (k & 077);
		cc++;
		if (cc >= 4) {
			printf ("Pos = %d, cnt = %d: %08o", pos, wc, wd);
			tag = (wd >> 21) & 07;
			op = (wd >> 15) & 077;
			addr = wd & 037777;
			if (opstr[op] && ((op != 0) || (wd == 0))) {
				if (wd & 040000) printf (" [%s* %o", opstr[op], addr);
				else printf (" [%s %o", opstr[op], addr);
				if (tag) printf (",%o", tag);
				printf ("]");  }
			printf ("\n");
			cc = wd = 0;
			wc++;  }
		}
	fclose (ifile);
	}
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %edi
jl 0x138d
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x138d
movl %edi, %eax
movq %rax, 0x10(%rsp)
movl $0x1, %r14d
movq %rbx, 0x18(%rsp)
movq (%rbx,%r14,8), %rdi
leaq 0xeb1(%rip), %rsi       # 0x20c4
callq 0x1080
movq %r14, 0x20(%rsp)
movq (%rbx,%r14,8), %rsi
testq %rax, %rax
je 0x1378
movq %rax, %rbp
leaq 0xeab(%rip), %rdi       # 0x20df
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
callq 0x119c
testl %eax, %eax
js 0x1347
xorl %r14d, %r14d
movl $0x1, 0xc(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
testl %eax, %eax
je 0x1329
movl %r13d, %ebx
shll $0x6, %ebx
andl $0x3f, %eax
movl %eax, %r12d
orl %ebx, %r12d
cmpl $0x3, %r15d
jl 0x132e
leaq 0xe75(%rip), %rdi       # 0x20f9
movl %r14d, %esi
movl 0xc(%rsp), %r15d
movl %r15d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x1070
movl %ebx, %eax
shrl $0xf, %eax
movabsq $0xb412f220b8, %rcx     # imm = 0xB412F220B8
btq %rax, %rcx
jb 0x130f
andl $0x3f, %eax
leaq 0x2938(%rip), %rcx      # 0x3bf0
movq (%rcx,%rax,8), %rsi
jne 0x12c3
testl %r12d, %r12d
jne 0x130f
shrl $0x15, %ebx
andl $0x7, %ebx
andl $0x3fff, %r12d          # imm = 0x3FFF
btl $0x8, %r13d
leaq 0xe36(%rip), %rdi       # 0x2112
leaq 0xe38(%rip), %rax       # 0x211b
cmovaeq %rax, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1070
testl %ebx, %ebx
je 0x1305
leaq 0xe27(%rip), %rdi       # 0x2123
movl %ebx, %esi
xorl %eax, %eax
callq 0x1070
movl $0x5d, %edi
callq 0x1030
movl $0xa, %edi
callq 0x1030
incl %r15d
movl %r15d, 0xc(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x1331
movl %r13d, %r12d
jmp 0x1331
incl %r15d
incl %r14d
movq %rbp, %rdi
callq 0x119c
movl %r12d, %r13d
testl %eax, %eax
jns 0x125c
movq %rbp, %rdi
callq 0x1060
movq 0x20(%rsp), %r14
incq %r14
cmpq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
jne 0x1208
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd48(%rip), %rdi       # 0x20c7
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x1090
leaq 0xda8(%rip), %rdi       # 0x213c
callq 0x1040
jmp 0x1386