// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x240(%rbp), %rdi
leaq 0x29d9(%rip), %rsi      # 0x3bf0
movl $0x200, %edx            # imm = 0x200
callq 0x1060
cmpl $0x2, -0x8(%rbp)
jl 0x1231
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1246
leaq 0xea2(%rip), %rdi       # 0x20da
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x1080
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1463
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xe8d(%rip), %rsi       # 0x20f9
callq 0x1070
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x129d
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xe6d(%rip), %rdi       # 0x20fc
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x1080
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xe64(%rip), %rdi       # 0x2114
movb $0x0, %al
callq 0x1050
movl $0x0, -0x28(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1190
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jge 0x1304
cmpl $0x0, -0x28(%rbp)
je 0x12ff
leaq 0xe36(%rip), %rdi       # 0x212e
movb $0x0, %al
callq 0x1050
jmp 0x144c
cmpl $0x0, -0x18(%rbp)
jne 0x1330
cmpl $0x0, -0x28(%rbp)
je 0x1324
cmpl $0x0, -0x24(%rbp)
je 0x1324
leaq 0xe1f(%rip), %rdi       # 0x213c
movb $0x0, %al
callq 0x1050
movl $0x0, -0x28(%rbp)
jmp 0x143e
movl -0x2c(%rbp), %eax
shll $0x6, %eax
movl -0x18(%rbp), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jl 0x143c
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq 0xde9(%rip), %rdi       # 0x214d
movb $0x0, %al
callq 0x1050
movl -0x2c(%rbp), %eax
sarl $0x15, %eax
andl $0x7, %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
sarl $0xf, %eax
andl $0x3f, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x38(%rbp)
movslq -0x30(%rbp), %rax
cmpq $0x0, -0x240(%rbp,%rax,8)
je 0x1417
cmpl $0x0, -0x30(%rbp)
jne 0x13a9
cmpl $0x0, -0x2c(%rbp)
jne 0x1417
movl -0x2c(%rbp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x13d5
movslq -0x30(%rbp), %rax
movq -0x240(%rbp,%rax,8), %rsi
movl -0x38(%rbp), %edx
leaq 0xd9a(%rip), %rdi       # 0x2166
movb $0x0, %al
callq 0x1050
jmp 0x13f2
movslq -0x30(%rbp), %rax
movq -0x240(%rbp,%rax,8), %rsi
movl -0x38(%rbp), %edx
leaq 0xd84(%rip), %rdi       # 0x216f
movb $0x0, %al
callq 0x1050
cmpl $0x0, -0x34(%rbp)
je 0x1409
movl -0x34(%rbp), %esi
leaq 0xd75(%rip), %rdi       # 0x2177
movb $0x0, %al
callq 0x1050
leaq 0xd6b(%rip), %rdi       # 0x217b
movb $0x0, %al
callq 0x1050
leaq 0xcd9(%rip), %rdi       # 0x20f7
movb $0x0, %al
callq 0x1050
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x143e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x12da
movq -0x40(%rbp), %rdi
callq 0x1040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x124d
xorl %eax, %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq