// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/macros.c
// Function: read_body
void read_body(
    STACK *stack,
    BUFFER *gb,
    char *name,
    int called)
{
    int             nest;

    /* Read the stream in until the end marker is hit */

    /* Note: "called" says that this body is being pulled from a macro
       library, and so under no circumstance should it be listed. */

    nest = 1;
    for (;;) {
        SYMBOL         *op;
        char           *nextline;
        char           *cp;

        nextline = stack_gets(stack);  /* Now read the line */
        if (nextline == NULL) {        /* End of file. */
            report(stack->top, "Macro body of '%s' not closed\n", name);
            break;
        }

        if (!called && (list_level - 1 + list_md) > 0) {
            list_flush();
            list_source(stack->top, nextline);
        }

        op = get_op(nextline, &cp);

        if (op == NULL) {              /* Not a pseudo-op */
            buffer_append_line(gb, nextline);
            continue;
        }
        if (op->section->type == SECTION_PSEUDO) {
            if (op->value == P_MACRO || op->value == P_REPT || op->value == P_IRP || op->value == P_IRPC) {
                nest++;
            }

            if (op->value == P_ENDM || op->value == P_ENDR) {
                nest--;
                /* If there's a name on the .ENDM, then
                 * check if the name matches the one on .MACRO.
                 * See page 7-3.
                 * Since we don't keep a stack of nested
                 * .MACRO names, just check for the outer one.
                 */
                if (nest == 0 && name && op->value == P_ENDM) {
                    cp = skipwhite(cp);
                    if (!EOL(*cp)) {
                        char           *label = get_symbol(cp, &cp, NULL);

                        if (label) {
                            if (strcmp(label, name) != 0) {
                                report(stack->top, ".ENDM '%s' does not match .MACRO '%s'\n", label, name);
                            }
                            free(label);
                        }
                    }
                }
            }

            if (nest == 0)
                return;                /* All done. */
        }

        buffer_append_line(gb, nextline);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl $0x1, %ebp
movq %r12, %rdi
callq 0xe0b6
testq %rax, %rax
je 0x7e42
movq %rax, %r13
testl %ebx, %ebx
jne 0x7db6
leaq 0xdcee(%rip), %rax      # 0x15a80
movl (%rax), %eax
leaq 0xdcd9(%rip), %rcx      # 0x15a74
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
testl %eax, %eax
jle 0x7db6
callq 0x78e1
movq (%r12), %rdi
movq %r13, %rsi
callq 0x77e8
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x8b34
testq %rax, %rax
je 0x7e33
movq 0x18(%rax), %rcx
cmpl $0x4, 0x8(%rcx)
jne 0x7e33
movl 0x8(%rax), %eax
cmpq $0x32, %rax
ja 0x7ded
movabsq $0x4100006000000, %rcx  # imm = 0x4100006000000
btq %rax, %rcx
jae 0x7ded
incl %ebp
leal -0xb(%rax), %ecx
cmpl $0x1, %ecx
ja 0x7e2f
decl %ebp
testq %r14, %r14
je 0x7e2f
testl %ebp, %ebp
jne 0x7e2f
xorl %ebp, %ebp
cmpl $0xb, %eax
jne 0x7e2f
movq 0x8(%rsp), %rdi
callq 0x88a0
movq %rax, 0x8(%rsp)
movzbl (%rax), %ecx
cmpq $0x3b, %rcx
ja 0x7e67
movabsq $0x800000000000401, %rdx # imm = 0x800000000000401
btq %rcx, %rdx
jae 0x7e67
testl %ebp, %ebp
je 0x7e63
movq %r15, %rdi
movq %r13, %rsi
callq 0xde0b
xorl %eax, %eax
jmp 0x7e59
movq (%r12), %rdi
leaq 0x868d(%rip), %rsi      # 0x104da
movq %r14, %rdx
xorl %eax, %eax
callq 0x7b5a
movb $0x1, %al
testb %al, %al
je 0x7d73
jmp 0x7eba
xorl %ebp, %ebp
jmp 0x7e57
xorl %ebp, %ebp
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x8c1a
testq %rax, %rax
je 0x7e2f
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0x21d0
testl %eax, %eax
je 0x7eab
movq (%r12), %rdi
leaq 0x865d(%rip), %rsi      # 0x104f9
movq 0x10(%rsp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x7b5a
movq 0x10(%rsp), %rdi
callq 0x2050
jmp 0x7e2f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq