// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/extracters/mtdump/mtdump.c
// Function: main
int main (int argc, char *argv[])
{
int obj, i, k, fc, rc, tpos;
unsigned int bc = 0, fmt, rlntsiz;
 unsigned char *s;
 unsigned char bca[4] = { 0,0,0,0 };
int preveof, gapcount, gpos = 0, gincr;
FILE *ifile;
#define MAXRLNT 65536

if ((argc < 2) || (argv[0] == NULL)) {
	printf ("Usage is: mtdump {-secf} file [file...]\n");
	exit (0);  }

s = argv[1];
if ((s != NULL) && (*s++ == '-')) {
	++argv; --argc;
	switch (*s) {
 	case 'S': case 's':
	    fmt = F_STD; rlntsiz = 4; break;
	case 'E': case 'e':
	    fmt = F_E11; rlntsiz = 4; break;
        case 'C': case 'c':
	    fmt = F_TPC; rlntsiz = 2; break;
            /*	case 'F': case 'f': */
/*	    fmt = F_TPF; break; */
	default:
	    fprintf (stderr, "Bad option %c\n", *s);
	    return 0;
	    }
	}
else {	fmt = F_STD;
	rlntsiz = 4;  }

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]);
	tpos = 0; rc = 1; fc = 1; preveof = 0; gapcount = 0;
	printf ("Processing tape file %d\n", fc);
	for (obj = 1;;) {
	    fseek (ifile, tpos, SEEK_SET);
	    k = fread (bca, 1, rlntsiz, ifile);
	    switch (fmt) {
	    case F_STD: case F_E11:
		bc = (((unsigned int) bca[3]) << 24) | (((unsigned int) bca[2]) << 16) |
		    (((unsigned int) bca[1]) << 8) | ((unsigned int) bca[0]);
		break;
	    case F_TPC:
		bc = (((unsigned int) bca[1]) << 8) | ((unsigned int) bca[0]);
	        break;
		}

        if (k && ((bc == 0xFFFFFFFE) | (bc == 0xFFFEFFFF))) {
            if (gapcount == 0)
                gpos = tpos;
            gincr = (bc == 0xFFFFFFFE ? 4 : 2);
            gapcount = gapcount + gincr;
            tpos = tpos + gincr;
            continue;  }
        else if (gapcount) {
            printf ("Obj %d, position %d, erase gap, length = %d (0x%X)\n",
                obj, gpos, gapcount, gapcount);
            obj++;
            gapcount = 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 ("Obj %d, position %d, end of logical tape\n", obj, tpos);
		    break;  }
		preveof = 1;
		printf ("Obj %d, position %d, end of tape file %d\n", obj, tpos, fc);
		fc++; obj++;
		rc = 1;
		tpos = tpos + rlntsiz;  }
	    else if (bc > MAXRLNT) {
		printf ("Invalid record length %d, terminating dump\n", bc);
		break;  }
	    else {
		if (preveof) printf ("Processing tape file %d\n", fc);
		preveof = 0;
		printf ("Obj %d, position %d, record %d, length = %d (0x%X)\n",
		    obj, tpos, rc, bc, bc);
		rc++; obj++;
		switch (fmt) {
		case F_STD:
		    tpos = tpos + 8 + ((bc + 1) & ~1); break;
		case F_E11:
		    tpos = tpos + 8 + bc; break;
		case F_TPC:
		    tpos = tpos + 2 + ((bc + 1) & ~1); break;
		    }
		}
	    }
	fclose (ifile);
	}

return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0x44(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x1060
movl $0x0, -0x50(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x11f4
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1209
leaq 0xe09(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x12ef
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movzbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x12ef
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
decl %eax
movl %eax, -0x8(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x64(%rbp)
subl $0x43, %eax
je 0x12b2
jmp 0x1260
movl -0x64(%rbp), %eax
subl $0x45, %eax
je 0x12a2
jmp 0x126a
movl -0x64(%rbp), %eax
subl $0x53, %eax
je 0x1292
jmp 0x1274
movl -0x64(%rbp), %eax
subl $0x63, %eax
je 0x12b2
jmp 0x127e
movl -0x64(%rbp), %eax
subl $0x65, %eax
je 0x12a2
jmp 0x1288
movl -0x64(%rbp), %eax
subl $0x73, %eax
jne 0x12c2
jmp 0x1292
movl $0x0, -0x30(%rbp)
movl $0x4, -0x34(%rbp)
jmp 0x12ed
movl $0x1, -0x30(%rbp)
movl $0x4, -0x34(%rbp)
jmp 0x12ed
movl $0x2, -0x30(%rbp)
movl $0x2, -0x34(%rbp)
jmp 0x12ed
movq 0x2d2f(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movzbl (%rax), %edx
leaq 0xd53(%rip), %rsi       # 0x202d
movb $0x0, %al
callq 0x1070
movl $0x0, -0x4(%rbp)
jmp 0x164e
jmp 0x12fd
movl $0x0, -0x30(%rbp)
movl $0x4, -0x34(%rbp)
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1647
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd19(%rip), %rsi       # 0x203c
callq 0x1090
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x1354
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xcf9(%rip), %rdi       # 0x203f
movb $0x0, %al
callq 0x1050
xorl %edi, %edi
callq 0x10a0
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xcf0(%rip), %rdi       # 0x2057
movb $0x0, %al
callq 0x1050
movl $0x0, -0x28(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x20(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x20(%rbp), %esi
leaq 0xcd6(%rip), %rdi       # 0x2071
movb $0x0, %al
callq 0x1050
movl $0x1, -0x14(%rbp)
movq -0x60(%rbp), %rdi
movslq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x1080
movl -0x34(%rbp), %eax
movl %eax, %edx
movq -0x60(%rbp), %rcx
leaq -0x44(%rbp), %rdi
movl $0x1, %esi
callq 0x1030
movl %eax, -0x1c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x68(%rbp)
subl $0x2, %eax
jb 0x13e9
jmp 0x13df
movl -0x68(%rbp), %eax
subl $0x2, %eax
je 0x140d
jmp 0x141d
movzbl -0x41(%rbp), %eax
shll $0x18, %eax
movzbl -0x42(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x43(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x44(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
jmp 0x141d
movzbl -0x43(%rbp), %eax
shll $0x8, %eax
movzbl -0x44(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x147f
cmpl $-0x2, -0x2c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0xfffeffff, -0x2c(%rbp) # imm = 0xFFFEFFFF
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
je 0x147f
cmpl $0x0, -0x4c(%rbp)
jne 0x1452
movl -0x28(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x2c(%rbp), %edx
movl $0x2, %eax
movl $0x4, %ecx
cmpl $-0x2, %edx
cmovel %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x28(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x13a9
cmpl $0x0, -0x4c(%rbp)
je 0x14b0
movl -0x14(%rbp), %esi
movl -0x50(%rbp), %edx
movl -0x4c(%rbp), %ecx
movl -0x4c(%rbp), %r8d
leaq 0xbf1(%rip), %rdi       # 0x208a
movb $0x0, %al
callq 0x1050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x4c(%rbp)
jmp 0x14b2
cmpl $0x0, -0x1c(%rbp)
je 0x14be
cmpl $-0x1, -0x2c(%rbp)
jne 0x14d1
leaq 0xbf9(%rip), %rdi       # 0x20be
movb $0x0, %al
callq 0x1050
jmp 0x1630
movl -0x2c(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x14fa
movl -0x24(%rbp), %esi
leaq 0xbec(%rip), %rdi       # 0x20d4
movb $0x0, %al
callq 0x1050
movl -0x2c(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x1564
cmpl $0x0, -0x48(%rbp)
je 0x151f
movl -0x14(%rbp), %esi
movl -0x28(%rbp), %edx
leaq 0xbdc(%rip), %rdi       # 0x20ef
movb $0x0, %al
callq 0x1050
jmp 0x1630
movl $0x1, -0x48(%rbp)
movl -0x14(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x20(%rbp), %ecx
leaq 0xbe3(%rip), %rdi       # 0x2119
movb $0x0, %al
callq 0x1050
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x162b
cmpl $0x10000, -0x2c(%rbp)   # imm = 0x10000
jbe 0x1583
movl -0x2c(%rbp), %esi
leaq 0xbcc(%rip), %rdi       # 0x2143
movb $0x0, %al
callq 0x1050
jmp 0x1630
cmpl $0x0, -0x48(%rbp)
je 0x159a
movl -0x20(%rbp), %esi
leaq 0xade(%rip), %rdi       # 0x2071
movb $0x0, %al
callq 0x1050
movl $0x0, -0x48(%rbp)
movl -0x14(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x24(%rbp), %ecx
movl -0x2c(%rbp), %r9d
leaq 0xbba(%rip), %rdi       # 0x216f
xorl %eax, %eax
movl %r9d, %r8d
callq 0x1050
movl -0x24(%rbp), %eax
incl %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movl %eax, -0x14(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x6c(%rbp)
testl %eax, %eax
je 0x15ef
jmp 0x15db
movl -0x6c(%rbp), %eax
subl $0x1, %eax
je 0x1605
jmp 0x15e5
movl -0x6c(%rbp), %eax
subl $0x2, %eax
je 0x1613
jmp 0x1627
movl -0x28(%rbp), %eax
addl $0x8, %eax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
andl $-0x2, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x1627
movl -0x28(%rbp), %eax
addl $0x8, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x1627
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
andl $-0x2, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x1629
jmp 0x162b
jmp 0x13a9
movq -0x60(%rbp), %rdi
callq 0x1040
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1304
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq