// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/crossassemblers/macro11/dumpobj.c
// Function: dump_bin
void dump_bin(
    unsigned addr,
    char *buf,
    int len)
{
    int             chksum;     /* Checksum is negative sum of all
                                   bytes including header and length */
    int             FBR_LEAD1 = 1,
            FBR_LEAD2 = 0;
    int             i;
    unsigned        hdrlen = len + 6;

    for (i = 0; i < 8; i++)
        fputc(0, bin);
    chksum = 0;
    if (fputc(FBR_LEAD1, bin) == EOF)
        return;                        /* All recs begin with 1,0 */
    chksum -= FBR_LEAD1;
    if (fputc(FBR_LEAD2, bin) == EOF)
        return;
    chksum -= FBR_LEAD2;

    i = hdrlen & 0xff;                 /* length, lsb */
    chksum -= i;
    if (fputc(i, bin) == EOF)
        return;

    i = (hdrlen >> 8) & 0xff;          /* length, msb */
    chksum -= i;
    if (fputc(i, bin) == EOF)
        return;

    i = addr & 0xff;                   /* origin, msb */
    chksum -= i;
    if (fputc(i, bin) == EOF)
        return;

    i = (addr >> 8) & 0xff;            /* origin, lsb */
    chksum -= i;
    if (fputc(i, bin) == EOF)
        return;

    if ((len == 0) || (buf == NULL))
        return;                        /* end of tape block */

    i = fwrite(buf, 1, len, bin);
    if (i < len)
        return;

    while (len > 0) {                  /* All the data bytes */
        chksum -= *buf++ & 0xff;
        len--;
    }

    chksum &= 0xff;

    fputc(chksum, bin);                /* Followed by the checksum byte */

    return;                            /* Worked okay. */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movq %rsi, %r14
movl %edi, %r13d
movl $0x8, %ebp
movq 0x3a99(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
decl %ebp
jne 0x16a8
movq 0x3a87(%rip), %rsi      # 0x5148
movl $0x1, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
movq 0x3a6d(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
leal 0x6(%r12), %ebx
movzbl %bl, %ebp
movq 0x3a4e(%rip), %rsi      # 0x5148
movl %ebp, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
movzbl %bh, %ebx
movq 0x3a38(%rip), %rsi      # 0x5148
movl %ebx, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
movl %r13d, %eax
movzbl %al, %r15d
movq 0x3a1e(%rip), %rsi      # 0x5148
movl %r15d, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
movl %r13d, %eax
movzbl %ah, %edi
movq 0x3a04(%rip), %rsi      # 0x5148
movl %edi, %r13d
callq 0x1100
cmpl $-0x1, %eax
je 0x177d
testl %r12d, %r12d
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x177d
movslq %r12d, %rdx
movq 0x39dd(%rip), %rcx      # 0x5148
movl $0x1, %esi
movq %r14, %rdi
callq 0x1180
cmpl %r12d, %eax
jge 0x178c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
notl %ebp
addl %r15d, %r13d
addl %ebx, %r13d
subl %r13d, %ebp
testl %r12d, %r12d
jle 0x17b1
incl %r12d
movzbl (%r14), %eax
incq %r14
subl %eax, %ebp
decl %r12d
cmpl $0x1, %r12d
ja 0x179f
movzbl %bpl, %edi
movq 0x398c(%rip), %rsi      # 0x5148
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100