// File: /workspace/github_c_makefile_star2_O3/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 0x9d77
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x10b0
movq %rax, %r15
incl %eax
movslq %eax, %rdi
callq 0x1190
testq %rax, %rax
je 0x9c40
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x1080
movl $0x1, (%rbx)
testl %r15d, %r15d
jle 0x9c69
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x1, %ebp
xorl %eax, %eax
leaq (%r14,%rax), %rdx
movq %r15, %rsi
subq %rax, %rsi
xorl %ecx, %ecx
cmpb $0x7e, (%rdx,%rcx)
je 0x9c21
incq %rcx
cmpq %rcx, %rsi
jne 0x9c11
jmp 0x9c64
testl %ecx, %ecx
je 0x9c69
incl %ebp
movl %ebp, (%rbx)
leaq (%rax,%rcx), %rdx
incq %rdx
notq %rax
addq %r15, %rax
cmpq %rcx, %rax
movq %rdx, %rax
jne 0x9c05
jmp 0x9c69
leaq 0x95f5(%rip), %rsi      # 0x1323c
leaq 0x9eef(%rip), %rdx      # 0x13b3d
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x156, %ecx            # imm = 0x156
xorl %eax, %eax
callq 0xa278
jmp 0x9c90
cmpl $0x1, %ecx
jne 0x9ca2
leaq 0x9ef5(%rip), %rsi      # 0x13b65
xorl %r15d, %r15d
movl $0x6, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0xa278
movq %r14, %rdi
callq 0x1040
movl $0x0, (%rbx)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %esi
shlq $0x3, %rsi
movl $0x1, %edi
callq 0x1150
testq %rax, %rax
je 0x9d32
movq %rax, %r15
xorl %eax, %eax
xorl %r12d, %r12d
cmpl $0x2, %ebp
jb 0x9d11
xorl %r13d, %r13d
movslq %r13d, %r13
leal 0x1(%r13), %ebp
movzbl 0x1(%r14,%r13), %ecx
incq %r13
incl %ebp
cmpl $0x7e, %ecx
je 0x9ce2
testl %ecx, %ecx
jne 0x9cce
movb $0x0, (%r14,%r13)
movslq %eax, %rdi
addq %r14, %rdi
callq 0x98ac
movq %rax, (%r15,%r12,8)
testq %rax, %rax
je 0x9d59
incq %r12
movslq (%rbx), %rcx
decq %rcx
movl %ebp, %eax
cmpq %rcx, %r12
jl 0x9cc7
movslq %ebp, %rax
movl %r12d, %r12d
movq %r14, %rdi
addq %rax, %rdi
callq 0x98ac
movq %rax, (%r15,%r12,8)
testq %rax, %rax
je 0x9d59
movq %r14, %rdi
callq 0x1040
jmp 0x9c90
leaq 0x9503(%rip), %rsi      # 0x1323c
leaq 0x9dfd(%rip), %rdx      # 0x13b3d
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x17a, %ecx            # imm = 0x17A
xorl %eax, %eax
callq 0xa278
jmp 0x9c82
movq %r14, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x1040
movl $0x0, (%rbx)
xorl %r15d, %r15d
jmp 0x9c90
callq 0x1060