// File: /workspace/github_c_makefile_star2_O1/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 0x3a91(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
decl %ebp
jne 0x16b0
movq 0x3a7f(%rip), %rsi      # 0x5148
movl $0x1, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
movq 0x3a65(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
leal 0x6(%r12), %ebx
movzbl %bl, %ebp
movq 0x3a46(%rip), %rsi      # 0x5148
movl %ebp, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
movzbl %bh, %ebx
movq 0x3a30(%rip), %rsi      # 0x5148
movl %ebx, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
movl %r13d, %eax
movzbl %al, %r15d
movq 0x3a16(%rip), %rsi      # 0x5148
movl %r15d, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
movl %r13d, %eax
movzbl %ah, %edi
movq 0x39fc(%rip), %rsi      # 0x5148
movl %edi, %r13d
callq 0x1100
cmpl $-0x1, %eax
je 0x1785
testl %r12d, %r12d
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1785
movslq %r12d, %rdx
movq 0x39d5(%rip), %rcx      # 0x5148
movl $0x1, %esi
movq %r14, %rdi
callq 0x1180
cmpl %r12d, %eax
jge 0x1794
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 0x17b9
incl %r12d
movzbl (%r14), %eax
incq %r14
subl %eax, %ebp
decl %r12d
cmpl $0x1, %r12d
jg 0x17a7
movzbl %bpl, %edi
movq 0x3984(%rip), %rsi      # 0x5148
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100