// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movq %rdi, 0x8(%rsp)
movq 0x8475(%rip), %rax      # 0xc0c0
testq %rax, %rax
je 0x3c86
movq 0x70(%rax), %rbx
testq %rbx, %rbx
je 0x3c86
movl (%rbx), %ebp
addq $0x4, %rbx
xorl %r14d, %r14d
cmpl %ebp, %r14d
jg 0x3c86
leaq 0x4(%rbx), %rsi
movq 0x8(%rsp), %rdi
callq 0x20f0
testl %eax, %eax
je 0x3e2c
incl %r14d
addq $0x18, %rbx
jmp 0x3c62
movl %r15d, 0x1c(%rsp)
movslq 0x60be(%rip), %rax      # 0x9d50
movq %rax, 0x20(%rsp)
leal -0x1(%rax), %ebx
movq $0x0, 0x10(%rsp)
movq 0x609e(%rip), %r15      # 0x9d48
xorl %ebp, %ebp
cmpl %ebx, %ebp
jg 0x3d39
leal (%rbx,%rbp), %r13d
shrl %r13d
imulq $0x18, %r13, %rax
leaq (%r15,%rax), %r14
leaq (%r15,%rax), %r12
addq $0x4, %r12
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x20f0
testl %eax, %eax
jns 0x3ce4
decl %r13d
movl %r13d, %ebx
jmp 0x3cf0
je 0x3dec
incl %r13d
movl %r13d, %ebp
movl (%r14), %eax
movl %eax, %ecx
notl %ecx
testw $0x101, %cx             # imm = 0x101
je 0x3d14
movl %eax, %ecx
andl $0x43, %ecx
cmpl $0x43, %ecx
je 0x3d14
andl $0x83, %eax
cmpl $0x83, %eax
jne 0x3cac
movq 0x8(%rsp), %rdi
movq %r12, %rsi
pushq $0x3
popq %rdx
callq 0x2060
testl %eax, %eax
movq 0x10(%rsp), %rax
cmoveq %r14, %rax
movq %rax, 0x10(%rsp)
jmp 0x3cac
cmpl $0x0, 0x1c(%rsp)
movq 0x10(%rsp), %rbx
jne 0x3d4e
testq %rbx, %rbx
jne 0x3e2c
movq 0x20(%rsp), %rdi
cmpl $0x1ffe, %edi           # imm = 0x1FFE
jg 0x3e3e
movl %ebp, %eax
imulq $0x18, %rdi, %rcx
addq %r15, %rcx
movq %rdi, %rdx
cmpq %rax, %rdx
jl 0x3d88
movq 0x10(%rcx), %rsi
movq %rsi, 0x28(%rcx)
movups (%rcx), %xmm0
movups %xmm0, 0x18(%rcx)
decq %rdx
addq $-0x18, %rcx
jmp 0x3d6b
incl %edi
movl %edi, 0x5fc0(%rip)      # 0x9d50
imulq $0x18, %rax, %rax
leaq (%r15,%rax), %rbx
addq %rax, %r15
addq $0x4, %r15
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x2070
andl $0x0, -0x4(%r15)
andl $0x0, 0x8(%r15)
andl $0x0, 0x10(%r15)
cmpb $0x0, 0x5fa7(%rip)      # 0x9d69
je 0x3de1
cmpl $0x2, 0x5fb5(%rip)      # 0x9d80
jne 0x3de1
movslq 0x10(%rbx), %rax
testq %rax, %rax
js 0x3de1
movq 0x60db(%rip), %rcx      # 0x9eb8
andl $0x0, (%rcx,%rax,4)
cmpl $0x0, 0x95d0(%rip)      # 0xd3b8
jne 0x3e21
jmp 0x3e2c
cmpl $0x0, 0x95c5(%rip)      # 0xd3b8
je 0x3e29
testb $0x1, (%r14)
jne 0x3e29
cmpl $0x2, 0x5f7e(%rip)      # 0x9d80
jne 0x3e29
movl $0x1, (%r14)
movl 0x95ab(%rip), %eax      # 0xd3bc
leal 0x1(%rax), %ecx
movl %ecx, 0x95a2(%rip)      # 0xd3bc
movl %eax, 0xc(%r14)
movq %r14, %rbx
incl 0x8329(%rip)            # 0xc150
jmp 0x3e2c
movq %r14, %rbx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x826c(%rip), %edx      # 0xc0b0
leaq 0x5da5(%rip), %rdi      # 0x9bf0
movq 0x8(%rsp), %rsi
callq 0x3ea0
pushq $0x1
popq %rdi
callq 0x2170