// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xed6c
callq 0x1050
movq -0x18(%rbp), %rdi
callq 0x10a0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xedbd
movl $0x7, %edi
leaq 0xf4db(%rip), %rsi      # 0x1e278
leaq 0xfe59(%rip), %rdx      # 0x1ebfd
movl $0x156, %ecx            # imm = 0x156
movb $0x0, %al
callq 0xf610
movq $0x0, -0x8(%rbp)
jmp 0xf03a
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1070
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xee62
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
jne 0xee4c
cmpl $0x1, -0x30(%rbp)
jge 0xee38
movq -0x18(%rbp), %rdx
movl $0x6, %edi
leaq 0xfe16(%rip), %rsi      # 0x1ec27
movb $0x0, %al
callq 0xf610
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xf03a
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x30(%rbp)
jmp 0xee55
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xee57
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xede2
cmpl $0x2, -0x30(%rbp)
jge 0xee9f
movq -0x18(%rbp), %rdx
movl $0x6, %edi
leaq 0xfdaf(%rip), %rsi      # 0x1ec27
movb $0x0, %al
callq 0xf610
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xf03a
movq -0x10(%rbp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
callq 0x1160
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xeef9
movl $0x7, %edi
leaq 0xf3b2(%rip), %rsi      # 0x1e278
leaq 0xfd30(%rip), %rdx      # 0x1ebfd
movl $0x17a, %ecx            # imm = 0x17A
movb $0x0, %al
callq 0xf610
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0xf03a
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq (%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1100
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xefd3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3d(%rbp)
je 0xef6c
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
setne %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0xef75
jmp 0xef80
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xef41
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
callq 0xe9f0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0xefbc
jmp 0xf016
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xef24
movq -0x28(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
callq 0xe9f0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0xf003
jmp 0xf016
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf03a
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x20(%rbp), %rdi
callq 0x1040
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)