// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/symbol_table.c
// Function: prv_symbol_table_insert
static const subtilis_symbol_t *
prv_symbol_table_insert(subtilis_symbol_table_t *st, const char *key,
			const subtilis_type_t *id_type,
			const subtilis_type_t *sub_type, size_t size,
			size_t level, bool no_rc, subtilis_error_t *err)

{
	subtilis_symbol_t *sym;
	size_t align_bytes;
	size_t required_alignment;
	char *key_dup = NULL;

	sym = subtilis_hashtable_find(st->h, key);
	if (sym)
		return sym;

	key_dup = malloc(strlen(key) + 1);
	if (!key_dup) {
		subtilis_error_set_oom(err);
		goto on_error;
	}
	(void)strcpy(key_dup, key);

	/*
	 * TODO:  This can leave holes in our global data.  It would
	 * be good to keep track of those holes so we could plug them
	 * with bytes variables.
	 */

	if (size > 0) {
		required_alignment = subtilis_type_if_align(id_type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		align_bytes = st->allocated % required_alignment;
		if (align_bytes > 0)
			st->allocated += required_alignment - align_bytes;
	}

	sym = prv_symbol_new(key_dup, st->allocated, id_type, sub_type, size,
			     false, no_rc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	prv_ensure_symbol_level(st, level, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;
	st->levels[level].symbols[st->levels[level].size++] = sym;

	(void)subtilis_hashtable_insert(st->h, key_dup, sym, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	st->allocated += sym->size;
	if (st->allocated > st->max_allocated)
		st->max_allocated = st->allocated;

	return sym;

on_error:
	free(key_dup);
	prv_symbol_delete(sym);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbp
movq 0x300(%rdi), %rdi
callq 0x2deed
movq %rax, %r15
testq %rax, %rax
jne 0x2e594
movq %rbp, 0x8(%rsp)
movq 0x58(%rsp), %rbp
movq %r14, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
movq %rax, %r15
testq %rax, %rax
je 0x2e4a6
movq %r15, %rdi
movq %r14, %rsi
callq 0x12070
testq %rbx, %rbx
je 0x2e4ca
movq %r13, %rdi
movq %rbp, %rsi
callq 0x35dbe
cmpl $0x0, (%rbp)
je 0x2e4db
movq %r15, %r14
jmp 0x2e4c2
movq %r15, %r14
leaq 0x45e22(%rip), %rdx     # 0x742d2
movq %rbp, %rdi
movl $0x1, %esi
movl $0xb7, %ecx
callq 0x145a4
xorl %r15d, %r15d
jmp 0x2e581
movq %rbx, %r8
movq 0x8(%rsp), %rbx
movq 0x308(%rbx), %rsi
jmp 0x2e50a
movq %rax, %rdi
movq 0x8(%rsp), %r9
movq 0x308(%r9), %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
je 0x2e504
addq %rdi, %rsi
subq %rdx, %rsi
movq %rsi, 0x308(%r9)
movq %rbx, %r8
movq %r9, %rbx
movb 0x50(%rsp), %al
movzbl %al, %eax
movq %r15, %r14
movq %r15, %rdi
movq %r13, %rdx
movq %r12, %rcx
xorl %r9d, %r9d
pushq %rbp
pushq %rax
callq 0x2ea57
addq $0x10, %rsp
movq %rax, %r15
cmpl $0x0, (%rbp)
jne 0x2e581
movq %rbx, %rdi
movq 0x10(%rsp), %r12
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2eb5b
cmpl $0x0, (%rbp)
jne 0x2e581
leaq (%r12,%r12,2), %rax
movq (%rbx,%rax,8), %rcx
movq 0x10(%rbx,%rax,8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx,%rax,8)
movq %r15, (%rdx,%rcx,8)
movq 0x300(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x2df38
cmpl $0x0, (%rbp)
je 0x2e5a6
movq %r14, %rdi
callq 0x122c0
movq %r15, %rdi
callq 0x2e29a
xorl %r15d, %r15d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x308(%rbx), %rax
addq 0x2a0(%r15), %rax
movq %rax, 0x308(%rbx)
cmpq 0x310(%rbx), %rax
jbe 0x2e594
movq %rax, 0x310(%rbx)
jmp 0x2e594