// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/extracters/mmdir/mmdir.c
// Function: main
int main (int argc, char *argv[])
{
int obj, i, k, fc, rc, tpos, sa, ea, fr, fq;
unsigned char b[53];
unsigned char bca[4];
unsigned int bc;
int preveof;
FILE *ifile;
#define MAXRLNT 65536

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]);
	    return 0;  }
	printf ("Processing input file %s\n", argv[i]);
	tpos = 0; rc = 1; fc = 0; preveof = 0;
	for (;;) {
	    fseek (ifile, tpos, SEEK_SET);
	    k = fread (bca, 1, 4, ifile);
	    bc = (((unsigned int) bca[3]) << 24) | (((unsigned int) bca[2]) << 16) |
		(((unsigned int) bca[1]) << 8) | ((unsigned int) bca[0]);
	    if ((k == 0) || (bc == 0xFFFFFFFF)) {
		printf ("End of physical tape\n");
		break;  }
	    if (bc & 0x80000000) {
		printf ("Error marker at record %d\n", rc);
		bc = bc & ~0x80000000;  }
	    if (bc == 0) {
		if (preveof) {
		    printf ("End of logical tape\n");
		    break;  }
		preveof = 1;
		fc++; obj++;
		rc = 1;
		tpos = tpos + 4;  }
	    else if (bc > MAXRLNT) {
		printf ("Invalid record length %d, terminating\n", bc);
		break;  }
	    else {
		tpos = tpos + 8 + ((bc + 1) & ~1);
		preveof = 0;
		if (fc && (rc == 1)) {
		    if (bc != 52) {
			printf ("Invalid record length %d, terminating\n", bc);
			break;  }
		    fread (b, 1, 52, ifile);
		    sa = (((unsigned int) b[18]) << 16) |
			(((unsigned int) b[19]) << 8) | ((unsigned int) b[20]);
		    ea = (((unsigned int) b[21]) << 16) |
			(((unsigned int) b[22]) << 8) | ((unsigned int) b[23]);
		    fr = b[27] >> 4;
		    fq = b[27] & 0xF;
		    printf ("%3d %c%c%c 06-%c%c%c", fc,
			b[0], b[1], b[2], b[3], b[4], b[5]);
		    if (fr) printf ("F0%X", fr);
		    else printf ("   ");
		    printf ("R%c%c%c%c %c%c  ",
			b[6], b[7], b[25], b[26], b[28], b[29]);
		    b[18] = b[51] = b[52] = 0;
		    printf ("%s%s  %06X %06X %X\n",
			&b[8], &b[30], sa, ea, fq);
		    }
		rc++;  }
	    }
	fclose (ifile);
	}
return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
cmpl $0x2, %edi
jl 0x14bd
movq %rsi, %rbx
cmpq $0x0, (%rsi)
je 0x14bd
movl %edi, %eax
movq %rax, 0x78(%rsp)
pushq $0x1
popq %r14
leaq 0x10(%rsp), %r15
pushq $0x4
popq %r12
movq %r14, %r13
movq %rbx, 0x70(%rsp)
cmpq 0x78(%rsp), %r13
je 0x14a9
movq (%rbx,%r13,8), %rdi
leaq 0xe0f(%rip), %rsi       # 0x2004
callq 0x1080
movq (%rbx,%r13,8), %rsi
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x149b
movq %r13, 0x80(%rsp)
xorl %ebp, %ebp
leaq 0xe02(%rip), %rdi       # 0x201f
xorl %eax, %eax
callq 0x1060
movb $0x1, %bl
movl $0x0, 0x14(%rsp)
movq 0x60(%rsp), %r13
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
movq %rbp, 0x68(%rsp)
movslq %ebp, %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x1070
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1040
testl %eax, %eax
je 0x1469
movzbl 0x13(%rsp), %eax
shll $0x18, %eax
movzbl 0x12(%rsp), %ecx
shll $0x10, %ecx
movzwl 0x10(%rsp), %ebp
orl %ecx, %ebp
orl %eax, %ebp
cmpl $-0x1, %ebp
je 0x1469
testl %eax, %eax
jns 0x12a3
leaq 0xda7(%rip), %rdi       # 0x2039
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x1060
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
testl %ebp, %ebp
je 0x143f
cmpl $0x10001, %ebp          # imm = 0x10001
jae 0x1457
cmpl $0x0, 0x14(%rsp)
setne %al
movl 0xc(%rsp), %edx
cmpl $0x1, %edx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x141d
cmpl $0x34, %ebp
jne 0x1457
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
pushq $0x34
popq %rdx
movq %r13, %rcx
callq 0x1040
movzbl 0x32(%rsp), %r14d
movzbl 0x33(%rsp), %r13d
movzbl 0x34(%rsp), %eax
movl %eax, 0x18(%rsp)
movzbl 0x35(%rsp), %r15d
movzbl 0x36(%rsp), %r12d
movzbl 0x37(%rsp), %eax
movl %eax, 0x1c(%rsp)
movzbl 0x3b(%rsp), %ebx
movzbl 0x20(%rsp), %edx
movzbl 0x21(%rsp), %ecx
movzbl 0x22(%rsp), %r8d
movzbl 0x23(%rsp), %r9d
movzbl 0x24(%rsp), %r10d
movzbl 0x25(%rsp), %r11d
leaq 0xd33(%rip), %rdi       # 0x207b
movl 0x14(%rsp), %esi
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x1060
popq %rcx
popq %rdx
cmpl $0x10, %ebx
jae 0x136e
leaq 0xd30(%rip), %rdi       # 0x2095
xorl %eax, %eax
callq 0x1060
jmp 0x1381
movl %ebx, %esi
shrl $0x4, %esi
leaq 0xd16(%rip), %rdi       # 0x2090
xorl %eax, %eax
callq 0x1060
shll $0x10, %r14d
shll $0x8, %r13d
orl %r14d, %r13d
addl 0x18(%rsp), %r13d
shll $0x10, %r15d
shll $0x8, %r12d
orl %r15d, %r12d
addl 0x1c(%rsp), %r12d
andl $0xf, %ebx
movzbl 0x26(%rsp), %esi
movzbl 0x27(%rsp), %edx
movzbl 0x39(%rsp), %ecx
movzbl 0x3a(%rsp), %r8d
movzbl 0x3c(%rsp), %r9d
movzbl 0x3d(%rsp), %r10d
subq $0x8, %rsp
leaq 0xcc9(%rip), %rdi       # 0x2099
xorl %eax, %eax
pushq %r10
callq 0x1060
popq %rcx
popq %rdx
andw $0x0, 0x53(%rsp)
movb $0x0, 0x32(%rsp)
leaq 0xcbd(%rip), %rdi       # 0x20aa
leaq 0x28(%rsp), %rsi
leaq 0x3e(%rsp), %rdx
movl %r13d, %ecx
movl %r12d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x1060
pushq $0x1
popq %r14
leaq 0x10(%rsp), %r15
pushq $0x4
popq %r12
movq 0x60(%rsp), %r13
movl 0xc(%rsp), %edx
incl %ebp
andl $0x3fffe, %ebp          # imm = 0x3FFFE
movq 0x68(%rsp), %rax
addl %ebp, %eax
addl $0x8, %eax
movq %rax, %rbp
incl %edx
movl %edx, 0xc(%rsp)
movb $0x1, %bl
jmp 0x123a
testb $0x1, %bl
je 0x1492
incl 0x14(%rsp)
movq 0x68(%rsp), %rbp
addl $0x4, %ebp
xorl %ebx, %ebx
jmp 0x1233
leaq 0xbf6(%rip), %rdi       # 0x2054
movl %ebp, %esi
xorl %eax, %eax
callq 0x1060
jmp 0x1475
leaq 0xc62(%rip), %rdi       # 0x20d2
callq 0x1030
movq %r13, %rdi
callq 0x1050
movq 0x80(%rsp), %r13
incq %r13
movq 0x70(%rsp), %rbx
jmp 0x11df
leaq 0xc25(%rip), %rdi       # 0x20be
jmp 0x1470
leaq 0xb65(%rip), %rdi       # 0x2007
xorl %eax, %eax
callq 0x1060
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc23(%rip), %rdi       # 0x20e7
callq 0x1030
xorl %edi, %edi
callq 0x1090