// File: /workspace/github_c_makefile_star2_O2/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 0x8e28
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 0x8cf9
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x1080
movl $0x1, (%rbx)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
pushq $0x1
popq %rbp
xorl %ecx, %ecx
cmpq %rax, %r15
je 0x8d1a
cmpb $0x7e, (%r14,%rax)
jne 0x8cf2
testl %ecx, %ecx
jle 0x8d1f
incl %ebp
movl %ebp, (%rbx)
xorl %ecx, %ecx
jmp 0x8cf4
incl %ecx
incq %rax
jmp 0x8cda
leaq 0x853c(%rip), %rsi      # 0x1123c
leaq 0x8da6(%rip), %rdx      # 0x11aad
xorl %ebp, %ebp
pushq $0x7
popq %rdi
movl $0x156, %ecx            # imm = 0x156
xorl %eax, %eax
callq 0x9174
jmp 0x8d40
cmpl $0x1, %ecx
jg 0x8d52
leaq 0x8daf(%rip), %rsi      # 0x11ad5
xorl %ebp, %ebp
pushq $0x6
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9174
movq %r14, %rdi
callq 0x1040
andl $0x0, (%rbx)
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebp, %rsi
shlq $0x3, %rsi
pushq $0x1
popq %rdi
callq 0x1150
movq %rax, (%rsp)
testq %rax, %rax
je 0x8dbe
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
decl %ebp
movslq %ebp, %rax
movslq %r15d, %rdi
cmpq %rax, %r12
jge 0x8de2
movslq %r13d, %r13
leal 0x1(%r13), %r15d
movq (%rsp), %rbp
movzbl 0x1(%r14,%r13), %eax
incq %r13
incl %r15d
cmpl $0x7e, %eax
je 0x8da0
testl %eax, %eax
jne 0x8d8b
movb $0x0, (%r14,%r13)
addq %r14, %rdi
callq 0x8a6d
movq %rax, (%rbp,%r12,8)
testq %rax, %rax
je 0x8e0e
incq %r12
movl (%rbx), %ebp
jmp 0x8d73
leaq 0x8477(%rip), %rsi      # 0x1123c
leaq 0x8ce1(%rip), %rdx      # 0x11aad
xorl %ebp, %ebp
pushq $0x7
popq %rdi
movl $0x17a, %ecx            # imm = 0x17A
xorl %eax, %eax
callq 0x9174
jmp 0x8d35
movq %r14, %rax
addq %rdi, %rax
movq %rax, %rdi
callq 0x8a6d
movl %r12d, %ecx
movq (%rsp), %rbp
movq %rax, (%rbp,%rcx,8)
testq %rax, %rax
je 0x8e0e
movq %r14, %rdi
callq 0x1040
jmp 0x8d40
movq %r14, %rdi
callq 0x1040
movq %rbp, %rdi
callq 0x1040
andl $0x0, (%rbx)
xorl %ebp, %ebp
jmp 0x8d40
callq 0x1060