// File: /workspace/github_c_makefile_star2_O1/MikeGray-APH[P]LibLouisAPH/source/lookup.c
// Function: lookup_tables
struct table** lookup_tables(int *table_cnt, const char *table_names)
{
	struct table **tables;
	char *names;
	int names_len, len, off, crs, i;

	ASSERT(table_names)

	/*   parse table_names   */
	names_len = strlen(table_names);
	names = MALLOC(names_len + 1);
	LOG_ALLOCATE_FAIL_RETURN_NULL(names)
	strcpy(names, table_names);

	*table_cnt = 1;
	len = 0;
	for(i = 0; i < names_len; i++)
	if(names[i] == '~')
	{
		/*   ~ at the beginning or ~~ found   */
		if(len < 1)
		{
			log_message(LOG_ERROR, "invalid table list %s\n", table_names);
			FREE(names);
			*table_cnt = 0;
			return NULL;
		}
		(*table_cnt)++;
		len = 0;
	}
	else
		len++;

	/*   just the terminating NULL character,
	     ~ at the end   */
	if(len < 2)
	{
		log_message(LOG_ERROR, "invalid table list %s\n", table_names);
		FREE(names);
		*table_cnt = 0;
		return NULL;
	}

	/*   setup tables array   */
	tables = MALLOC(*table_cnt * sizeof(struct table*));
	if(!tables)
	{
		LOG_ALLOCATE_FAIL
		FREE(names);
		*table_cnt = 0;
		return NULL;
	}
	memset(tables, 0, *table_cnt * sizeof(struct table*));

	i =
	off =
	crs = 0;

	/*   more than one table in list   */
	while(i < *table_cnt - 1)
	{
		crs++;
		while(names[crs] != 0 && names[crs] != '~')
			crs++;
		names[crs] = 0;
		tables[i] = lookup_table(&names[off]);
		if(!tables[i])
			goto return_fail;
		off = crs + 1;
		i++;
	}
	tables[i] = lookup_table(&names[off]);
	if(!tables[i])
		goto return_fail;

	FREE(names);
	return tables;

	return_fail:
	FREE(names);
	FREE(tables);
	*table_cnt = 0;
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x9e7b
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x10b0
movq %rax, %r15
incl %eax
movslq %eax, %rdi
callq 0x1180
testq %rax, %rax
je 0x9d49
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x1080
movl $0x1, (%rbx)
testl %r15d, %r15d
jle 0x9d20
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %eax, %eax
xorl %ecx, %ecx
cmpb $0x7e, (%r14,%rax)
jne 0x9d11
testl %ecx, %ecx
jle 0x9d20
incl (%rbx)
xorl %ecx, %ecx
jmp 0x9d13
incl %ecx
incq %rax
cmpq %rax, %r15
jne 0x9d00
cmpl $0x1, %ecx
jg 0x9d7d
leaq 0x9d6e(%rip), %rsi      # 0x13a95
xorl %r15d, %r15d
movl $0x6, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0xa36c
movq %r14, %rdi
callq 0x1040
movl $0x0, (%rbx)
jmp 0x9d6b
leaq 0x94a4(%rip), %rsi      # 0x131f4
leaq 0x9d16(%rip), %rdx      # 0x13a6d
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x156, %ecx            # imm = 0x156
xorl %eax, %eax
callq 0xa36c
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq (%rbx), %r12
shlq $0x3, %r12
movq %r12, %rdi
callq 0x1180
testq %rax, %rax
je 0x9e0c
movq %rax, %rbp
xorl %r13d, %r13d
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1110
cmpl $0x2, (%rbx)
movq %rbp, (%rsp)
jl 0x9e33
xorl %r12d, %r12d
xorl %ebp, %ebp
movslq %ebp, %rbp
leal 0x1(%rbp), %r15d
movzbl 0x1(%r14,%rbp), %eax
incq %rbp
incl %r15d
cmpl $0x7e, %eax
je 0x9dd2
testl %eax, %eax
jne 0x9dbd
movb $0x0, (%r14,%rbp)
movslq %r13d, %rdi
addq %r14, %rdi
callq 0x99af
movq (%rsp), %rcx
movq %rax, (%rcx,%r12,8)
testq %rax, %rax
je 0x9e5c
incq %r12
movslq (%rbx), %rax
decq %rax
movl %r15d, %r13d
cmpq %rax, %r12
jl 0x9db6
movslq %r15d, %r13
movl %r12d, %r15d
movq (%rsp), %rbp
jmp 0x9e36
leaq 0x93e1(%rip), %rsi      # 0x131f4
leaq 0x9c53(%rip), %rdx      # 0x13a6d
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x17a, %ecx            # imm = 0x17A
xorl %eax, %eax
callq 0xa36c
jmp 0x9d39
xorl %r15d, %r15d
movq %r14, %rdi
addq %r13, %rdi
callq 0x99af
movq %rax, (%rbp,%r15,8)
testq %rax, %rax
je 0x9e5c
movq %r14, %rdi
callq 0x1040
movq (%rsp), %r15
jmp 0x9d6b
movq %r14, %rdi
callq 0x1040
movq (%rsp), %rdi
callq 0x1040
movl $0x0, (%rbx)
xorl %r15d, %r15d
jmp 0x9d6b
callq 0x1060