// File: /workspace/github_c_makefile_star2_O3/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
callq 0xde01
testq %rax, %rax
je 0x7d89
movq %rax, %r12
movl $0x1, %ebx
leaq 0x10(%rsp), %r13
testl %ebp, %ebp
jne 0x7c95
leaq 0xde0e(%rip), %rax      # 0x15a80
movl (%rax), %eax
leaq 0xddf9(%rip), %rcx      # 0x15a74
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
testl %eax, %eax
jle 0x7c95
callq 0x77bb
movq (%r14), %rdi
movq %r12, %rsi
callq 0x76c4
movq %r12, %rdi
movq %r13, %rsi
callq 0x8a17
testq %rax, %rax
je 0x7cd2
movq 0x18(%rax), %rcx
cmpl $0x4, 0x8(%rcx)
jne 0x7cd2
movl 0x8(%rax), %eax
cmpq $0x32, %rax
ja 0x7cf6
movabsq $0x4100006000000, %rcx  # imm = 0x4100006000000
btq %rax, %rcx
jae 0x7cf6
incl %ebx
testl %ebx, %ebx
je 0x7d9f
movq %r15, %rdi
movq %r12, %rsi
callq 0xdb56
movq %r14, %rdi
callq 0xde01
movq %rax, %r12
testq %rax, %rax
jne 0x7c67
jmp 0x7d89
leal -0xb(%rax), %ecx
cmpl $0x1, %ecx
ja 0x7cca
decl %ebx
cmpq $0x0, 0x8(%rsp)
je 0x7cca
testl %ebx, %ebx
jne 0x7cca
cmpl $0xb, %eax
jne 0x7d9f
movq 0x10(%rsp), %rdi
callq 0x8744
movq %rax, 0x10(%rsp)
movzbl (%rax), %ecx
cmpq $0x3b, %rcx
ja 0x7d3d
movabsq $0x800000000000401, %rdx # imm = 0x800000000000401
btq %rcx, %rdx
jb 0x7d9f
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x8af9
testq %rax, %rax
je 0x7d9f
movq %rax, %r15
movq %rax, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x21d0
testl %eax, %eax
je 0x7d7f
movq (%r14), %rdi
leaq 0x8777(%rip), %rsi      # 0x104e9
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x7a34
movq %r15, %rdi
callq 0x2050
jmp 0x7d9f
movq (%r14), %rdi
leaq 0x8737(%rip), %rsi      # 0x104ca
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x7a34
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq