// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jge 0x17df
movq 0x396b(%rip), %rsi      # 0x5138
xorl %edi, %edi
callq 0x10f0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x17c0
movl $0x0, -0x18(%rbp)
movl -0x1c(%rbp), %edi
movq 0x3948(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x17ff
jmp 0x1972
movl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %edi
movq 0x3924(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x1823
jmp 0x1972
movl -0x20(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x28(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %edi
movq 0x38ea(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x185d
jmp 0x1972
movl -0x28(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %edi
movq 0x38b8(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x188f
jmp 0x1972
movl -0x4(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %edi
movq 0x3889(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x18be
jmp 0x1972
movl -0x4(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %edi
movq 0x3857(%rip), %rsi      # 0x5138
callq 0x10f0
cmpl $-0x1, %eax
jne 0x18f0
jmp 0x1972
cmpl $0x0, -0x14(%rbp)
je 0x18fd
cmpq $0x0, -0x10(%rbp)
jne 0x18ff
jmp 0x1972
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rdx
movq 0x382a(%rip), %rcx      # 0x5138
movl $0x1, %esi
callq 0x1170
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1925
jmp 0x1972
jmp 0x1927
cmpl $0x0, -0x14(%rbp)
jle 0x1958
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %ecx
andl $0xff, %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1927
movl -0x18(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
movq 0x37cb(%rip), %rsi      # 0x5138
callq 0x10f0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)