// File: /workspace/github_c_makefile_star2_O2/mist64[P]cbm6502asm/src/line.c
// Function: macsubst
void macsubst(char *parm, char *arg, char *subbed) { /* substitute macro args for parms */
	int angleb, dif, i, j, k, la, lp, ll;
	la = strlen(arg);
	lp = strlen(parm);
	ll = strlen(line);
	angleb = (arg[0] == '<') && (arg[la - 1] == '>'); /* is arg in <> ? */
	for (i = 0; i <= ll - lp; i++) {
		if (strncmp(&line[i], parm, lp)) /* search for parms */
			continue;                /* no match */
		for (k = j = 0; !j && k < lp; k++)
			j |= subbed[k + i]; /* test if part of recent subs */
		if (j) continue;            /* don't replace if part of sub */
		dif = la - lp;              /* length diff of parm and arg */
		dif -= 2 * angleb;          /* 2 less if angle brackets */
		if (dif > 0)
			for (j = strlen(line) + dif + 1; j > i;
			     j--) { /* arg is longer than parm */
				line[j] = line[j - dif]; /* shift line */
				subbed[j] =
				        subbed[j - dif]; /* and sub'd flags */
			}
		if (dif < 0)
			for (j = i; j < strlen(line) + dif + 1;
			     j++) { /* parm is longer than arg */
				line[j] = line[j - dif]; /* shift line */
				subbed[j] =
				        subbed[j - dif]; /* and sub's flags */
			}

		for (j = angleb; j < la - angleb;
		     i++, j++) {           /* subst arg for parm */
			subbed[i] = 1;     /* substitution made */
			line[i] = arg[j];  /* insert arg */
			ll = strlen(line); /* line length may have changed */
		}
		i--; /* will be incremented by for */
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x10b0
movq %rax, %r12
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x10b0
movq %rax, 0x30(%rsp)
leaq 0x9046(%rip), %r13      # 0xe0c0
movq %r13, %rdi
callq 0x10b0
movq %rax, %rbp
xorl %edx, %edx
cmpb $0x3c, (%rbx)
movl $0x0, %eax
jne 0x50a2
movl %r12d, %eax
decl %eax
movslq %eax, %rcx
xorl %eax, %eax
cmpb $0x3e, (%rbx,%rcx)
sete %al
movq 0x30(%rsp), %rcx
movslq %ecx, %r15
leal (%rcx,%rax,2), %ecx
movl %r12d, %esi
subl %ecx, %esi
negl %ecx
addl %r12d, %ecx
incl %ecx
movl %ecx, 0x2c(%rsp)
movl %esi, 0xc(%rsp)
movslq %esi, %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x48(%rsp)
subl %eax, %r12d
movl %eax, %eax
movslq %r12d, %rsi
movq %rsi, 0x58(%rsp)
movq %r13, %rsi
subq %rcx, %rsi
movq %rsi, 0x40(%rsp)
movq 0x10(%rsp), %rsi
subq %rcx, %rsi
movq %rsi, 0x38(%rsp)
movq %rax, 0x60(%rsp)
addq %rax, %rbx
movq %rbx, 0x50(%rsp)
movq 0x18(%rsp), %rbx
movl %ebp, %eax
subl 0x30(%rsp), %eax
cmpl %eax, %edx
jg 0x5223
movq %rdx, 0x20(%rsp)
movslq %edx, %r14
leaq (%r14,%r13), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1070
testl %eax, %eax
jne 0x5158
movq 0x10(%rsp), %rax
leaq (%rax,%r14), %rbx
xorl %eax, %eax
xorl %ecx, %ecx
testl %ecx, %ecx
jne 0x514f
cmpq %r15, %rax
jge 0x514f
movsbl (%rbx,%rax), %ecx
incq %rax
jmp 0x513d
testl %ecx, %ecx
je 0x5161
movq 0x18(%rsp), %rbx
movq 0x20(%rsp), %rdx
incl %edx
jmp 0x5104
cmpl $0x0, 0xc(%rsp)
jle 0x519d
movq %r13, %rdi
callq 0x10b0
addl 0x2c(%rsp), %eax
cltq
cmpq %r14, %rax
jle 0x519d
movq 0x40(%rsp), %rcx
movb (%rcx,%rax), %cl
movb %cl, (%r13,%rax)
movq 0x38(%rsp), %rcx
movb (%rcx,%rax), %cl
movq 0x10(%rsp), %rdx
movb %cl, (%rdx,%rax)
decq %rax
jmp 0x5176
cmpl $0x0, 0xc(%rsp)
jns 0x51db
jmp 0x51c9
movq 0x40(%rsp), %rax
movb (%rax,%r14), %al
movb %al, (%r13,%r14)
movq 0x38(%rsp), %rax
movb (%rax,%r14), %al
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r14)
incq %r14
movq %r13, %rdi
callq 0x10b0
addq 0x48(%rsp), %rax
cmpq %r14, %rax
ja 0x51a6
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
addq %r14, %rax
cmpq 0x58(%rsp), %rax
jge 0x520f
movb $0x1, (%rbx,%r14)
movq 0x50(%rsp), %rax
movb (%rax,%r14), %al
movb %al, (%r12,%r14)
movq %r13, %rdi
callq 0x10b0
movq %rax, %rbp
incq %r14
jmp 0x51de
movq 0x20(%rsp), %rdx
addl %r14d, %edx
decl %edx
movq 0x18(%rsp), %rbx
jmp 0x515d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq