// File: /workspace/github_c_makefile_star2_O0/mist64[P]cbm6502asm/src/macrodef.c
// Function: macro_def
void macro_def(char *macprmbgn, char **maclinptr, char *macargbgn, int mactype) {
/* mactype: 1=.MACRO 2=.REPT 3=.IRP 4=.IRPC */
	unsigned int i, l, m, macrocnt = 1;

	spechar = 'D';
	print = 1;
	outline((char)0, (char)0, (char *)0, (char)0, (char)1);
	newmac = (struct macdef *)malloc(
	        l = CHUNK); /* initial size of structure */
	                    /*
	                      save macro name
	                    */
	for (m = i = 0; s1[i]; i++) newmac->name[m++] = s1[i]; /* copy name */
	newmac->name[31] = newmac->name[m++] = 0; /* terminate name string */
	m = m > 32 ? 32 : m;                /* fix up if name was > 31 chars */
	if (!strlen(newmac->name))          /* check for missing name */
		display_error(error = 'D'); /* missing macro name */
	                                    /*
	                                      get macro's parameter list
	                                    */
	parses3(1);                         /* separate fields in operand */
	while (*s3 || s3[1])                /* copy parms to macro definition */
		newmac->name[m++] = *s3++;
	newmac->name[m++] = 0;
	newmac->name[m++] = 0;
	/*
	  store the macro definition lines
	*/
	i = 1;
	while (i) {
		get_line(macprmbgn, maclinptr,
		         macargbgn); /* get a source or macro exp line */
		print = 1;

		if (strcmp(s2, ".MACRO") ==
		            0 || /* check for nested macro defs */
		    strcmp(s2, ".IRP") == 0 ||
		    strcmp(s2, ".IRPC") == 0 || strcmp(s2, ".REPT") == 0)
			macrocnt++;
		if (strcmp(s2, ".ENDM") == 0 || strcmp(s2, ".ENDR") == 0)
			macrocnt--;

		if (!strcmp(s2, ".END"))
			error_msg(
			        ".END encountered during definition of macro: ",
			        newmac->name, 4);

		spechar = 'D';
		/* check for end of macro definition */
		if (((!strcmp(s2, ".ENDM") && mactype == 1) ||
		     (!strcmp(s2, ".ENDR") && mactype > 1)) &&
		    !macrocnt) {
			newmac->name[m++] =
			        0; /* add a null indicating macro end */
			newmac->size = m + 8;
			if (error) {
				free((char *)newmac); /* don't save macro if
				                         error */
				return;
			}
			newmac->nextmac = macro_head; /* link macro definition
			                                 into list */
			/* truncated memory block */
			tmpmac =
			        (struct macdef *)realloc((char *)newmac, m + 8);
			if (!(long)(macro_head = tmpmac))
				error_msg("Available memory exceeded",
				          newmac->name, 4);
			return; /* finished */
		}
		outline((char)0, (char)0, (char *)0, (char)0, (char)1);
		/* check for macro def in macro */
		if (m + 8 + LINELENG > l) { /* alloc more memory if needed */
			tmpmac = (struct macdef *)realloc((char *)newmac,
			                                  l += CHUNK);
			if (!(long)tmpmac) /* check if allocation sucessful */
				error_msg("Available memory exceeded",
				          newmac->name, 4);
			newmac = tmpmac; /* allocation was successful */
		}
		if (strlen(line)) {
			strcpy(&newmac->name[m], line); /* copy the line */
			m += 1 + strlen(line); /* add length of line and null */
		} else {
			newmac->name[m++] = ' '; /* blank line */
			newmac->name[m++] = 0;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x1, -0x2c(%rbp)
leaq 0x91d1(%rip), %rax      # 0x10c06
movb $0x44, (%rax)
leaq 0x939d(%rip), %rax      # 0x10ddc
movl $0x1, (%rax)
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %r8d
movl %ecx, %edi
movl %ecx, %esi
callq 0xacb0
movl $0x200, -0x24(%rbp)     # imm = 0x200
movl $0x200, %edi            # imm = 0x200
callq 0x1160
movq %rax, %rcx
leaq 0x91fb(%rip), %rax      # 0x10c70
movq %rcx, (%rax)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
leaq 0x8feb(%rip), %rax      # 0x10a78
movq (%rax), %rax
movl -0x20(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x7acf
leaq 0x8fd8(%rip), %rax      # 0x10a78
movq (%rax), %rax
movl -0x20(%rbp), %ecx
movb (%rax,%rcx), %dl
leaq 0x91c0(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, 0xc(%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x7a86
leaq 0x919a(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x0, 0xc(%rax,%rcx)
leaq 0x917e(%rip), %rax      # 0x10c70
movq (%rax), %rax
movb $0x0, 0x2b(%rax)
cmpl $0x20, -0x28(%rbp)
jbe 0x7b09
movl $0x20, %eax
movl %eax, -0x30(%rbp)
jmp 0x7b0f
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
leaq 0x9154(%rip), %rax      # 0x10c70
movq (%rax), %rdi
addq $0xc, %rdi
callq 0x10a0
cmpq $0x0, %rax
jne 0x7b42
leaq 0x92ab(%rip), %rax      # 0x10de0
movb $0x44, (%rax)
movl $0x44, %edi
callq 0x2350
movl $0x1, %edi
callq 0x7120
leaq 0x953d(%rip), %rax      # 0x11090
movq (%rax), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
jne 0x7b7a
leaq 0x9526(%rip), %rax      # 0x11090
movq (%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x7b83
jmp 0x7bbd
leaq 0x9506(%rip), %rax      # 0x11090
movq (%rax), %rax
movq %rax, %rdx
addq $0x1, %rdx
leaq 0x94f5(%rip), %rcx      # 0x11090
movq %rdx, (%rcx)
movb (%rax), %dl
leaq 0x90c9(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, 0xc(%rax,%rcx)
jmp 0x7b4c
leaq 0x90ac(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x0, 0xc(%rax,%rcx)
leaq 0x9090(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x0, 0xc(%rax,%rcx)
movl $0x1, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x7f5a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x7770
leaq 0x91be(%rip), %rax      # 0x10ddc
movl $0x1, (%rax)
leaq 0x945d(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x56d9(%rip), %rsi      # 0xd30e
callq 0x1110
cmpl $0x0, %eax
je 0x7c90
leaq 0x9442(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x56b9(%rip), %rsi      # 0xd309
callq 0x1110
cmpl $0x0, %eax
je 0x7c90
leaq 0x9427(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5698(%rip), %rsi      # 0xd303
callq 0x1110
cmpl $0x0, %eax
je 0x7c90
leaq 0x940c(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5663(%rip), %rsi      # 0xd2e9
callq 0x1110
cmpl $0x0, %eax
jne 0x7c99
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x93e8(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5c95(%rip), %rsi      # 0xd93f
callq 0x1110
cmpl $0x0, %eax
je 0x7ccf
leaq 0x93cd(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5c80(%rip), %rsi      # 0xd945
callq 0x1110
cmpl $0x0, %eax
jne 0x7cd8
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
leaq 0x93a9(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5658(%rip), %rsi      # 0xd341
callq 0x1110
cmpl $0x0, %eax
jne 0x7d12
leaq 0x8f76(%rip), %rax      # 0x10c70
movq (%rax), %rsi
addq $0xc, %rsi
leaq 0x5c43(%rip), %rdi      # 0xd94b
movl $0x4, %edx
callq 0x22f0
leaq 0x8eed(%rip), %rax      # 0x10c06
movb $0x44, (%rax)
leaq 0x9365(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5c12(%rip), %rsi      # 0xd93f
callq 0x1110
cmpl $0x0, %eax
jne 0x7d3d
cmpl $0x1, -0x1c(%rbp)
je 0x7d66
leaq 0x9344(%rip), %rax      # 0x11088
movq (%rax), %rdi
leaq 0x5bf7(%rip), %rsi      # 0xd945
callq 0x1110
cmpl $0x0, %eax
jne 0x7e3a
cmpl $0x1, -0x1c(%rbp)
jle 0x7e3a
cmpl $0x0, -0x2c(%rbp)
jne 0x7e3a
leaq 0x8ef9(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x0, 0xc(%rax,%rcx)
movl -0x28(%rbp), %ecx
addl $0x8, %ecx
leaq 0x8ed7(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl %ecx, 0x8(%rax)
leaq 0x903a(%rip), %rax      # 0x10de0
cmpb $0x0, (%rax)
je 0x7dbf
leaq 0x8ebe(%rip), %rax      # 0x10c70
movq (%rax), %rdi
callq 0x1030
jmp 0x7f5a
leaq 0x8cd2(%rip), %rax      # 0x10a98
movq (%rax), %rcx
leaq 0x8ea0(%rip), %rax      # 0x10c70
movq (%rax), %rax
movq %rcx, (%rax)
leaq 0x8e93(%rip), %rax      # 0x10c70
movq (%rax), %rdi
movl -0x28(%rbp), %eax
addl $0x8, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x1190
movq %rax, %rcx
leaq 0x8e6f(%rip), %rax      # 0x10c68
movq %rcx, (%rax)
leaq 0x8e65(%rip), %rax      # 0x10c68
movq (%rax), %rax
leaq 0x8c8b(%rip), %rcx      # 0x10a98
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x7e35
leaq 0x8e53(%rip), %rax      # 0x10c70
movq (%rax), %rsi
addq $0xc, %rsi
leaq 0x5b4e(%rip), %rdi      # 0xd979
movl $0x4, %edx
callq 0x22f0
jmp 0x7f5a
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %r8d
movl %ecx, %edi
movl %ecx, %esi
callq 0xacb0
movl -0x28(%rbp), %eax
addl $0x8, %eax
addl $0x86, %eax
cmpl -0x24(%rbp), %eax
jbe 0x7ecd
leaq 0x8e0a(%rip), %rax      # 0x10c70
movq (%rax), %rdi
movl -0x24(%rbp), %eax
addl $0x200, %eax            # imm = 0x200
movl %eax, -0x24(%rbp)
movl %eax, %eax
movl %eax, %esi
callq 0x1190
movq %rax, %rcx
leaq 0x8de1(%rip), %rax      # 0x10c68
movq %rcx, (%rax)
leaq 0x8dd7(%rip), %rax      # 0x10c68
movq (%rax), %rax
cmpq $0x0, %rax
jne 0x7eb9
leaq 0x8dcf(%rip), %rax      # 0x10c70
movq (%rax), %rsi
addq $0xc, %rsi
leaq 0x5aca(%rip), %rdi      # 0xd979
movl $0x4, %edx
callq 0x22f0
leaq 0x8da8(%rip), %rax      # 0x10c68
movq (%rax), %rcx
leaq 0x8da6(%rip), %rax      # 0x10c70
movq %rcx, (%rax)
leaq 0x91cc(%rip), %rdi      # 0x110a0
callq 0x10a0
cmpq $0x0, %rax
je 0x7f1d
leaq 0x8d8a(%rip), %rax      # 0x10c70
movq (%rax), %rdi
addq $0xc, %rdi
movl -0x28(%rbp), %eax
addq %rax, %rdi
leaq 0x91a6(%rip), %rsi      # 0x110a0
callq 0x1070
leaq 0x919a(%rip), %rdi      # 0x110a0
callq 0x10a0
movq %rax, %rcx
addq $0x1, %rcx
movl -0x28(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x28(%rbp)
jmp 0x7f55
leaq 0x8d4c(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x20, 0xc(%rax,%rcx)
leaq 0x8d30(%rip), %rax      # 0x10c70
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x28(%rbp)
movl %ecx, %ecx
movb $0x0, 0xc(%rax,%rcx)
jmp 0x7bfc
addq $0x40, %rsp
popq %rbp
retq