// File: /workspace/github_c_makefile_star2_O2/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 0x136d
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x136d
movl %edi, %eax
movq %rax, 0x18(%rsp)
pushq $0x1
popq %r14
movq %rbx, 0x10(%rsp)
cmpq 0x18(%rsp), %r14
je 0x1347
movq (%rbx,%r14,8), %rdi
leaq 0xeae(%rip), %rsi       # 0x20c4
callq 0x1080
movq %r14, 0x20(%rsp)
movq (%rbx,%r14,8), %rsi
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1358
xorl %r14d, %r14d
leaq 0xea3(%rip), %rdi       # 0x20df
xorl %eax, %eax
callq 0x1070
xorl %ebp, %ebp
xorl %r13d, %r13d
pushq $0x1
popq %r15
movq 0x8(%rsp), %rdi
callq 0x119c
testl %eax, %eax
js 0x132b
je 0x1319
movl %eax, %ebx
movl %r14d, %r12d
shll $0x6, %r12d
andl $0x3f, %ebx
orl %r12d, %ebx
cmpl $0x3, %ebp
jl 0x131e
leaq 0xe76(%rip), %rdi       # 0x20f9
movl %r13d, %esi
movl %r15d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1070
movl %r12d, %eax
shrl $0xf, %eax
movabsq $0xb412f220b8, %rcx     # imm = 0xB412F220B8
btq %rax, %rcx
jb 0x1308
andl $0x3f, %eax
leaq 0x293e(%rip), %rcx      # 0x3bf0
movq (%rcx,%rax,8), %rsi
jne 0x12bc
testl %ebx, %ebx
jne 0x1308
shrl $0x15, %r12d
andl $0x7, %r12d
andl $0x3fff, %ebx           # imm = 0x3FFF
btl $0x8, %r14d
leaq 0xe3c(%rip), %rdi       # 0x2112
leaq 0xe3e(%rip), %rax       # 0x211b
cmovaeq %rax, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1070
testl %r12d, %r12d
je 0x1300
leaq 0xe2d(%rip), %rdi       # 0x2123
movl %r12d, %esi
xorl %eax, %eax
callq 0x1070
pushq $0x5d
popq %rdi
callq 0x1030
pushq $0xa
popq %rdi
callq 0x1030
incl %r15d
xorl %ebx, %ebx
xorl %ebp, %ebp
jmp 0x1320
movl %r14d, %ebx
jmp 0x1320
incl %ebp
incl %r13d
movl %ebx, %r14d
jmp 0x124c
movq 0x8(%rsp), %rdi
callq 0x1060
movq 0x20(%rsp), %r14
incq %r14
movq 0x10(%rsp), %rbx
jmp 0x1200
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd68(%rip), %rdi       # 0x20c7
xorl %eax, %eax
callq 0x1070
xorl %edi, %edi
callq 0x1090
leaq 0xdc8(%rip), %rdi       # 0x213c
callq 0x1040
jmp 0x1366