// File: /workspace/github_c_makefile_star2_O1/albinoloverats[P]hide/src/hide.c
// Function: find_supported_formats
static void *find_supported_formats(char *path, image_info_t *image_info)
{
	void *so = NULL;
	struct dirent **eps;
	int n = scandir(path, &eps, selector, NULL);
	char buffer[80] = "Supported image formats: ";
	if (n == 0)
	{
		if (strcmp(path, DIR_LOCAL))
			return find_supported_formats(DIR_LOCAL, image_info);
		fprintf(stderr, "Could not find any hide image libraries!\n");
		return NULL;
	}
	for (int i = 0; i < n; ++i)
	{
		char *l = NULL;
		if (strcmp(path, DIR_LOCAL))
			l = eps[i]->d_name;
		else
			asprintf(&l, "%s%s", path, eps[i]->d_name);
		so = dlopen(l, RTLD_LAZY);
		if (!strcmp(path, DIR_LOCAL))
			free(l);
		if (so == NULL)
		{
			fprintf(stderr, "%s\n", dlerror());
			continue;
		}
		image_type_t *(*init)();
		if (!(init = dlsym(so, "init")))
		{
			fprintf(stderr, "%s\n", dlerror());
			dlclose(so);
			continue;
		}
		image_type_t *format = init();
		if (!image_info)
		{
			strcat(buffer, format->type);
			strcat(buffer, " ");
			if (strlen(buffer) > 72)
			{
				fprintf(stderr, "%s\n", buffer);
				memset(buffer, 0x00, sizeof buffer);
			}
		}
		else if (format->is_type(image_info->file))
		{
			image_info->read = format->read;
			image_info->write = format->write;
			image_info->info = format->info;
			image_info->free = format->free;
			break;
		}
		dlclose(so);
		so = NULL;
	}
	if (!image_info && strlen(buffer))
		fprintf(stderr, "%s\n", buffer);

	for (int i = 0; i < n; ++i)
		free(eps[i]);
	free(eps);

	return so;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, (%rsp)
movq %rdi, %r14
leaq 0x876(%rip), %rdx       # 0x35dc
leaq 0x10(%rsp), %rsi
xorl %ecx, %ecx
callq 0x2280
leaq 0x24a7(%rip), %rsi      # 0x5220
leaq 0x20(%rsp), %rdi
movl $0xa, %ecx
rep  movsq (%rsi), %es:(%rdi)
testl %eax, %eax
je 0x2efe
movl %eax, 0x1c(%rsp)
movl %eax, %ebp
jle 0x2f2a
leaq 0x23d7(%rip), %r13      # 0x5178
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x21f0
movq 0x10(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
addq $0x13, %rcx
testl %eax, %eax
je 0x2dd0
movq %rcx, 0x8(%rsp)
jmp 0x2de6
leaq 0x8(%rsp), %rdi
leaq 0x23c9(%rip), %rsi      # 0x51a5
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0x2210
movq %rax, %r15
movq %r14, %rdi
movq %r13, %rsi
callq 0x21f0
testl %eax, %eax
jne 0x2e11
movq 0x8(%rsp), %rdi
callq 0x2050
testq %r15, %r15
je 0x2ed4
movq %r15, %rdi
leaq 0x2386(%rip), %rsi      # 0x51aa
callq 0x2310
testq %rax, %rax
je 0x2ee3
movq %rax, %rcx
movq %rbp, %rbx
movq %r13, %rbp
xorl %eax, %eax
callq *%rcx
movq %rax, %r13
movq (%rsp), %rax
testq %rax, %rax
je 0x2e81
movq (%rax), %rdi
callq *0x8(%r13)
testb %al, %al
je 0x2eaf
movq 0x10(%r13), %rax
movq (%rsp), %rcx
movq %rax, 0x8(%rcx)
movq 0x18(%r13), %rax
movq %rax, 0x10(%rcx)
movq 0x20(%r13), %rax
movq %rax, 0x18(%rcx)
movq 0x28(%r13), %rax
movq %rax, 0x20(%rcx)
movl $0x2, %eax
jmp 0x2ebc
movq (%r13), %rsi
leaq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x2330
movq %r13, %rdi
callq 0x2100
movw $0x20, 0x20(%rsp,%rax)
movq %r13, %rdi
callq 0x2100
cmpq $0x49, %rax
jae 0x2ef2
movq %r15, %rdi
callq 0x23b0
xorl %eax, %eax
xorl %r15d, %r15d
movq %rbp, %r13
movq %rbx, %rbp
testb $0x3, %al
jne 0x2f2d
incq %r12
cmpq %r12, %rbp
jne 0x2da4
jmp 0x2f2d
callq 0x2461
movl $0x4, %eax
xorl %r15d, %r15d
jmp 0x2ec2
movq %r15, %rdi
callq 0x2427
movl $0x4, %eax
jmp 0x2ec2
leaq 0x20(%rsp), %rdi
callq 0x23f0
jmp 0x2eaf
leaq 0x2273(%rip), %rsi      # 0x5178
movq %r14, %rdi
callq 0x21f0
testl %eax, %eax
je 0x2f95
leaq 0x225c(%rip), %rdi      # 0x5178
movq (%rsp), %rsi
callq 0x2d4a
movq %rax, %r15
jmp 0x2f64
xorl %r15d, %r15d
cmpq $0x0, (%rsp)
jne 0x2f3b
cmpb $0x0, 0x20(%rsp)
jne 0x2f76
cmpl $0x0, 0x1c(%rsp)
jle 0x2f5a
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
incq %rbx
cmpq %rbx, %rbp
jne 0x2f44
movq 0x10(%rsp), %rdi
callq 0x2050
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x507b(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x23ea(%rip), %rsi      # 0x5371
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2220
jmp 0x2f3b
callq 0x2487
xorl %r15d, %r15d
jmp 0x2f64