// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro1/macro1.c
// Function: invokeMacro
int
invokeMacro(int index)
{
    struct macinv *mip;
    struct macdef *mdp;
    int jx;

    mdp = mac_defs[index];
    if (mdp == NULL || mdp->body[0] == '\0')
	return 0;

    /* Find arguments. */
    while (ISBLANK(line[lexstart]))
	next(0);

    mip = calloc(1, sizeof(struct macinv));
    if (!mip) {
	fprintf(stderr, "could not allocate memory for macro invocation\n");
	exit(1);
    }
    mip->defn = mdp;

    /* evaluate args, saving values in SYM_T entries in defn.
     * (cannot have recursive macros)
     */
    mdp->args[0].val = clc;		/* r is location at start */
    for( jx = 1; !ISDONE(line[lexstart]) && jx <= MAC_MAX_ARGS; ) {
	WORD32 val;

	next(0);
	if (ISDONE(line[lexstart]))
	    break;

	if (line[lexstart] == ',')
	    next(0);

	while( ISBLANK( line[lexstart] ))
	    next(0);

	if (ISDONE(line[lexstart]))
	    break;

	val = getExprs();

	/* ignore excess values silently? */
	if (jx <= mdp->nargs)
	    mdp->args[jx].val = val;
	jx++;
    } /* end for */

    /* XXX complain if too few actuals? -- nah */
    while (jx <= mdp->nargs)
	mdp->args[jx++].val = 0;

    strcpy(mip->mac_line, line);	/* save line */
    mip->mac_cc = cc;			/* save position in line */
    mip->mac_ptr = mdp->body;
    mip->prev = curmacro;		/* push the old entry */
    curmacro = mip;			/* step up to the plate! */
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq %edi, %rax
leaq 0x69c5(%rip), %rcx      # 0xa050
movq (%rcx,%rax,8), %r15
xorl %eax, %eax
testq %r15, %r15
je 0x3836
cmpb $0x0, 0x1fc(%r15)
je 0x3836
leaq 0x1fc(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x8995(%rip), %r12      # 0xc050
movslq 0x89ee(%rip), %rax      # 0xc0b0
movzbl (%rax,%r12), %eax
cmpl $0x20, %eax
je 0x36d1
cmpl $0xc, %eax
jne 0x36da
xorl %edi, %edi
callq 0x384a
jmp 0x36bb
movl $0x1, %edi
movl $0x80, %esi
callq 0x20e0
testq %rax, %rax
je 0x3845
movq %rax, %rbx
movq %r15, 0x70(%rax)
movl 0x89b5(%rip), %eax      # 0xc0b4
leaq 0x4(%r15), %rcx
movq %rcx, 0x8(%rsp)
movl %eax, 0x10(%r15)
movl $0x1, %ebp
movabsq $0x800000000601, %r13   # imm = 0x800000000601
movslq 0x898e(%rip), %rax      # 0xc0b0
movzbl (%rax,%r12), %eax
cmpq $0x2f, %rax
ja 0x3741
movabsq $0x800000000401, %rcx   # imm = 0x800000000401
btq %rax, %rcx
jb 0x37d6
cmpb $0x9, %al
je 0x37d6
cmpl $0x14, %ebp
jg 0x37d6
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x384a
movslq 0x894d(%rip), %rax      # 0xc0b0
movzbl (%rax,%r12), %eax
cmpq $0x2f, %rax
ja 0x377a
btq %rax, %r13
jb 0x3795
cmpq $0x2c, %rax
je 0x37ac
movslq 0x892f(%rip), %rax      # 0xc0b0
movzbl (%rax,%r12), %eax
cmpq $0x2f, %rax
ja 0x37b5
btq %rax, %r13
jae 0x379c
xorl %r14d, %r14d
testb %r14b, %r14b
jne 0x371b
jmp 0x37d6
movabsq $0x100001000, %rcx      # imm = 0x100001000
btq %rax, %rcx
jae 0x37b5
xorl %edi, %edi
callq 0x384a
jmp 0x377a
callq 0x398a
cmpl (%r15), %ebp
jg 0x37cf
movslq %ebp, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rsp), %rdx
movl %eax, 0xc(%rdx,%rcx,8)
incl %ebp
movb $0x1, %r14b
jmp 0x3795
movl (%r15), %eax
cmpl %eax, %ebp
jg 0x37fe
movslq %ebp, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%r15,%rcx,8), %rcx
addq $0x10, %rcx
subl %ebp, %eax
incl %eax
movl $0x0, (%rcx)
addq $0x18, %rcx
decl %eax
jne 0x37f0
leaq 0x884b(%rip), %rsi      # 0xc050
movq %rbx, %rdi
callq 0x2070
movl 0x88a5(%rip), %eax      # 0xc0b8
movl %eax, 0x60(%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x68(%rbx)
movq 0x889a(%rip), %rax      # 0xc0c0
movq %rax, 0x78(%rbx)
movq %rbx, 0x888f(%rip)      # 0xc0c0
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x237b