// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro1/macro1.c
// Function: lookup
SYM_T *lookup( char *name, int type )
{
    int ix;				/* Insertion index */
    int lx;				/* Left index */
    int rx;				/* Right index */
    SYM_T *best;			/* best match */
    SYM_T *sym;

    /* YIKES!  Search dummies (and "R") before anything else!! */
    if (curmacro && curmacro->defn) {
	struct macdef *mdp = curmacro->defn;
	int i;

	for (i = 0, sym = mdp->args; i <= mdp->nargs; i++, sym++)
	    if (strcmp(name, sym->name) == 0)
		return sym;
    }

    lx = 0;
    rx = symbol_top - 1;
    best = NULL;
    while (lx <= rx) {
	int mx = (lx + rx) / 2;		/* Find center of search area. */
	int compare;

	sym = symtab + mx;

	compare = strcmp(name, sym->name);
	if (compare < 0)
	    rx = mx - 1;
	else if (compare > 0)
	    lx = mx + 1;
	else {				/* match */
	    if (overbar && !M_DEFINED(sym->type) && pass == 2) {
		sym->type = DEFINED;
		sym->val = vars_addr++;
		nvars++;
	    }
	    return sym;			/* return exact match */
	} /* match */

	/* save best non-exact match; MACRO returns last defined n-x match! */
	if ((M_PSEUDO(sym->type)||M_EPSEUDO(sym->type)||M_MACRO(sym->type)) &&
	    strncmp(name, sym->name, 3) == 0)
	    best = sym;
    } /* while */

    /* return best match (pseudo or macro) if any for lookups (not defns) */
    if (best && type == UNDEFINED)
	return best;

    /* Must put symbol in table if index is negative. */
    ix = lx;				/* insertion point */
    if( symbol_top + 1 >= SYMBOL_TABLE_SIZE ) {
	errorSymbol( &symbol_table_full, name, lexstart );
	exit( 1 );
    }

    for( rx = symbol_top; rx >= ix; rx-- )
	symtab[rx + 1] = symtab[rx];

    symbol_top++;

    /* Enter the symbol as UNDEFINED with a value of zero. */
    sym = symtab + ix;
    strcpy( sym->name, name );
    sym->type = UNDEFINED;
    sym->val  = 0;
    sym->xref_count = 0;
    if( xref && pass == 2 && sym->xref_index >= 0)
	xreftab[sym->xref_index] = 0;

    if (overbar)
	nvars++;

    return sym;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r14d
movq %rdi, 0x18(%rsp)
movq 0x808e(%rip), %rax      # 0xc0c0
testq %rax, %rax
je 0x4089
movq 0x70(%rax), %rax
testq %rax, %rax
je 0x4089
leaq 0x4(%rax), %r15
movslq (%rax), %rcx
testq %rcx, %rcx
js 0x4265
leaq (%rcx,%rcx,2), %rdx
leaq (%rax,%rdx,8), %rbx
addq $0x1c, %rbx
leal 0x1(%rcx), %ebp
leaq 0x4(%r15), %rsi
movq 0x18(%rsp), %rdi
callq 0x20f0
testl %eax, %eax
je 0x4274
addq $0x18, %r15
decl %ebp
jne 0x405f
movl %r14d, 0x14(%rsp)
movq %rbx, 0x8(%rsp)
jmp 0x408e
movl %r14d, 0x14(%rsp)
movl 0x5cbc(%rip), %ebp      # 0x9d50
decl %ebp
movq $0x0, 0x20(%rsp)
movq 0x5ca2(%rip), %r13      # 0x9d48
xorl %r12d, %r12d
cmpl %ebp, %r12d
jg 0x4189
leal (%r12,%rbp), %ebx
shrl %ebx
leaq (%rbx,%rbx,2), %rax
leaq (,%rax,8), %r14
addq %r13, %r14
leaq 0x4(,%rax,8), %r15
addq %r13, %r15
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x20f0
testl %eax, %eax
jns 0x40e9
decl %ebx
movl %ebx, %ebp
jmp 0x40f0
je 0x413b
incl %ebx
movl %ebx, %r12d
movl (%r14), %eax
movl %eax, %ecx
notl %ecx
movb $0x1, %bl
testl $0x101, %ecx            # imm = 0x101
je 0x4117
movl %eax, %ecx
andl $0x43, %ecx
cmpl $0x43, %ecx
je 0x4117
andl $0x83, %eax
cmpl $0x83, %eax
jne 0x417c
movl $0x3, %edx
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x2060
testl %eax, %eax
movq 0x20(%rsp), %rax
cmoveq %r14, %rax
movq %rax, 0x20(%rsp)
jmp 0x417c
cmpl $0x0, 0x9276(%rip)      # 0xd3b8
je 0x4175
xorl %ebx, %ebx
testb $0x1, (%r14)
jne 0x4177
cmpl $0x2, 0x5c2d(%rip)      # 0x9d80
jne 0x4177
movl $0x1, (%r14)
movl 0x925a(%rip), %eax      # 0xd3bc
leal 0x1(%rax), %ecx
movl %ecx, 0x9251(%rip)      # 0xd3bc
movl %eax, 0xc(%r14)
incl 0x7fdb(%rip)            # 0xc150
xorl %ebx, %ebx
movq %r14, 0x8(%rsp)
testb %bl, %bl
jne 0x40a9
jmp 0x4279
cmpl $0x0, 0x14(%rsp)
jne 0x41a3
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x4279
movslq 0x5ba6(%rip), %rax      # 0x9d50
cmpq $0x1ffe, %rax           # imm = 0x1FFE
jg 0x428d
movl %r12d, %ecx
cmpl %r12d, %eax
jl 0x41ec
leaq 0x1(%rax), %rdx
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x5b77(%rip), %rsi      # 0x9d48
movq 0x10(%rsi), %rdi
movq %rdi, 0x28(%rsi)
movups (%rsi), %xmm0
movups %xmm0, 0x18(%rsi)
decq %rdx
addq $-0x18, %rsi
cmpq %rcx, %rdx
jg 0x41d1
incl %eax
movl %eax, 0x5b5c(%rip)      # 0x9d50
movq 0x5b4d(%rip), %rax      # 0x9d48
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rbx
leaq (%rax,%rcx,8), %r15
addq $0x4, %r15
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x2070
xorl %eax, %eax
movl %eax, -0x4(%r15)
movl %eax, 0x8(%r15)
movl %eax, 0x10(%r15)
cmpb $0x0, 0x5b3c(%rip)      # 0x9d69
je 0x424f
cmpl $0x2, 0x5b4a(%rip)      # 0x9d80
jne 0x424f
movslq 0x10(%rbx), %rax
testq %rax, %rax
js 0x424f
movq 0x5c70(%rip), %rcx      # 0x9eb8
movl $0x0, (%rcx,%rax,4)
movq %rbx, 0x8(%rsp)
cmpl $0x0, 0x915d(%rip)      # 0xd3b8
je 0x4279
incl 0x7eed(%rip)            # 0xc150
jmp 0x4279
movq %r15, 0x8(%rsp)
movl %r14d, 0x14(%rsp)
jmp 0x408e
movq %r15, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x7e1d(%rip), %edx      # 0xc0b0
leaq 0x5956(%rip), %rdi      # 0x9bf0
movq 0x18(%rsp), %rsi
callq 0x42f3
movl $0x1, %edi
callq 0x2170