// File: /workspace/github_c_makefile_star2_O1/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, %rbx
cmpl $0x2, %edi
jge 0x12ce
movq %rbx, %rdi
callq 0x123c
movl $0x1, %eax
jmp 0x17cb
movl %edi, %r14d
incl %r14d
leaq 0x2dc5(%rip), %rbp      # 0x40a0
movl $0x1, %ecx
movl $0x1, %r13d
leaq 0x2df3(%rip), %r15      # 0x40e0
leaq 0x2d6c(%rip), %r12      # 0x4060
movl $0x0, 0x1c(%rsp)
movl $0x1, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
movq (%rbx,%r13,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x138d
movzbl 0x1(%rdi), %eax
cmpl $0x67, %eax
jle 0x1337
cmpl $0x68, %eax
je 0x134b
cmpl $0x6f, %eax
je 0x1350
cmpl $0x77, %eax
jne 0x135f
movl $0x1, 0xc(%rsp)
jmp 0x1380
cmpl $0x61, %eax
je 0x1355
cmpl $0x65, %eax
jne 0x135f
movl $0x0, 0x18(%rsp)
jmp 0x1380
movq %r15, %rbp
jmp 0x1380
movq %r12, %rbp
jmp 0x1380
movl $0x1, 0x1c(%rsp)
jmp 0x1380
leaq 0xd49(%rip), %rsi       # 0x20af
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
je 0x12bc
xorl %ecx, %ecx
subl 0x8(%rsp), %ecx
incq %r13
cmpq %r13, %r14
jne 0x130c
movl %ecx, %r15d
jmp 0x1393
movl %ecx, %r15d
movl %r13d, %r14d
movl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
leaq 0xcc1(%rip), %rsi       # 0x2062
callq 0x1080
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x17b0
movb 0x10(%rbp), %al
movb %al, (%rbp)
movl $0x1, 0x8(%rsp)
movl %r15d, %ecx
cmpl $0x2, %r15d
jl 0x13e1
leaq 0xca5(%rip), %rdi       # 0x2077
movl $0x1, %esi
xorl %eax, %eax
callq 0x1060
movl %r15d, %ecx
testl %ecx, %ecx
jle 0x17c9
leaq 0x54(%rsp), %rdx
movaps 0xc1b(%rip), %xmm0      # 0x2010
movl $0xcccccccd, %r15d      # imm = 0xCCCCCCCD
leaq 0xc7e(%rip), %rdi       # 0x2080
movq %rbx, 0x48(%rsp)
movq %r14, 0x40(%rsp)
movl %ecx, %r11d
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 %rdx, %rax
movq %rax, %rdx
movl %ecx, %esi
movl %esi, %r10d
imulq %r15, %r10
shrq $0x23, %r10
leal (%r10,%r10), %r8d
leal (%r8,%r8,4), %r8d
movl %esi, %r9d
subl %r8d, %r9d
orb $0x30, %r9b
movb %r9b, (%rdx)
decq %rdx
cmpl $0x9, %esi
movl %r10d, %esi
ja 0x1456
leaq 0x5(%rcx), %rdx
addq $0x5, %rax
cmpq $0x60, %rcx
movq %rdx, %rcx
jb 0x1451
movq %r11, 0x30(%rsp)
leal -0x1(%r11), %eax
movl %eax, 0x2c(%rsp)
xorl %r12d, %r12d
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
movq 0x20(%rsp), %rdi
callq 0x118c
testq %rax, %rax
je 0x1742
incl %r12d
movl %r12d, 0x10(%rsp)
movl $0x1, %r13d
movq %rax, 0x38(%rsp)
movl %eax, %r12d
movl %r13d, 0x14(%rsp)
movabsq $0x5e5e5e5e5e5e5e5e, %rax # imm = 0x5E5E5E5E5E5E5E5E
movq %rax, 0xad(%rsp)
movaps 0xb2b(%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 0xb0d(%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 0x15de
xorl %r13d, %r13d
movl %r12d, %ebx
movslq %r13d, %r14
leaq (%rsp,%r14), %r12
addq $0x50, %r12
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movq 0x20(%rsp), %rcx
callq 0x1050
testq %rax, %rax
je 0x178d
movsbq (%r12), %rax
movl %eax, %eax
movb (%rbp,%rax), %al
movb %al, (%r12)
cmpl $0x0, 0xc(%rsp)
je 0x15c3
cmpb 0x1d(%rbp), %al
jne 0x15c3
leal -0x1(%r14), %r13d
movb $0x31, 0xc0(%rsp,%r14)
leal 0x1(%r13), %r14d
leal -0x1(%rbx), %r12d
cmpl $0x2, %ebx
jl 0x15e1
movl %r12d, %ebx
cmpl $0x63, %r13d
movl %r14d, %r13d
jl 0x1570
jmp 0x15e1
xorl %r14d, %r14d
testl %r14d, %r14d
setns %al
js 0x1618
movb 0x10(%rbp), %cl
movl %r14d, %edx
cmpb %cl, 0x50(%rsp,%rdx)
movl 0x14(%rsp), %r13d
jne 0x161d
cmpb $0x20, 0xc0(%rsp,%rdx)
jne 0x161d
testl %edx, %edx
setg %al
jle 0x161d
decq %rdx
movl %edx, %esi
cmpb %cl, 0x50(%rsp,%rsi)
je 0x15fa
jmp 0x161d
movl 0x14(%rsp), %r13d
testl %r12d, %r12d
je 0x1637
testb $0x1, %al
jne 0x1637
cmpl $0x1, %r13d
je 0x1637
cmpl $0x0, 0x1c(%rsp)
je 0x16ea
leaq 0xa5f(%rip), %rdi       # 0x209d
movl %r13d, %esi
xorl %eax, %eax
callq 0x1060
movslq %r14d, %rax
movb $0x0, 0x50(%rsp,%rax)
leaq 0xa4c(%rip), %rdi       # 0x20a3
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
cmpl $0x1, %r13d
jne 0x1696
cmpl $0x64, %r14d
jg 0x1684
leal -0x2(%r14), %ebx
movl $0x20, %edi
callq 0x1030
incl %ebx
cmpl $0x63, %ebx
jl 0x1673
leaq 0xa1b(%rip), %rdi       # 0x20a6
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x1060
movl $0xa, %edi
callq 0x1030
cmpl $0x0, 0xc(%rsp)
je 0x16ea
leaq 0x9d2(%rip), %rdi       # 0x2080
testl %r14d, %r14d
jle 0x16d0
leal -0x1(%r14), %eax
cmpb $0x20, 0xc0(%rsp,%rax)
jne 0x16cb
decl %r14d
jg 0x16b3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
incl %eax
movl %eax, %r14d
movslq %r14d, %rax
movb $0x0, 0xc0(%rsp,%rax)
leaq 0xc0(%rsp), %rsi
xorl %eax, %eax
callq 0x1060
addl $0x64, %r13d
testl %r12d, %r12d
jne 0x14d7
cmpl $0x0, 0x18(%rsp)
setne %al
andb 0x38(%rsp), %al
cmpb $0x1, %al
jne 0x1720
movl $0x1, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rcx
callq 0x1050
movq 0x20(%rsp), %rdi
callq 0x118c
movq 0x38(%rsp), %rsi
cmpq %rsi, %rax
movl 0x10(%rsp), %r12d
je 0x14ae
jmp 0x17dd
movq 0x30(%rsp), %rcx
cmpl $0x1, %ecx
je 0x1769
movl 0x8(%rsp), %esi
incl %esi
movl %esi, 0x8(%rsp)
leaq 0x91a(%rip), %rdi       # 0x2077
xorl %eax, %eax
callq 0x1060
movq 0x30(%rsp), %rcx
xorl %eax, %eax
cmpl $0x1, %ecx
movl 0x2c(%rsp), %ecx
leaq 0x54(%rsp), %rdx
movaps 0x892(%rip), %xmm0      # 0x2010
leaq 0x8fb(%rip), %rdi       # 0x2080
jg 0x140c
jmp 0x17cb
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x8e9(%rip), %rdi       # 0x208b
xorl %eax, %eax
callq 0x1060
movl $0x3, %eax
jmp 0x17cb
movq (%rbx,%r14,8), %rsi
leaq 0x8a9(%rip), %rdi       # 0x2064
xorl %eax, %eax
callq 0x1060
movl $0x2, %eax
jmp 0x17cb
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8ce(%rip), %rdi       # 0x20b2
movq %rax, %rdx
xorl %eax, %eax
callq 0x1060
movl $0x4, %eax
jmp 0x17cb