// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/macros.c
// Function: subst_args
BUFFER         *subst_args(
    BUFFER *text,
    ARG *args)
{
    char           *in;
    char           *begin;
    BUFFER         *gb;
    char           *label;
    ARG            *arg;

    gb = new_buffer();

    /* Blindly look for argument symbols in the input. */
    /* Don't worry about quotes or comments. */

    for (begin = in = text->buffer; in < text->buffer + text->length;) {
        char           *next;

        if (issym((unsigned char)*in)) {
            label = get_symbol(in, &next, NULL);
            if (label) {
                if ((arg = find_arg(args, label))) {
                    /* An apostrophe may appear before or after the symbol. */
                    /* In either case, remove it from the expansion. */

                    if (in > begin && in[-1] == '\'')
                        in--;          /* Don't copy it. */
                    if (*next == '\'')
                        next++;

                    /* Copy prior characters */
                    buffer_appendn(gb, begin, (int) (in - begin));
                    /* Copy replacement string */
                    buffer_append_line(gb, arg->value);
                    in = begin = next;
                    --in;              /* prepare for subsequent increment */
                }
                free(label);
                in = next;
            } else
                in++;
        } else
            in++;
    }

    /* Append the rest of the text */
    buffer_appendn(gb, begin, (int) (in - begin));

    return gb;                         /* Done. */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r13
movq %rdi, %r15
callq 0xdd0c
movq %rax, 0x18(%rsp)
movq (%r15), %r12
cmpl $0x0, 0xc(%r15)
jle 0x8347
callq 0x2300
movq %rax, %rbp
movq %r12, 0x8(%rsp)
movq %rax, 0x20(%rsp)
movq (%rbp), %rcx
movzbl (%r12), %eax
movzwl (%rcx,%rax,2), %ecx
testl $0xc00, %ecx            # imm = 0xC00
je 0x830b
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x8c1a
testq %rax, %rax
je 0x8332
movq %rax, %rbx
testq %r13, %r13
je 0x8293
movq %r13, %r14
movq 0x10(%r14), %rdi
movq %rbx, %rsi
callq 0x21d0
testl %eax, %eax
je 0x8296
movq (%r14), %r14
testq %r14, %r14
jne 0x827b
xorl %r14d, %r14d
testq %r14, %r14
je 0x82fc
cmpq 0x8(%rsp), %r12
jbe 0x82b1
leaq -0x1(%r12), %rax
cmpb $0x27, -0x1(%r12)
cmoveq %rax, %r12
movq %r13, %rbp
movq 0x10(%rsp), %rax
cmpb $0x27, (%rax)
jne 0x82c6
incq %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rsi
subl %esi, %r12d
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r12d, %edx
callq 0xdd99
movq 0x18(%r14), %rsi
movq %r13, %rdi
callq 0xde0b
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %r13
movq 0x20(%rsp), %rbp
movq %rbx, %rdi
callq 0x2050
movq 0x10(%rsp), %r12
jmp 0x8335
cmpl $0x24, %eax
je 0x8258
cmpl $0x2e, %eax
je 0x8258
cmpl $0x5f, %eax
jne 0x8332
leaq 0xf357(%rip), %rax      # 0x17680
cmpl $0x0, (%rax)
jne 0x8258
incq %r12
movslq 0xc(%r15), %rax
addq (%r15), %rax
cmpq %rax, %r12
jb 0x823f
jmp 0x834c
movq %r12, 0x8(%rsp)
movq 0x8(%rsp), %rsi
subl %esi, %r12d
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %edx
callq 0xdd99
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq