// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/extracters/ckabstape/ckabstape.c
// Function: main
int main(int argc, char **argv)
{
	int totalblks = 0;
	int badblks = 0;
	unsigned int currentwd = 0;
	int bytecnt = 0;	
	int col = 0;
	int framecount;
	unsigned int cksum;
	unsigned int adr;

        (void) argc;
        (void) argv;

	/*
	 *  read 3 chars and pack them in a word 
	 */
        do {
	     currentwd = readframe();
	     printf("%010o ", currentwd);
	     printf("%c %c %c ",sixbit((currentwd & 0770000) >>12),
                                 sixbit((currentwd & 007700) >>6),
			         sixbit(currentwd & 077) );
	     col++;
	     if(col == 4){
	      printf("\n");
	      col = 0;
	     }
	     if(currentwd & 00010000000) {
	      printf("\n loader end ----\n");
	     /*
	      * start looking for binary data frames
	      */
	      while(1){
	     /*
	      * frames start at the first 0x80 punched
	      * (check is in readframe..)
	      */

                  adr = readframe() & 0777777;		/*staring adr */
	       cksum = adr;
	       printf("ADR: %010o\n", adr);

	       framecount = readframe() & 0777777;	/* word count */
	       cksum += framecount;
	       framecount = -(0xfffe0000 | framecount); /* sign extend */
	       printf("CNT: %010o (%d)\n", framecount, framecount);

	       if((adr & 0700000) != 0){
	        printf("FRAMECOUNT == 0 START ADR == %06o\n", adr);
		printf("TOTAL BLKS %d TOTAL ERRS %d\n", totalblks, badblks);
	        exit(0);
	       }

	       currentwd = readframe() & 0777777;		/* checksum */
	       cksum += currentwd;
	       printf("CKS: %06o\n", currentwd);
	       /*
		* read all the data words
	        */
	       while(framecount > 0){
	 	currentwd = readframe();
	        cksum += currentwd & 0777777;
		printf("%05o: %06o  ",adr++, currentwd & 0777777);
		disasm(currentwd & 0777777);
	        printf("   ; %c%c%c ",sixbit((currentwd & 0770000) >>12),
                                 sixbit((currentwd & 007700) >>6),
                                 sixbit(currentwd & 077) );
 		printf("\n");
		framecount--;
	       }

	       if(cksum&0777777){
	        printf("****BAD CKSUM**** %06o\n",cksum&0777777);
	        badblks++;
	       }

	       totalblks++;
	      }
	     }
        } while(!feof(stdin));

	if(bytecnt > 0){
	 printf("%d chrs left\n", bytecnt);
	}

        exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
callq 0x1210
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
leaq 0x133c(%rip), %rdi      # 0x33f7
movb $0x0, %al
callq 0x1030
movl -0x1c(%rbp), %eax
andl $0x3f000, %eax          # imm = 0x3F000
shrl $0xc, %eax
movsbl %al, %edi
callq 0x1170
movsbl %al, %eax
movl %eax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
andl $0xfc0, %eax            # imm = 0xFC0
shrl $0x6, %eax
movsbl %al, %edi
callq 0x1170
movsbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %edi
callq 0x1170
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
movsbl %al, %ecx
leaq 0x12ec(%rip), %rdi      # 0x33fe
movb $0x0, %al
callq 0x1030
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jne 0x213d
leaq 0x1307(%rip), %rdi      # 0x3436
movb $0x0, %al
callq 0x1030
movl $0x0, -0x24(%rbp)
movl -0x1c(%rbp), %eax
andl $0x200000, %eax         # imm = 0x200000
cmpl $0x0, %eax
je 0x2318
leaq 0x12b3(%rip), %rdi      # 0x3408
movb $0x0, %al
callq 0x1030
callq 0x1210
andl $0x3ffff, %eax          # imm = 0x3FFFF
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %esi
leaq 0x12a2(%rip), %rdi      # 0x341b
movb $0x0, %al
callq 0x1030
callq 0x1210
andl $0x3ffff, %eax          # imm = 0x3FFFF
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %ecx
orl $0xfffe0000, %ecx       # imm = 0xFFFE0000
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %esi
movl -0x28(%rbp), %edx
leaq 0x1274(%rip), %rdi      # 0x3427
movb $0x0, %al
callq 0x1030
movl -0x30(%rbp), %eax
andl $0x38000, %eax          # imm = 0x38000
cmpl $0x0, %eax
je 0x21f3
movl -0x30(%rbp), %esi
leaq 0x1267(%rip), %rdi      # 0x3438
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq 0x1276(%rip), %rdi      # 0x345b
movb $0x0, %al
callq 0x1030
xorl %edi, %edi
callq 0x1060
callq 0x1210
andl $0x3ffff, %eax          # imm = 0x3FFFF
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %esi
leaq 0x1265(%rip), %rdi      # 0x3478
movb $0x0, %al
callq 0x1030
cmpl $0x0, -0x28(%rbp)
jle 0x22dd
callq 0x1210
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3ffff, %eax          # imm = 0x3FFFF
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %edx
andl $0x3ffff, %edx          # imm = 0x3FFFF
leaq 0x122e(%rip), %rdi      # 0x3483
movb $0x0, %al
callq 0x1030
movl -0x1c(%rbp), %edi
andl $0x3ffff, %edi          # imm = 0x3FFFF
callq 0x1390
movl -0x1c(%rbp), %eax
andl $0x3f000, %eax          # imm = 0x3F000
shrl $0xc, %eax
movsbl %al, %edi
callq 0x1170
movsbl %al, %eax
movl %eax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
andl $0xfc0, %eax            # imm = 0xFC0
shrl $0x6, %eax
movsbl %al, %edi
callq 0x1170
movsbl %al, %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %edi
callq 0x1170
movl -0x40(%rbp), %esi
movl -0x3c(%rbp), %edx
movsbl %al, %ecx
leaq 0x11d6(%rip), %rdi      # 0x3490
movb $0x0, %al
callq 0x1030
leaq 0x116e(%rip), %rdi      # 0x3436
movb $0x0, %al
callq 0x1030
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x221a
movl -0x2c(%rbp), %eax
andl $0x3ffff, %eax          # imm = 0x3FFFF
cmpl $0x0, %eax
je 0x230a
movl -0x2c(%rbp), %esi
andl $0x3ffff, %esi          # imm = 0x3FFFF
leaq 0x11a3(%rip), %rdi      # 0x349d
movb $0x0, %al
callq 0x1030
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x215c
jmp 0x231a
movq 0x2cbf(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
callq 0x1050
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x20a9
cmpl $0x0, -0x20(%rbp)
jle 0x2350
movl -0x20(%rbp), %esi
leaq 0x116c(%rip), %rdi      # 0x34b5
movb $0x0, %al
callq 0x1030
xorl %edi, %edi
callq 0x1060