// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r14
pushq $0x1
popq %rbx
leaq 0x10(%rsp), %r12
movq %r14, %rdi
callq 0xcb1a
testq %rax, %rax
je 0x79a8
movq %rax, %r13
testl %ebp, %ebp
jne 0x78c8
leaq 0xe1db(%rip), %rax      # 0x15a80
movl (%rax), %eax
leaq 0xe1c6(%rip), %rcx      # 0x15a74
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
testl %eax, %eax
jle 0x78c8
callq 0x7469
movq (%r14), %rdi
movq %r13, %rsi
callq 0x7370
movq %r13, %rdi
movq %r12, %rsi
callq 0x84ca
testq %rax, %rax
je 0x7905
movq 0x18(%rax), %rcx
cmpl $0x4, 0x8(%rcx)
jne 0x7905
movl 0x8(%rax), %eax
cmpq $0x32, %rax
ja 0x7915
movabsq $0x4100006000000, %rcx  # imm = 0x4100006000000
btq %rax, %rcx
jae 0x7915
incl %ebx
testl %ebx, %ebx
je 0x79be
movq %r15, %rdi
movq %r13, %rsi
callq 0xc898
jmp 0x7886
leal -0xb(%rax), %ecx
cmpl $0x1, %ecx
ja 0x78fd
decl %ebx
cmpq $0x0, 0x8(%rsp)
je 0x78fd
testl %ebx, %ebx
jne 0x78fd
cmpl $0xb, %eax
jne 0x79be
movq 0x10(%rsp), %rdi
callq 0x8234
movq %rax, 0x10(%rsp)
movzbl (%rax), %ecx
cmpq $0x3b, %rcx
ja 0x795c
movabsq $0x800000000000401, %rdx # imm = 0x800000000000401
btq %rcx, %rdx
jb 0x79be
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x8597
testq %rax, %rax
je 0x79be
movq %rax, %r15
movq %rax, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x21d0
testl %eax, %eax
je 0x799e
movq (%r14), %rdi
leaq 0x7b6d(%rip), %rsi      # 0xf4fe
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x7668
movq %r15, %rdi
callq 0x2050
jmp 0x79be
movq (%r14), %rdi
leaq 0x7b2d(%rip), %rsi      # 0xf4df
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x7668
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq