// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movq %rdi, %r15
callq 0xda54
movq %rax, 0x18(%rsp)
movq (%r15), %r13
cmpl $0x0, 0xc(%r15)
jle 0x8212
callq 0x2300
movq %rax, %r12
leaq 0x8(%rsp), %r14
movq %r13, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq (%r12), %rcx
movzbl (%r13), %eax
movzwl (%rcx,%rax,2), %ecx
testl $0xc00, %ecx            # imm = 0xC00
je 0x816f
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x8af9
testq %rax, %rax
je 0x818a
movq %rax, %rbx
testq %rbp, %rbp
je 0x81f3
movq %rbp, %r14
movq 0x10(%r14), %rdi
movq %rbx, %rsi
callq 0x21d0
testl %eax, %eax
je 0x818f
movq (%r14), %r14
testq %r14, %r14
jne 0x8155
jmp 0x81ee
cmpl $0x24, %eax
je 0x8134
cmpl $0x2e, %eax
je 0x8134
cmpl $0x5f, %eax
jne 0x818a
leaq 0xf4fb(%rip), %rax      # 0x17680
cmpl $0x0, (%rax)
jne 0x8134
incq %r13
jmp 0x8200
cmpq 0x10(%rsp), %r13
jbe 0x81a3
leaq -0x1(%r13), %rax
cmpb $0x27, -0x1(%r13)
cmoveq %rax, %r13
movq %rbp, %r12
movq 0x8(%rsp), %rax
cmpb $0x27, (%rax)
jne 0x81b8
incq %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rsi
subl %esi, %r13d
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movl %r13d, %edx
callq 0xdae1
movq 0x18(%r14), %rsi
movq %rbp, %rdi
callq 0xdb56
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rbp
movq 0x20(%rsp), %r12
leaq 0x8(%rsp), %r14
movq %rbx, %rdi
callq 0x2050
movq 0x8(%rsp), %r13
movslq 0xc(%r15), %rax
addq (%r15), %rax
cmpq %rax, %r13
jb 0x811f
jmp 0x8217
movq %r13, 0x10(%rsp)
movq 0x10(%rsp), %rsi
subl %esi, %r13d
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %edx
callq 0xdae1
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq