// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/extracters/tpdump/tpdump.c
// Function: main
int main ( int argc, char* argv[] )
{ FILE* fi;
  int all;              /* "print all of a record, even blank lines" */
  char* bcd_to_ascii;   /* Translation table, ..._a or ..._h */
  int cl;               /* Command line argument index */
  int dowm;             /* "do word marks" */
  int even;             /* Require even-length records */
  int i, j;             /* Subscript, loop inductor */
  int nb;               /* Number of characters in print buffer so far */
  int nf, nft;          /* Number of "files" */
  int np;               /* Number of characters processed so far */
  int nr;               /* Number of records dumped so far */
  char pr[101];         /* Buffer to print tape contents */
  size_t recsiz, recsiz2;    /* Record size before, after */
  char wm[101];         /* Buffer to print word marks */

  if ( argc < 2 )
  { usage( argv );
    return(1);
  }

  all = 0;
  bcd_to_ascii = bcd_to_ascii_a;
  dowm = 0;
  even = 1;
  nf = 1;
  for ( cl=1; cl<=argc; cl++ )
  { if ( argv[cl][0] != '-' ) break;
    if ( argv[cl][1] == 'w' ) dowm = 1;
    else if ( argv[cl][1] == 'a' ) all = 1;
    else if ( argv[cl][1] == 'e' ) even = 0;
    else if ( argv[cl][1] == 'h' ) bcd_to_ascii = bcd_to_ascii_h;
    else if ( argv[cl][1] == 'o' ) bcd_to_ascii = bcd_to_ascii_old;
    else if ( sscanf(argv[cl], "%d", &nft ) ) nf = -nft;
    else
    { usage ( argv );
      return(1);
    }
  }

  fi = fopen ( argv[cl], "r" );
  if ( fi == NULL )
  { printf ( "Unable to open %s\n", argv[cl] );
    return(2);
  }
  bcd_to_ascii[BCD_BLANK] = bcd_to_ascii[BCD_ALT]; /* use '^' for blank */
  nft = 1;
  if ( nf > 1 ) printf ( "File %d\n", nft );
  while ( nf > 0 )
  { nf--;
    for ( np=0; np<100; pr[np++]='.' ); 
    pr[100] = '\0';
    for ( np=5; np<=100; np+=5 )    /* Print a row of dots and column numbers */
      for ( nb=1, i=np; i>0; i/=10, nb++ ) pr[np-nb] = '0' + ( i%10 );
    printf ( "       %s\n", pr );
    nr = 0;
    while ( (recsiz = read_len ( fi )) )
    { nb = 1;
      nr++;
      i = recsiz;
      while ( i )
      { for ( np=0; np<101; pr[np]='^',wm[np++]=' ') ; /* Clear buffers */
        for ( np=0; i>0 && np<100; np++ )
        { if ( fread ( &pr[np], 1, 1, fi ) <= 0 )
          { printf ( "Error reading %s\n", argv[cl] );
            return(3);
          }
          i--;
          pr[np] = bcd_to_ascii[(unsigned int)pr[np]];
          if ( dowm )
            if ( pr[np] == bcd_to_ascii[BCD_WM] ) wm[np--] = '1';
        }
        for ( j=np--; j>=0 && pr[j] == bcd_to_ascii[BCD_ALT] && 
                              wm[j] == ' '; j-- ) ;
        if ( ( j >= 0 ) || ( nb == 1 ) || all || ( i == 0 ) )
        { printf ( "%5d: ", nb );
          pr[np+1] = '\0';
          printf ( "%s", pr );
          if ( nb == 1 )
          { for ( j=np ; j++<100 ; printf ( " " ) ) ;
            printf ( "  Record %d", nr );
          }
          printf ( "\n" );
          if ( dowm )
          { for ( ; np >= 0 && wm[np] == ' '; np-- );
            wm[++np] = '\0';
            printf ( "       %s\n", wm );
          }
        } 
        nb += 100;
      }
      if ( (recsiz & 1) && even ) fread ( pr, 1, 1, fi );
      recsiz2 = read_len ( fi );
      if ( recsiz2 != recsiz )
      { printf("Unequal starting and ending record sizes: %d != %d\n",
          recsiz, recsiz2);
        return(4);
      }
    }
    if ( nf > 0 ) printf ( "File %d\n", ++nft );
  }
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
cmpl $0x2, %edi
jge 0x12ce
movq %r14, %rdi
callq 0x123c
movl $0x1, %ebp
jmp 0x17e2
movl %edi, %r13d
incl %r13d
leaq 0x2dc5(%rip), %r12      # 0x40a0
movl $0x1, %edx
movl $0x1, %r15d
leaq 0x2df3(%rip), %rbx      # 0x40e0
leaq 0x2d6c(%rip), %rbp      # 0x4060
movl $0x0, 0x14(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq (%r14,%r15,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x1399
movzbl 0x1(%rdi), %eax
cmpl $0x67, %eax
jle 0x133b
cmpl $0x68, %eax
je 0x134f
cmpl $0x6f, %eax
je 0x1354
cmpl $0x77, %eax
jne 0x1363
movl $0x1, 0x8(%rsp)
jmp 0x1384
cmpl $0x61, %eax
je 0x1359
cmpl $0x65, %eax
jne 0x1363
movl $0x0, 0x10(%rsp)
jmp 0x1384
movq %rbx, %r12
jmp 0x1384
movq %rbp, %r12
jmp 0x1384
movl $0x1, 0x14(%rsp)
jmp 0x1384
leaq 0xd45(%rip), %rsi       # 0x20af
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
je 0x12bc
xorl %edx, %edx
subl 0x4(%rsp), %edx
incq %r15
cmpq %r15, %r13
jne 0x130c
movq %rdx, %rbx
movq %r12, 0x20(%rsp)
movq %r13, %r15
jmp 0x13a1
movq %rdx, %rbx
movq %r12, 0x20(%rsp)
movq (%r14,%r15,8), %rdi
leaq 0xcb6(%rip), %rsi       # 0x2062
callq 0x1080
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x13ee
movq 0x20(%rsp), %rcx
movb 0x10(%rcx), %al
movb %al, (%rcx)
movl $0x1, 0x4(%rsp)
movq %rbx, %r10
cmpl $0x2, %r10d
jl 0x140a
leaq 0xc9a(%rip), %rdi       # 0x2077
movl $0x1, %esi
xorl %eax, %eax
callq 0x1060
movq %rbx, %r10
jmp 0x1414
movq (%r14,%r15,8), %rsi
leaq 0xc6b(%rip), %rdi       # 0x2064
xorl %eax, %eax
callq 0x1060
movl $0x2, %ebp
jmp 0x17e2
cmpl $0x1, %r10d
jne 0x17e0
leaq 0x54(%rsp), %rax
movaps 0xbf0(%rip), %xmm0      # 0x2010
movl $0xcccccccd, %ebx       # imm = 0xCCCCCCCD
movq %r14, 0x48(%rsp)
movq %r15, 0x40(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movl $0x2e2e2e2e, 0xb0(%rsp) # imm = 0x2E2E2E2E
movb $0x0, 0xb4(%rsp)
movl $0x5, %ecx
movq %rax, %rdx
movl %ecx, %esi
movl %esi, %edi
imulq %rbx, %rdi
shrq $0x23, %rdi
leal (%rdi,%rdi), %r8d
leal (%r8,%r8,4), %r8d
movl %esi, %r9d
subl %r8d, %r9d
orb $0x30, %r9b
movb %r9b, (%rdx)
decq %rdx
cmpl $0x9, %esi
movl %edi, %esi
ja 0x1473
leaq 0x5(%rcx), %rdx
addq $0x5, %rax
cmpq $0x60, %rcx
movq %rdx, %rcx
jb 0x146e
movq %r10, 0x30(%rsp)
leal -0x1(%r10), %eax
movl %eax, 0x28(%rsp)
xorl %ebp, %ebp
leaq 0xbbd(%rip), %rdi       # 0x2080
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
movq 0x18(%rsp), %rdi
callq 0x118c
testq %rax, %rax
je 0x1777
incl %ebp
movl %ebp, 0xc(%rsp)
movl $0x1, %r14d
movq %rax, 0x38(%rsp)
movl %eax, %r12d
movabsq $0x5e5e5e5e5e5e5e5e, %rax # imm = 0x5E5E5E5E5E5E5E5E
movq %rax, 0xad(%rsp)
movaps 0xb11(%rip), %xmm0      # 0x2020
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps 0xaf3(%rip), %xmm0      # 0x2030
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0x110(%rsp)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x11d(%rsp)
testl %r12d, %r12d
jle 0x1615
movl %r14d, 0x2c(%rsp)
xorl %ebp, %ebp
movl %r12d, %r15d
movslq %ebp, %r14
leaq (%rsp,%r14), %r12
addq $0x50, %r12
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movq 0x18(%rsp), %rcx
callq 0x1050
testq %rax, %rax
je 0x17bd
movsbq (%r12), %rax
movl %eax, %eax
movq 0x20(%rsp), %rcx
movb (%rcx,%rax), %al
movb %al, (%r12)
cmpl $0x0, 0x8(%rsp)
je 0x15ee
movl %ebp, %r13d
cmpb 0x1d(%rcx), %al
jne 0x15f1
leal -0x1(%r14), %r13d
movb $0x31, 0xc0(%rsp,%r14)
jmp 0x15f1
movl %ebp, %r13d
leal 0x1(%r13), %ebp
leal -0x1(%r15), %r12d
cmpl $0x2, %r15d
jb 0x1608
movl %r12d, %r15d
cmpl $0x63, %r13d
jl 0x1592
cmpl $-0x1, %r13d
movl 0x2c(%rsp), %r14d
jge 0x161d
jmp 0x1640
xorl %ebp, %ebp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %rax
movb 0x10(%rax), %al
movl %ebp, %edx
movl %edx, %ecx
cmpb %al, 0x50(%rsp,%rcx)
jne 0x165c
cmpb $0x20, 0xc0(%rsp,%rcx)
jne 0x165c
leal -0x1(%rcx), %edx
testl %ecx, %ecx
jg 0x1627
cmpl $0x1, %r14d
sete %r15b
je 0x1664
cmpl $0x0, 0x14(%rsp)
jne 0x1664
testl %r12d, %r12d
jne 0x1724
jmp 0x1664
cmpl $0x1, %r14d
sete %r15b
leaq 0xa32(%rip), %rdi       # 0x209d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1060
movslq %ebp, %rax
movb $0x0, 0x50(%rsp,%rax)
leaq 0xa1f(%rip), %rdi       # 0x20a3
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
testb %r15b, %r15b
je 0x16c9
movl %r14d, %r15d
cmpl $0x64, %ebp
jg 0x16b4
leal -0x1(%r13), %r14d
movl $0x20, %edi
callq 0x1030
incl %r14d
cmpl $0x63, %r14d
jl 0x16a1
leaq 0x9eb(%rip), %rdi       # 0x20a6
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x1060
movl %r15d, %r14d
movl $0xa, %edi
callq 0x1030
cmpl $0x0, 0x8(%rsp)
je 0x1724
testl %ebp, %ebp
jle 0x1703
movl %r13d, %eax
cmpb $0x20, 0xc0(%rsp,%rax)
jne 0x16fd
leal -0x1(%r13), %eax
testl %r13d, %r13d
movl %eax, %r13d
jg 0x16de
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
incl %r13d
movl %r13d, %ebp
movslq %ebp, %rax
movb $0x0, 0xc0(%rsp,%rax)
leaq 0x96b(%rip), %rdi       # 0x2080
leaq 0xc0(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
addl $0x64, %r14d
testl %r12d, %r12d
jne 0x14f6
cmpl $0x0, 0x10(%rsp)
setne %al
movq 0x38(%rsp), %r12
andb %r12b, %al
cmpb $0x1, %al
jne 0x175e
movl $0x1, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq 0x18(%rsp), %rcx
callq 0x1050
movq 0x18(%rsp), %rdi
callq 0x118c
cmpq %r12, %rax
movl 0xc(%rsp), %ebp
je 0x14cf
jmp 0x17f6
movq 0x30(%rsp), %rcx
cmpl $0x1, %ecx
je 0x17e0
movl 0x4(%rsp), %esi
incl %esi
movl %esi, 0x4(%rsp)
xorl %ebp, %ebp
leaq 0x8e3(%rip), %rdi       # 0x2077
xorl %eax, %eax
movq %rcx, %r12
callq 0x1060
cmpl $0x1, %r12d
movl 0x28(%rsp), %eax
movl %eax, %r10d
leaq 0x54(%rsp), %rax
movaps 0x85b(%rip), %xmm0      # 0x2010
jg 0x142f
jmp 0x17e2
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x8b9(%rip), %rdi       # 0x208b
xorl %eax, %eax
callq 0x1060
movl $0x3, %ebp
jmp 0x17e2
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8b5(%rip), %rdi       # 0x20b2
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1060
movl $0x4, %ebp
jmp 0x17e2