// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/decl.c
// Function: declcommon
static struct decl *
declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struct type *t, enum typequal tq, enum storageclass sc, struct decl *prior)
{
	struct decl *d;
	enum linkage linkage;
	const char *kindstr = kind == DECLFUNC ? "function" : "object";

	if (prior) {
		if (prior->linkage == LINKNONE)
			error(&tok.loc, "%s '%s' with no linkage redeclared", kindstr, name);
		linkage = getlinkage(kind, sc, prior, s == &filescope);
		if (prior->linkage != linkage)
			error(&tok.loc, "%s '%s' redeclared with different linkage", kindstr, name);
		if (!typecompatible(t, prior->type) || tq != prior->qual)
			error(&tok.loc, "%s '%s' redeclared with incompatible type", kindstr, name);
		if (asmname && (!prior->asmname || strcmp(prior->asmname, asmname) != 0))
			error(&tok.loc, "%s '%s' redeclared with different assembler name", kindstr, name);
		prior->type = typecomposite(t, prior->type);
		return prior;
	}
	if (s->parent)
		prior = scopegetdecl(s->parent, name, true);
	linkage = getlinkage(kind, sc, prior, s == &filescope);
	if (linkage != LINKNONE && s->parent) {
		/* XXX: should maintain map of identifiers with linkage to their declaration, and use that */
		if (s->parent != &filescope)
			prior = scopegetdecl(&filescope, name, false);
		if (prior && prior->linkage != LINKNONE) {
			if (prior->kind != kind)
				error(&tok.loc, "'%s' redeclared with different kind", name);
			if (prior->linkage != linkage)
				error(&tok.loc, "%s '%s' redeclared with different linkage", kindstr, name);
			if (!typecompatible(t, prior->type) || tq != prior->qual)
				error(&tok.loc, "%s '%s' redeclared with incompatible type", kindstr, name);
			if (!asmname)
				asmname = prior->asmname;
			else if (!prior->asmname || strcmp(prior->asmname, asmname) != 0)
				error(&tok.loc, "%s '%s' redeclared with different assembler name", kindstr, name);
			t = typecomposite(t, prior->type);
		}
	}
	d = mkdecl(name, kind, t, tq, linkage);
	d->asmname = asmname;
	scopeputdecl(s, d);
	return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0xc(%rsp)
movq %r8, %r14
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %rdx
movq 0x68(%rsp), %r15
movl 0x60(%rsp), %esi
cmpl $0x2, %ebp
leaq 0xd8e9(%rip), %rax      # 0x128d7
leaq 0xfc65(%rip), %r12      # 0x14c5a
cmoveq %rax, %r12
testq %r15, %r15
movq %rcx, 0x18(%rsp)
je 0x5109
movq %rbx, %r13
movq %r14, %rbx
movl 0xc(%r15), %r14d
testl %r14d, %r14d
jne 0x5043
leaq 0x170eb(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xceff(%rip), %rsi      # 0x11f27
movq %rdx, %r14
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xc536
movl 0x60(%rsp), %esi
movq %r14, %rdx
movl 0xc(%r15), %r14d
xorl %ecx, %ecx
cmpq 0x15f8c(%rip), %rdx     # 0x1afd8
sete %cl
movl %ebp, %edi
movq %r15, %rdx
callq 0x5ccf
cmpl %eax, %r14d
je 0x507d
leaq 0x170a3(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xceda(%rip), %rsi      # 0x11f4a
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xc536
movq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0xc85a
testb %al, %al
je 0x5097
movl 0xc(%rsp), %eax
cmpl %eax, 0x18(%r15)
je 0x50b6
leaq 0x1706a(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xcecb(%rip), %rsi      # 0x11f74
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xc536
cmpq $0x0, 0x18(%rsp)
je 0x50f4
movq 0x28(%r15), %rdi
testq %rdi, %rdi
je 0x50d5
movq 0x18(%rsp), %rsi
callq 0x3140
testl %eax, %eax
je 0x50f4
leaq 0x1702c(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xceb7(%rip), %rsi      # 0x11f9e
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xc536
movq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0xc95e
movq %rax, 0x10(%r15)
jmp 0x52c5
movq 0x58(%rdx), %rdi
testq %rdi, %rdi
je 0x512b
movq %rdx, %r15
pushq $0x1
popq %rdx
movl %esi, %r13d
movq %rbx, %rsi
callq 0xb758
movl %r13d, %esi
movq %r15, %rdx
jmp 0x512d
xorl %eax, %eax
xorl %ecx, %ecx
cmpq 0x15ea2(%rip), %rdx     # 0x1afd8
sete %cl
movl %ebp, %edi
movq %rdx, %r15
movq %rax, %r13
movq %rax, %rdx
callq 0x5ccf
movl %eax, %r8d
testl %eax, %eax
movq %r15, 0x20(%rsp)
je 0x5284
movq 0x58(%r15), %rax
testq %rax, %rax
je 0x5284
cmpq 0x15e6b(%rip), %rax     # 0x1afd8
movq %r13, %rax
je 0x5189
leaq 0x16f27(%rip), %rdi     # 0x1c0a0
movq %rbx, %rsi
xorl %edx, %edx
movl %r8d, %r15d
callq 0xb758
movl %r15d, %r8d
testq %rax, %rax
movq 0x18(%rsp), %r13
je 0x52a0
movl 0xc(%rax), %ecx
testl %ecx, %ecx
je 0x52a0
cmpl %ebp, 0x8(%rax)
movq %rax, 0x10(%rsp)
je 0x51d6
leaq 0x16f55(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xc102(%rip), %rsi      # 0x112c0
movq %rbx, %rdx
xorl %eax, %eax
movl %r8d, %r15d
callq 0xc536
movq 0x10(%rsp), %rax
movl %r15d, %r8d
movl 0xc(%rax), %ecx
movl %r8d, %r15d
cmpl %r8d, %ecx
je 0x5202
leaq 0x16f23(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xcd5a(%rip), %rsi      # 0x11f4a
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc536
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0xc85a
testb %al, %al
je 0x5220
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl %eax, 0x18(%rcx)
je 0x523f
leaq 0x16ee1(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xcd42(%rip), %rsi      # 0x11f74
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc536
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rdi
testq %r13, %r13
je 0x528b
testq %rdi, %rdi
je 0x525e
movq %r13, %rsi
callq 0x3140
testl %eax, %eax
je 0x527d
leaq 0x16ea3(%rip), %rdi     # 0x1c108
addq $0x8, %rdi
leaq 0xcd2e(%rip), %rsi      # 0x11f9e
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc536
movq 0x10(%rsp), %rax
jmp 0x528e
movq 0x18(%rsp), %r13
jmp 0x52a0
movq %rdi, %r13
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0xc95e
movq %rax, %r14
movl %r15d, %r8d
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl 0xc(%rsp), %ecx
callq 0x3724
movq %rax, %r15
movq %r13, 0x28(%rax)
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xb693
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq