// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x1364
movq -0x10(%rbp), %rdi
callq 0x12a0
movl $0x1, -0x4(%rbp)
jmp 0x1975
movl $0x0, -0x1c(%rbp)
leaq 0x2d1e(%rip), %rax      # 0x4090
movq %rax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jg 0x14ba
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x13b7
jmp 0x14ba
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x77, %eax
jne 0x13d8
movl $0x1, -0x30(%rbp)
jmp 0x14aa
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x61, %eax
jne 0x13f9
movl $0x1, -0x1c(%rbp)
jmp 0x14a8
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x65, %eax
jne 0x141a
movl $0x0, -0x34(%rbp)
jmp 0x14a6
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x68, %eax
jne 0x143c
leaq 0x2c9a(%rip), %rax      # 0x40d0
movq %rax, -0x28(%rbp)
jmp 0x14a4
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x6f, %eax
jne 0x145e
leaq 0x2bf8(%rip), %rax      # 0x4050
movq %rax, -0x28(%rbp)
jmp 0x14a2
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xd9c(%rip), %rsi       # 0x220d
leaq -0x48(%rbp), %rdx
movb $0x0, %al
callq 0x1050
cmpl $0x0, %eax
je 0x148b
xorl %eax, %eax
subl -0x48(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x14a0
movq -0x10(%rbp), %rdi
callq 0x12a0
movl $0x1, -0x4(%rbp)
jmp 0x1975
jmp 0x14a2
jmp 0x14a4
jmp 0x14a6
jmp 0x14a8
jmp 0x14aa
jmp 0x14ac
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1392
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xcf3(%rip), %rsi       # 0x21c0
callq 0x1060
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1503
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xcd2(%rip), %rdi       # 0x21c2
movb $0x0, %al
callq 0x1040
movl $0x2, -0x4(%rbp)
jmp 0x1975
movq -0x28(%rbp), %rax
movb 0x10(%rax), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movl $0x1, -0x48(%rbp)
cmpl $0x1, -0x44(%rbp)
jle 0x152e
movl -0x48(%rbp), %esi
leaq 0xcae(%rip), %rdi       # 0x21d5
movb $0x0, %al
callq 0x1040
jmp 0x1530
cmpl $0x0, -0x44(%rbp)
jle 0x196e
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
cmpl $0x64, -0x4c(%rbp)
jge 0x1569
jmp 0x1552
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x4c(%rbp)
cltq
movb $0x2e, -0xc0(%rbp,%rax)
jmp 0x154a
movb $0x0, -0x5c(%rbp)
movl $0x5, -0x4c(%rbp)
cmpl $0x64, -0x4c(%rbp)
jg 0x15d2
movl $0x1, -0x40(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x15c5
movl -0x38(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x30, %edx
movb %dl, %cl
movl -0x4c(%rbp), %eax
subl -0x40(%rbp), %eax
cltq
movb %cl, -0xc0(%rbp,%rax)
movl -0x38(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1587
jmp 0x15c7
movl -0x4c(%rbp), %eax
addl $0x5, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1574
leaq -0xc0(%rbp), %rsi
leaq 0xbfe(%rip), %rdi       # 0x21de
movb $0x0, %al
callq 0x1040
movl $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1170
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
je 0x194c
movl $0x1, -0x40(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0xc8(%rbp), %rax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x18d3
movl $0x0, -0x4c(%rbp)
cmpl $0x65, -0x4c(%rbp)
jge 0x165e
jmp 0x163b
movslq -0x4c(%rbp), %rax
movb $0x5e, -0xc0(%rbp,%rax)
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x4c(%rbp)
cltq
movb $0x20, -0x140(%rbp,%rax)
jmp 0x1633
movl $0x0, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x38(%rbp)
movb %al, -0x141(%rbp)
jle 0x1680
cmpl $0x64, -0x4c(%rbp)
setl %al
movb %al, -0x141(%rbp)
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x168f
jmp 0x1748
movslq -0x4c(%rbp), %rax
leaq -0xc0(%rbp), %rdi
addq %rax, %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1030
cmpq $0x0, %rax
ja 0x16da
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xb22(%rip), %rdi       # 0x21e9
movb $0x0, %al
callq 0x1040
movl $0x3, -0x4(%rbp)
jmp 0x1975
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl -0xc0(%rbp,%rcx), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movslq -0x4c(%rbp), %rax
movb %cl, -0xc0(%rbp,%rax)
cmpl $0x0, -0x30(%rbp)
je 0x1738
movslq -0x4c(%rbp), %rax
movsbl -0xc0(%rbp,%rax), %eax
movq -0x28(%rbp), %rcx
movsbl 0x1d(%rcx), %ecx
cmpl %ecx, %eax
jne 0x1736
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x4c(%rbp)
cltq
movb $0x31, -0x140(%rbp,%rax)
jmp 0x1738
jmp 0x173a
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1665
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x4c(%rbp)
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x142(%rbp)
jl 0x179c
movslq -0x3c(%rbp), %rax
movsbl -0xc0(%rbp,%rax), %ecx
movq -0x28(%rbp), %rax
movsbl 0x10(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x142(%rbp)
jne 0x179c
movslq -0x3c(%rbp), %rax
movsbl -0x140(%rbp,%rax), %eax
cmpl $0x20, %eax
sete %al
movb %al, -0x142(%rbp)
movb -0x142(%rbp), %al
testb $0x1, %al
jne 0x17a8
jmp 0x17b5
jmp 0x17aa
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1756
cmpl $0x0, -0x3c(%rbp)
jge 0x17d1
cmpl $0x1, -0x40(%rbp)
je 0x17d1
cmpl $0x0, -0x1c(%rbp)
jne 0x17d1
cmpl $0x0, -0x38(%rbp)
jne 0x18c5
movl -0x40(%rbp), %esi
leaq 0xa20(%rip), %rdi       # 0x21fb
movb $0x0, %al
callq 0x1040
movl -0x4c(%rbp), %eax
addl $0x1, %eax
cltq
movb $0x0, -0xc0(%rbp,%rax)
leaq -0xc0(%rbp), %rsi
leaq 0xa01(%rip), %rdi       # 0x2201
movb $0x0, %al
callq 0x1040
cmpl $0x1, -0x40(%rbp)
jne 0x1846
movl -0x4c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
cmpl $0x64, %eax
jge 0x1835
jmp 0x1825
leaq 0x9d3(%rip), %rdi       # 0x21ff
movb $0x0, %al
callq 0x1040
jmp 0x1813
movl -0x50(%rbp), %esi
leaq 0x9c5(%rip), %rdi       # 0x2204
movb $0x0, %al
callq 0x1040
leaq 0x842(%rip), %rdi       # 0x208f
movb $0x0, %al
callq 0x1040
cmpl $0x0, -0x30(%rbp)
je 0x18c3
jmp 0x185c
xorl %eax, %eax
cmpl $0x0, -0x4c(%rbp)
movb %al, -0x143(%rbp)
jl 0x1882
movslq -0x4c(%rbp), %rax
movsbl -0x140(%rbp,%rax), %eax
cmpl $0x20, %eax
sete %al
movb %al, -0x143(%rbp)
movb -0x143(%rbp), %al
testb $0x1, %al
jne 0x188e
jmp 0x189b
jmp 0x1890
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x185c
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
cltq
movb $0x0, -0x140(%rbp,%rax)
leaq -0x140(%rbp), %rsi
leaq 0x922(%rip), %rdi       # 0x21de
movb $0x0, %al
callq 0x1040
jmp 0x18c5
movl -0x40(%rbp), %eax
addl $0x64, %eax
movl %eax, -0x40(%rbp)
jmp 0x1622
movq -0xc8(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x1902
cmpl $0x0, -0x34(%rbp)
je 0x1902
leaq -0xc0(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1170
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x1947
movq -0xc8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
leaq 0x8d9(%rip), %rdi       # 0x2210
movb $0x0, %al
callq 0x1040
movl $0x4, -0x4(%rbp)
jmp 0x1975
jmp 0x15ee
cmpl $0x0, -0x44(%rbp)
jle 0x1969
movl -0x48(%rbp), %esi
addl $0x1, %esi
movl %esi, -0x48(%rbp)
leaq 0x873(%rip), %rdi       # 0x21d5
movb $0x0, %al
callq 0x1040
jmp 0x1530
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq