// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x8466(%rip), %rax      # 0xdc16
movb $0x44, (%rax)
leaq 0x8632(%rip), %rax      # 0xddec
movl $0x1, (%rax)
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x7bf7
movl $0x200, %edi            # imm = 0x200
callq 0x1180
leaq 0x849a(%rip), %r14      # 0xdc80
movq %rax, (%r14)
leaq 0x8298(%rip), %rax      # 0xda88
movq (%rax), %rcx
movb (%rcx), %cl
testb %cl, %cl
je 0x5810
xorl %ebx, %ebx
movq (%r14), %rdx
movl %ebx, %esi
incl %ebx
movb %cl, 0xc(%rdx,%rsi)
movq (%rax), %rcx
movb (%rcx,%rbx), %cl
testb %cl, %cl
jne 0x57fb
movq (%r14), %rax
movl %ebx, %ecx
incl %ebx
xorl %edx, %edx
movb %dl, 0xc(%rax,%rcx)
movq (%r14), %rax
movb %dl, 0x2b(%rax)
cmpl $0x20, %ebx
movl $0x20, %ebp
cmovbl %ebx, %ebp
cmpb %dl, 0xc(%rax)
jne 0x5847
leaq 0x85b6(%rip), %rax      # 0xddf0
movb $0x44, (%rax)
movl $0x44, %edi
callq 0x1ed1
movl $0x1, %edi
callq 0x5171
leaq 0x8848(%rip), %rax      # 0xe0a0
movq (%rax), %rdx
cmpb $0x0, (%rdx)
movl %ebp, %ecx
jne 0x5868
cmpb $0x0, 0x1(%rdx)
je 0x587c
leaq 0x1(%rdx), %rsi
movq %rsi, (%rax)
movb (%rdx), %dl
movq (%r14), %rsi
incl %ebp
movb %dl, 0xc(%rsi,%rcx)
jmp 0x5858
movq (%r14), %rax
leal 0x1(%rbp), %edx
xorl %esi, %esi
movb %sil, 0xc(%rax,%rcx)
movq (%r14), %rax
addl $0x2, %ebp
movb %sil, 0xc(%rax,%rdx)
movl $0x1, %ebx
movl $0x200, %r13d           # imm = 0x200
leaq 0x87f2(%rip), %r14      # 0xe098
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x55cc
leaq 0x852b(%rip), %rax      # 0xddec
movl $0x1, (%rax)
movq (%r14), %r15
movq %r15, %rdi
leaq 0x4a14(%rip), %rsi      # 0xa2e8
callq 0x1130
testl %eax, %eax
je 0x5916
movq %r15, %rdi
leaq 0x49fc(%rip), %rsi      # 0xa2e3
callq 0x1130
testl %eax, %eax
je 0x5916
movq %r15, %rdi
leaq 0x49e3(%rip), %rsi      # 0xa2dd
callq 0x1130
testl %eax, %eax
je 0x5916
movq %r15, %rdi
leaq 0x49b6(%rip), %rsi      # 0xa2c3
callq 0x1130
testl %eax, %eax
jne 0x5918
incl %ebx
movq %r15, %rdi
leaq 0x50b4(%rip), %rsi      # 0xa9d6
callq 0x1130
testl %eax, %eax
je 0x593e
movq %r15, %rdi
leaq 0x50a7(%rip), %rsi      # 0xa9dc
callq 0x1130
testl %eax, %eax
jne 0x5940
decl %ebx
movq %r15, %rdi
leaq 0x49ef(%rip), %rsi      # 0xa339
callq 0x1130
testl %eax, %eax
jne 0x5972
leaq 0x8326(%rip), %rax      # 0xdc80
movq (%rax), %rsi
addq $0xc, %rsi
leaq 0x507a(%rip), %rdi      # 0xa9e2
movl $0x4, %edx
callq 0x1e94
leaq 0x829d(%rip), %rax      # 0xdc16
movb $0x44, (%rax)
movq %r14, %r12
movq (%r14), %r15
movq %r15, %rdi
leaq 0x504a(%rip), %rsi      # 0xa9d6
callq 0x1130
movl %ebp, %r14d
cmpl $0x1, 0xc(%rsp)
jne 0x599f
testl %eax, %eax
je 0x59b9
movq %r15, %rdi
leaq 0x5033(%rip), %rsi      # 0xa9dc
callq 0x1130
cmpl $0x2, 0xc(%rsp)
jl 0x59c1
testl %eax, %eax
jne 0x59c1
testl %ebx, %ebx
je 0x5a7c
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x7bf7
leal 0x8e(%rbp), %eax
cmpl %r13d, %eax
leaq 0x829c(%rip), %r15      # 0xdc80
jbe 0x5a2c
movq (%r15), %rdi
addl $0x200, %r13d           # imm = 0x200
movq %r13, %rsi
callq 0x11b0
leaq 0x8279(%rip), %rcx      # 0xdc78
movq %rax, (%rcx)
testq %rax, %rax
jne 0x5a26
movq (%r15), %rsi
addq $0xc, %rsi
leaq 0x4ffb(%rip), %rdi      # 0xaa10
movl $0x4, %edx
callq 0x1e94
leaq 0x8252(%rip), %rcx      # 0xdc78
movq (%rcx), %rax
movq %rax, (%r15)
movq (%r15), %rdi
addq $0xc, %rdi
leaq 0x8676(%rip), %rax      # 0xe0b0
cmpb $0x0, (%rax)
je 0x5a61
addq %r14, %rdi
movq %rax, %r14
movq %rax, %rsi
callq 0x1080
movq %r14, %rdi
callq 0x10b0
addl %eax, %ebp
incl %ebp
movq %r12, %r14
jmp 0x58a6
leal 0x1(%rbp), %eax
movb $0x20, (%rdi,%r14)
movq (%r15), %rcx
addl $0x2, %ebp
movb $0x0, 0xc(%rcx,%rax)
movq %r12, %r14
jmp 0x58a6
leaq 0x81fd(%rip), %r15      # 0xdc80
movq (%r15), %rax
movb $0x0, 0xc(%rax,%r14)
addl $0x9, %ebp
movq (%r15), %rdi
movl %ebp, 0x8(%rdi)
leaq 0x8354(%rip), %rax      # 0xddf0
cmpb $0x0, (%rax)
je 0x5ab4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1040
leaq 0x7fed(%rip), %rbx      # 0xdaa8
movq (%rbx), %rax
movq %rax, (%rdi)
movq (%r15), %rdi
movl %ebp, %esi
callq 0x11b0
leaq 0x81a6(%rip), %rcx      # 0xdc78
movq %rax, (%rcx)
movq %rax, (%rbx)
testq %rax, %rax
je 0x5aec
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rsi
addq $0xc, %rsi
leaq 0x4f16(%rip), %rdi      # 0xaa10
movl $0x4, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1e94