// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x8
popq %rbp
subl $0x1, %ebp
jb 0x15b2
movq 0x3b9f(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
jmp 0x159d
movq 0x3b8f(%rip), %rsi      # 0x5148
pushq $0x1
popq %rdi
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
movq 0x3b77(%rip), %rsi      # 0x5148
xorl %edi, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
leal 0x6(%r12), %ebx
movzbl %bl, %ebp
movq 0x3b58(%rip), %rsi      # 0x5148
movl %ebp, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
movzbl %bh, %ebx
movq 0x3b42(%rip), %rsi      # 0x5148
movl %ebx, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
movl %r13d, %eax
movzbl %al, %r15d
movq 0x3b28(%rip), %rsi      # 0x5148
movl %r15d, %edi
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
movl %r13d, %eax
movzbl %ah, %edi
movq 0x3b0e(%rip), %rsi      # 0x5148
movl %edi, %r13d
callq 0x1100
cmpl $-0x1, %eax
je 0x1671
testl %r12d, %r12d
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1671
movslq %r12d, %rdx
movq 0x3ae7(%rip), %rcx      # 0x5148
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x1180
cmpl %r12d, %eax
jge 0x1680
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 0x169e
movzbl (%r14), %eax
incq %r14
subl %eax, %ebp
decl %r12d
jmp 0x168b
movzbl %bpl, %edi
movq 0x3a9f(%rip), %rsi      # 0x5148
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100