// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x12af0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movq -0x8(%rbp), %rdx
movslq 0xc(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0xb356
callq 0x22e0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xb26f
callq 0x22e0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0xb26f
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2e, %eax
je 0xb26f
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x24, %eax
je 0xb26f
leaq 0x1044a(%rip), %rax     # 0x1b6a0
cmpl $0x0, (%rax)
je 0xb345
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5f, %eax
jne 0xb345
movq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xbf60
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xb337
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xb380
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0xb324
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0xb2c9
movq -0x18(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x27, %eax
jne 0xb2c9
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x27, %eax
jne 0xb2e1
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x12c70
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x12d50
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x40(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xb343
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb351
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb1d8
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x12c70
movq -0x28(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)