// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/crossassemblers/macro1/macro1.c
// Function: defineMacro
void
defineMacro() {
    int lexstartsave;			/* point to macro name */
    int index;				/* point to error char */
    int error;				/* error boolean */
    int i;
    int count;
    WORD32  length;
    WORD32  value;
    char    termin[SYMLEN];
    char    args[MAC_MAX_ARGS][SYMLEN];	/* macro & arg names */
    char    body[MAC_MAX_LENGTH + 1];
    struct macdef *mdp;
    SYM_T *sym;

    if (nrepeats) {
	/* we can call readLine, so throw up hands now */
	errorLexeme( &define_in_repeat, lexstartprev );
	return;
    }

    while (line[lexstart] == ' ' || line[lexstart] == '\t')
	next(0);

    /* not a tab or space */
    if (ISEND(line[lexstart])) {	/* newline or EOS? */
	/* crock; next token should invisibly skip over line boundaries? */
	readLine();
	next(0);
	while (line[lexstart] == ' ' || line[lexstart] == '\t')
	    next(0);
    }

    /* XXX pick up macro name out here */

    count = 0;
    index = 0;
    error = FALSE;
    lexstartsave = lexstart;
    while (!ISDONE(line[lexstart]) && count < MAC_MAX_ARGS) {
	if (!isalnum(line[lexstart]) && index == 0)
	    index = lexstart;		/* error pointer */
	lexemeToName( args[count++], lexstart, lexterm );
	/* XXX error if NOT a comma (& not first dummy) ? */
	if (line[lexterm] == ',')
	    next(0);			/* eat the comma */
	next(0);
	if (line[lexstart] == ' ')
	    next(0);
    }
    if( count == 0 ) {			/* No macro name. */
	errorMessage( &no_macro_name, lexstartsave );
	error = TRUE;
    }
    else if( index ) {			/* Bad argument name. */
	errorMessage( &bad_dummy_arg, index );
	error = TRUE;
    }
    else if( mac_count >= MAC_TABLE_LENGTH ) {
	errorMessage( &macro_table_full, lexstartsave );
	error = TRUE;
    }
    else {
	value = mac_count++;		/* sym value is index into mac */
	defineSymbol( args[0], value, MACRO, lexstartsave );
    }

    for( length = 0;; ) {
	readLine();
	if (end_of_input)
	    break;
	next(0);
	while (line[lexstart] == ' ' || line[lexstart] == '\t')
	    next(0);

	lexemeToName( termin, lexstart, lexterm ); /* just look at line? */
	if (strncmp( termin, "term", 4 ) == 0)
	    break;

	if (!error) {
	    int ll = strlen(line);
	    int allblank = FALSE;

	    /* don't save blank lines! */
	    for( i = 0; i < ll && allblank; i++ )
		if(!ISBLANK(line[i]))
		    allblank = FALSE;

	    if (allblank)			/* nothing but air? */
		continue;			/* skip it! */

	    if ((length + ll + 1) >= MAC_MAX_LENGTH ) {
		errorMessage (&macro_too_long, lexstart );
		error = TRUE;
		continue;
	    }

	    strcpy(body+length, line);
	    length += ll;
	}
    } /* for */
    if( error )
	return;

    mdp = calloc(1, sizeof(struct macdef) + length);
    if (mdp == NULL) {
	fprintf(stderr, "error allocating memory for macro definition\n");
	exit(1);
    }
    mac_defs[value] = mdp;

    strncpy(mdp->body, body, length);
    mdp->body[length] = '\0';
    mdp->nargs = count - 1;

    /*
     * save dummy names
     * symbol slot 0 reserved for "r" symbol
     * move SYM_T entries to macinv to allow recursion
     */
    sym = mdp->args;
    sym->type = DEFINED;
    strcpy(sym->name, "R");
    sym->val = 0;
    sym->xref_index = -1;		/* ??? allow xref? */
    sym++;

    for (i = 1; i <= mdp->nargs; i++, sym++) {
	sym->type = DEFINED;
	strcpy(sym->name, args[i]);
	sym->val = 0;
	sym->xref_index = -1;		/* don't xref!! */
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20e0, %rsp           # imm = 0x20E0
cmpl $0x0, 0x8a92(%rip)      # 0xf3c4
je 0x694b
movl 0x780a(%rip), %esi      # 0xe144
leaq 0x530f(%rip), %rdi      # 0xbc50
callq 0x4d20
jmp 0x6f6b
jmp 0x694d
movslq 0x775c(%rip), %rcx      # 0xe0b0
leaq 0x76f5(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x20d9(%rbp)
je 0x698a
movslq 0x773d(%rip), %rcx      # 0xe0b0
leaq 0x76d6(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x20d9(%rbp)
movb -0x20d9(%rbp), %al
testb $0x1, %al
jne 0x6996
jmp 0x699f
xorl %edi, %edi
callq 0x3e10
jmp 0x694d
movslq 0x770a(%rip), %rcx      # 0xe0b0
leaq 0x76a3(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x69e4
movslq 0x76f3(%rip), %rcx      # 0xe0b0
leaq 0x768c(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x69e4
movslq 0x76dc(%rip), %rcx      # 0xe0b0
leaq 0x7675(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
jne 0x6a44
callq 0x5360
xorl %edi, %edi
callq 0x3e10
movslq 0x76b9(%rip), %rcx      # 0xe0b0
leaq 0x7652(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x20da(%rbp)
je 0x6a2d
movslq 0x769a(%rip), %rcx      # 0xe0b0
leaq 0x7633(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x20da(%rbp)
movb -0x20da(%rbp), %al
testb $0x1, %al
jne 0x6a39
jmp 0x6a42
xorl %edi, %edi
callq 0x3e10
jmp 0x69f0
jmp 0x6a44
movl $0x0, -0x14(%rbp)
movl $0x0, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl 0x7651(%rip), %eax      # 0xe0b0
movl %eax, -0x4(%rbp)
movslq 0x7647(%rip), %rcx      # 0xe0b0
leaq 0x75e0(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x2f, %ecx
movb %al, -0x20db(%rbp)
je 0x6aeb
movslq 0x7628(%rip), %rcx      # 0xe0b0
leaq 0x75c1(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x20db(%rbp)
je 0x6aeb
movslq 0x7609(%rip), %rcx      # 0xe0b0
leaq 0x75a2(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x20db(%rbp)
je 0x6aeb
movslq 0x75ea(%rip), %rcx      # 0xe0b0
leaq 0x7583(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x20db(%rbp)
je 0x6aeb
cmpl $0x14, -0x14(%rbp)
setl %al
movb %al, -0x20db(%rbp)
movb -0x20db(%rbp), %al
testb $0x1, %al
jne 0x6afa
jmp 0x6ba6
callq 0x21b0
movq (%rax), %rax
movslq 0x75a7(%rip), %rdx      # 0xe0b0
leaq 0x7540(%rip), %rcx      # 0xe050
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x6b32
cmpl $0x0, -0x8(%rbp)
jne 0x6b32
movl 0x7581(%rip), %eax      # 0xe0b0
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
cltq
leaq -0xb0(%rbp), %rdi
imulq $0x7, %rax, %rax
addq %rax, %rdi
movl 0x755d(%rip), %esi      # 0xe0b0
movl 0x75e3(%rip), %edx      # 0xe13c
callq 0x4b80
movslq 0x75d7(%rip), %rcx      # 0xe13c
leaq 0x74e4(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x6b7c
xorl %edi, %edi
callq 0x3e10
xorl %edi, %edi
callq 0x3e10
movslq 0x7526(%rip), %rcx      # 0xe0b0
leaq 0x74bf(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x6ba1
xorl %edi, %edi
callq 0x3e10
jmp 0x6a62
cmpl $0x0, -0x14(%rbp)
jne 0x6bc4
movl -0x4(%rbp), %esi
leaq 0x504a(%rip), %rdi      # 0xbc00
callq 0x56c0
movl $0x1, -0xc(%rbp)
jmp 0x6c35
cmpl $0x0, -0x8(%rbp)
je 0x6be2
movl -0x8(%rbp), %esi
leaq 0x503c(%rip), %rdi      # 0xbc10
callq 0x56c0
movl $0x1, -0xc(%rbp)
jmp 0x6c33
cmpl $0x400, 0x7568(%rip)    # imm = 0x400
jl 0x6c06
movl -0x4(%rbp), %esi
leaq 0x5048(%rip), %rdi      # 0xbc40
callq 0x56c0
movl $0x1, -0xc(%rbp)
jmp 0x6c31
movl 0x7548(%rip), %eax      # 0xe154
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x753d(%rip)      # 0xe154
movl %eax, -0x1c(%rbp)
leaq -0xb0(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x4(%rbp), %ecx
movl $0x101, %edx            # imm = 0x101
callq 0x2740
jmp 0x6c33
jmp 0x6c35
movl $0x0, -0x18(%rbp)
callq 0x5360
cmpb $0x0, 0x74e8(%rip)      # 0xe130
je 0x6c4f
jmp 0x6de1
xorl %edi, %edi
callq 0x3e10
movslq 0x7453(%rip), %rcx      # 0xe0b0
leaq 0x73ec(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x20dc(%rbp)
je 0x6c93
movslq 0x7434(%rip), %rcx      # 0xe0b0
leaq 0x73cd(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x20dc(%rbp)
movb -0x20dc(%rbp), %al
testb $0x1, %al
jne 0x6c9f
jmp 0x6ca8
xorl %edi, %edi
callq 0x3e10
jmp 0x6c56
leaq -0x23(%rbp), %rdi
movl 0x73fe(%rip), %esi      # 0xe0b0
movl 0x7484(%rip), %edx      # 0xe13c
callq 0x4b80
leaq -0x23(%rbp), %rdi
leaq 0x1cec(%rip), %rsi      # 0x89b4
movl $0x4, %edx
callq 0x2060
cmpl $0x0, %eax
jne 0x6cdc
jmp 0x6de1
cmpl $0x0, -0xc(%rbp)
jne 0x6ddc
leaq 0x7363(%rip), %rdi      # 0xe050
callq 0x2090
movl %eax, -0x20d4(%rbp)
movl $0x0, -0x20d8(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %ecx
xorl %eax, %eax
cmpl -0x20d4(%rbp), %ecx
movb %al, -0x20dd(%rbp)
jge 0x6d2c
cmpl $0x0, -0x20d8(%rbp)
setne %al
movb %al, -0x20dd(%rbp)
movb -0x20dd(%rbp), %al
testb $0x1, %al
jne 0x6d38
jmp 0x6d77
movslq -0x10(%rbp), %rcx
leaq 0x730d(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x6d6a
movslq -0x10(%rbp), %rcx
leaq 0x72f9(%rip), %rax      # 0xe050
movsbl (%rax,%rcx), %eax
cmpl $0xc, %eax
je 0x6d6a
movl $0x0, -0x20d8(%rbp)
jmp 0x6d6c
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x6d09
cmpl $0x0, -0x20d8(%rbp)
je 0x6d85
jmp 0x6c3c
movl -0x18(%rbp), %eax
addl -0x20d4(%rbp), %eax
addl $0x1, %eax
cmpl $0x2000, %eax           # imm = 0x2000
jl 0x6db6
movl 0x7312(%rip), %esi      # 0xe0b0
leaq 0x4e7b(%rip), %rdi      # 0xbc20
callq 0x56c0
movl $0x1, -0xc(%rbp)
jmp 0x6c3c
leaq -0x20c0(%rbp), %rdi
movslq -0x18(%rbp), %rax
addq %rax, %rdi
leaq 0x7285(%rip), %rsi      # 0xe050
callq 0x2070
movl -0x20d4(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x6c3c
cmpl $0x0, -0xc(%rbp)
je 0x6dec
jmp 0x6f6b
movslq -0x18(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
movl $0x1, %edi
callq 0x20e0
movq %rax, -0x20c8(%rbp)
cmpq $0x0, -0x20c8(%rbp)
jne 0x6e34
movq 0x41df(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x1b96(%rip), %rsi      # 0x89b9
movb $0x0, %al
callq 0x2110
movl $0x1, %edi
callq 0x2190
movq -0x20c8(%rbp), %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x520a(%rip), %rax      # 0xc050
movq %rdx, (%rax,%rcx,8)
movq -0x20c8(%rbp), %rdi
addq $0x1fc, %rdi            # imm = 0x1FC
leaq -0x20c0(%rbp), %rsi
movslq -0x18(%rbp), %rdx
callq 0x2040
movq -0x20c8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x0, 0x1fc(%rax,%rcx)
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movq -0x20c8(%rbp), %rax
movl %ecx, (%rax)
movq -0x20c8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20d0(%rbp)
movq -0x20d0(%rbp), %rax
movl $0x1, (%rax)
movq -0x20d0(%rbp), %rdi
addq $0x4, %rdi
leaq 0x1b2c(%rip), %rsi      # 0x89e7
callq 0x2070
movq -0x20d0(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x20d0(%rbp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x20d0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x20d0(%rbp)
movl $0x1, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x20c8(%rbp), %rcx
cmpl (%rcx), %eax
jg 0x6f6b
movq -0x20d0(%rbp), %rax
movl $0x1, (%rax)
movq -0x20d0(%rbp), %rdi
addq $0x4, %rdi
movslq -0x10(%rbp), %rax
leaq -0xb0(%rbp), %rsi
imulq $0x7, %rax, %rax
addq %rax, %rsi
callq 0x2070
movq -0x20d0(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x20d0(%rbp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movq -0x20d0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x20d0(%rbp)
jmp 0x6ef5
addq $0x20e0, %rsp           # imm = 0x20E0
popq %rbp
retq
nopw %cs:(%rax,%rax)