// File: /workspace/github_c_makefile_star2_O0/AK6DN[P]dec-utilities-for-pdp/d8tape/main.c
// Function: dumptape
static int
dumptape (unsigned char *t, int n)
{
    int     i;

    // basic preprocessing; find header
    for (i = 0; i < n; i++) {
        if (t [i] == 0x80) {        // got a header
            break;
        }
    }
    if (i == n) {
        fprintf (stderr, "%s:  couldn't find a 0x80 leader on tape %s; tape ignored\n", progname, tapename);
        return (0);
    }

    // skip header
    for (; i < n; i++) {
        if (t [i] < 0x80) {         // RK 20071104 was "!= 0x80"; 
            break;
        }
    }
    if (i == n) {
        fprintf (stderr, "%s:  no data content found after 0x80 leader on tape %s; tape ignored\n", progname, tapename);
        return (0);
    }

    // at this point, we're positioned on the first-non-leader byte of the tape
    if (n - i < 4) {
        fprintf (stderr, "%s:  tape %s is too short; tape ignored\n", progname, tapename);
        return (0);
    }

    // skip leader (t now points to start of tape; n indicates remaining # bytes)
    if (optv) {
        fprintf (stderr, "%s:  tape %s skipped %d (0x%0X, 0%0o) bytes of header, original size %d new size %d\n", progname, tapename, i, i, i, n, n - i);
    }
    t += i;
    n -= i;

    // find first 0x80 -- trailer
    for (i = 0; i < n; i++) {
        if (t [i] == 0x80) {
            break;
        }
    }
    if (i == n) {
        fprintf (stderr, "%s:  warning -- tape %s does not have a trailer\n", progname, tapename);
        // find first data >= 0x80, then
        for (i = 0; i < n; i++) {
            if (t [i] >= 0x80) {
                // at least stop on the first invalid character, then
                break;
            }
        }
    }

    // reset end-of-tape to last character
    if (optv > 2) {
        printf ("%s:  tape %s skipped %d bytes of trailer, new size is %d bytes\n", progname, tapename, n - i, i);
    }
    n = i;

    // determine type of tape and dump it
    if (checkrim (t, n)) {
        if (!dumprim (t, n)) {
            return (0);
        }
    } else if (checkbin (t, n)) {
        if (!dumpbin (t, n)) {
            return (0);
        }
    } else {
        fprintf (stderr, "%s:  tape %s is neither RIM nor BIN (first four bytes are 0%03o 0%03o 0%03o 0%03o)\n", progname, tapename, t [0], t [1], t [2], t [3]);
        return (0);
    }

    if (!optd) {
        flow ();                // perform flow analysis
        disassemble ();         // disassemble
        printf ("\n$\n");
    }
    return (1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3790
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jne 0x3783
jmp 0x3790
jmp 0x3785
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3766
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x37ca
movq 0xa859(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa957(%rip), %rdx      # 0xe100
movq 0xf7c0(%rip), %rcx      # 0x12f70
leaq 0x4cd2(%rip), %rsi      # 0x8489
movb $0x0, %al
callq 0x30f0
movl $0x0, -0x4(%rbp)
jmp 0x3a88
jmp 0x37cc
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x37f6
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jge 0x37e9
jmp 0x37f6
jmp 0x37eb
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x37cc
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x3830
movq 0xa7f3(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa8f1(%rip), %rdx      # 0xe100
movq 0xf75a(%rip), %rcx      # 0x12f70
leaq 0x4ca7(%rip), %rsi      # 0x84c4
movb $0x0, %al
callq 0x30f0
movl $0x0, -0x4(%rbp)
jmp 0x3a88
movl -0x14(%rbp), %eax
subl -0x18(%rbp), %eax
cmpl $0x4, %eax
jge 0x386d
movq 0xa7b6(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa8b4(%rip), %rdx      # 0xe100
movq 0xf71d(%rip), %rcx      # 0x12f70
leaq 0x4cb1(%rip), %rsi      # 0x850b
movb $0x0, %al
callq 0x30f0
movl $0x0, -0x4(%rbp)
jmp 0x3a88
cmpl $0x0, 0xb6dc(%rip)      # 0xef50
je 0x38bf
movq 0xa77b(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa879(%rip), %rdx      # 0xe100
movq 0xf6e2(%rip), %rcx      # 0x12f70
movl -0x18(%rbp), %r8d
movl -0x18(%rbp), %r9d
movl -0x18(%rbp), %r11d
movl -0x14(%rbp), %r10d
movl -0x14(%rbp), %eax
subl -0x18(%rbp), %eax
leaq 0x4c89(%rip), %rsi      # 0x8534
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x30f0
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x18(%rbp), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x390c
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jne 0x38ff
jmp 0x390c
jmp 0x3901
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x38e2
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x396d
movq 0xa6dd(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa7db(%rip), %rdx      # 0xe100
movq 0xf644(%rip), %rcx      # 0x12f70
leaq 0x4c56(%rip), %rsi      # 0x8589
movb $0x0, %al
callq 0x30f0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x396b
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jl 0x395e
jmp 0x396b
jmp 0x3960
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3941
jmp 0x396d
cmpl $0x2, 0xb5dc(%rip)      # 0xef50
jle 0x399c
movq 0xa783(%rip), %rsi      # 0xe100
movq 0xf5ec(%rip), %rdx      # 0x12f70
movl -0x14(%rbp), %ecx
subl -0x18(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq 0x4c25(%rip), %rdi      # 0x85ba
movb $0x0, %al
callq 0x30a0
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x41d0
cmpl $0x0, %eax
je 0x39d5
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x4340
cmpl $0x0, %eax
jne 0x39d0
movl $0x0, -0x4(%rbp)
jmp 0x3a88
jmp 0x3a60
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x4510
cmpl $0x0, %eax
je 0x3a05
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x45e0
cmpl $0x0, %eax
jne 0x3a03
movl $0x0, -0x4(%rbp)
jmp 0x3a88
jmp 0x3a5e
movq 0xa5ec(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xa6ea(%rip), %rdx      # 0xe100
movq 0xf553(%rip), %rcx      # 0x12f70
movq -0x10(%rbp), %rax
movzbl (%rax), %r8d
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %r9d
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %r10d
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
leaq 0x4bb4(%rip), %rsi      # 0x85fa
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x30f0
movl $0x0, -0x4(%rbp)
jmp 0x3a88
jmp 0x3a60
cmpl $0x0, 0xb4dd(%rip)      # 0xef44
jne 0x3a81
callq 0x63f0
callq 0x60a0
leaq 0x4bd4(%rip), %rdi      # 0x864e
movb $0x0, %al
callq 0x30a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)