// File: /workspace/github_c_makefile_star2_O2/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, %r13
cmpl $0x2, %edi
jge 0x12bb
movq %r13, %rdi
callq 0x122c
pushq $0x1
jmp 0x16bd
movl %edi, %r15d
pushq $0x1
popq %rbp
incl %r15d
leaq 0x2dd5(%rip), %rbx      # 0x40a0
pushq $0x1
popq %r14
leaq 0x8(%rsp), %r12
movl $0x0, 0xc(%rsp)
movl %ebp, 0x18(%rsp)
movl %ebp, %edx
movl $0x0, 0x1c(%rsp)
cmpq %r14, %r15
je 0x1362
movq (%r13,%r14,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x1367
movzbl 0x1(%rdi), %eax
cmpl $0x77, %eax
je 0x1359
cmpl $0x65, %eax
je 0x131c
cmpl $0x68, %eax
je 0x132f
cmpl $0x6f, %eax
je 0x1326
cmpl $0x61, %eax
jne 0x1338
movl %ebp, 0x1c(%rsp)
jmp 0x135d
movl $0x0, 0x18(%rsp)
jmp 0x135d
leaq 0x2d33(%rip), %rbx      # 0x4060
jmp 0x135d
leaq 0x2daa(%rip), %rbx      # 0x40e0
jmp 0x135d
leaq 0xd34(%rip), %rsi       # 0x2073
movq %r12, %rdx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
je 0x12ac
xorl %edx, %edx
subl 0x8(%rsp), %edx
jmp 0x135d
movl %ebp, 0xc(%rsp)
incq %r14
jmp 0x12ea
movq %rdx, %r12
jmp 0x136d
movq %rdx, %r12
movq %r14, %r15
movq (%r13,%r15,8), %rdi
leaq 0xcad(%rip), %rsi       # 0x2026
callq 0x1080
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x16a8
movq %r15, 0x40(%rsp)
movq %r13, 0x48(%rsp)
movb 0x10(%rbx), %al
movb %al, (%rbx)
movl $0x1, 0x8(%rsp)
movq %r12, %r8
cmpl $0x2, %r8d
jl 0x13c3
leaq 0xc88(%rip), %rdi       # 0x203b
pushq $0x1
popq %rsi
xorl %eax, %eax
movq %r8, %r14
callq 0x1060
movq %r14, %r8
leaq 0x54(%rsp), %rcx
pushq $0x5
popq %rsi
pushq $0xa
popq %rbp
leaq 0xc6f(%rip), %rdi       # 0x2044
leaq 0x50(%rsp), %r14
xorl %eax, %eax
testl %r8d, %r8d
jle 0x16be
cmpq $0x64, %rax
je 0x13f5
movb $0x2e, 0x50(%rsp,%rax)
incq %rax
jmp 0x13e5
movb $0x0, 0xb4(%rsp)
cmpq $0x64, %rsi
ja 0x1425
movq %rcx, %r9
movl %esi, %eax
testl %eax, %eax
je 0x141b
xorl %edx, %edx
divl %ebp
orb $0x30, %dl
movb %dl, (%r9)
decq %r9
jmp 0x1408
addq $0x5, %rsi
addq $0x5, %rcx
jmp 0x13fd
movq %r8, 0x38(%rsp)
leal -0x1(%r8), %eax
movl %eax, 0x2c(%rsp)
movl $0x0, 0x10(%rsp)
movq %r14, %rsi
xorl %eax, %eax
callq 0x1060
movq 0x20(%rsp), %rdi
callq 0x118c
testq %rax, %rax
je 0x1635
incl 0x10(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, %r14d
pushq $0x1
popq %r15
testl %r14d, %r14d
je 0x15f0
xorl %eax, %eax
cmpq $0x65, %rax
je 0x148a
movb $0x5e, 0x50(%rsp,%rax)
movb $0x20, 0xc0(%rsp,%rax)
incq %rax
jmp 0x1472
movl %r15d, 0x14(%rsp)
xorl %r15d, %r15d
movslq %r15d, %r13
testl %r14d, %r14d
jle 0x14f2
cmpl $0x63, %r15d
jg 0x14f2
leaq (%rsp,%r13), %r12
addq $0x50, %r12
movq %r12, %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq 0x20(%rsp), %rcx
callq 0x1050
testq %rax, %rax
je 0x1688
movsbq (%r12), %rax
movl %eax, %eax
movb (%rbx,%rax), %al
movb %al, (%r12)
cmpl $0x0, 0xc(%rsp)
je 0x14ea
cmpb 0x1d(%rbx), %al
jne 0x14ea
decl %r15d
movb $0x31, 0xc0(%rsp,%r13)
incl %r15d
decl %r14d
jmp 0x1492
leal -0x1(%r15), %r12d
movl %r15d, %eax
testl %r15d, %r15d
js 0x1517
movl %eax, %ecx
movb 0x50(%rsp,%rcx), %dl
cmpb 0x10(%rbx), %dl
jne 0x1517
leal -0x1(%rax), %r15d
cmpb $0x20, 0xc0(%rsp,%rcx)
je 0x14f6
testl %r14d, %r14d
movl 0x14(%rsp), %r15d
je 0x1536
testl %eax, %eax
jns 0x1536
cmpl $0x1, %r15d
je 0x1536
cmpl $0x0, 0x1c(%rsp)
je 0x15e7
leaq 0xb24(%rip), %rdi       # 0x2061
movl %r15d, %esi
xorl %eax, %eax
callq 0x1060
movb $0x0, 0x50(%rsp,%r13)
leaq 0xb13(%rip), %rdi       # 0x2067
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
cmpl $0x1, %r15d
jne 0x1597
movl %r12d, %r15d
pushq $0x20
popq %r13
cmpl $0x63, %r15d
jg 0x1580
incl %r15d
movl %r13d, %edi
callq 0x1030
jmp 0x156d
leaq 0xae3(%rip), %rdi       # 0x206a
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x1060
movl 0x14(%rsp), %r15d
movl %ebp, %edi
callq 0x1030
cmpl $0x0, 0xc(%rsp)
je 0x15e7
cmpl $-0x1, %r12d
pushq $-0x1
popq %rax
cmovll %r12d, %eax
leaq 0xa8d(%rip), %rdi       # 0x2044
testl %r12d, %r12d
js 0x15d1
movl %r12d, %ecx
cmpb $0x20, 0xc0(%rsp,%rcx)
jne 0x15ce
decl %r12d
jmp 0x15b7
movl %r12d, %eax
cltq
leaq 0xc0(%rsp), %rsi
movb $0x0, 0x1(%rax,%rsi)
xorl %eax, %eax
callq 0x1060
addl $0x64, %r15d
jmp 0x1467
cmpl $0x0, 0x18(%rsp)
setne %al
andb 0x30(%rsp), %al
cmpb $0x1, %al
leaq 0x50(%rsp), %r14
jne 0x1618
movq %r14, %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq 0x20(%rsp), %rcx
callq 0x1050
movq 0x20(%rsp), %rdi
callq 0x118c
movq 0x30(%rsp), %rsi
cmpq %rsi, %rax
je 0x1444
jmp 0x16d0
cmpl $0x1, 0x38(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, %r8d
leaq 0x54(%rsp), %rcx
pushq $0x5
popq %rsi
leaq 0x9f4(%rip), %rdi       # 0x2044
je 0x13da
movl 0x8(%rsp), %esi
incl %esi
movl %esi, 0x8(%rsp)
leaq 0x9d4(%rip), %rdi       # 0x203b
movl %eax, %r15d
xorl %eax, %eax
callq 0x1060
leaq 0x9cc(%rip), %rdi       # 0x2044
pushq $0x5
popq %rsi
leaq 0x54(%rsp), %rcx
movl %r15d, %r8d
jmp 0x13da
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x9b2(%rip), %rdi       # 0x204f
xorl %eax, %eax
callq 0x1060
pushq $0x3
jmp 0x16bd
movq (%r13,%r15,8), %rsi
leaq 0x974(%rip), %rdi       # 0x2028
xorl %eax, %eax
callq 0x1060
pushq $0x2
popq %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x99f(%rip), %rdi       # 0x2076
movq %rax, %rdx
xorl %eax, %eax
callq 0x1060
pushq $0x4
jmp 0x16bd