// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %r15
leaq 0x8ab(%rip), %rdx       # 0x35cd
leaq 0x18(%rsp), %rsi
xorl %ecx, %ecx
callq 0x2270
leaq 0x24bb(%rip), %rsi      # 0x51f0
leaq 0x20(%rsp), %rdi
movl $0xa, %ecx
rep  movsq (%rsi), %es:(%rdi)
testl %eax, %eax
je 0x2e88
movl %eax, %ebx
movl %eax, %r13d
jle 0x2ec2
movl %ebx, 0xc(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
cmpb $0x2e, (%r15)
jne 0x2d7c
cmpb $0x2f, 0x1(%r15)
jne 0x2d7c
cmpb $0x0, 0x2(%r15)
je 0x2e3e
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %rdi
addq $0x13, %rdi
movq %rdi, 0x10(%rsp)
movl $0x1, %esi
callq 0x2200
movq %rax, %r12
cmpb $0x2e, (%r15)
jne 0x2db9
cmpb $0x2f, 0x1(%r15)
jne 0x2db9
cmpb $0x0, 0x2(%r15)
jne 0x2db9
movq 0x10(%rsp), %rdi
callq 0x2050
testq %r12, %r12
je 0x2e6b
movq %r12, %rdi
leaq 0x23db(%rip), %rsi      # 0x51a7
callq 0x2300
testq %rax, %rax
je 0x2e72
movq %rax, %rcx
xorl %eax, %eax
callq *%rcx
movq %rax, %rbx
testq %r14, %r14
je 0x2df8
movq (%r14), %rdi
callq *0x8(%rbx)
testb %al, %al
je 0x2e25
jmp 0x2eef
movq (%rbx), %rsi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2320
movq %rbx, %rdi
callq 0x2100
movw $0x20, 0x20(%rsp,%rax)
movq %rbx, %rdi
callq 0x2100
cmpq $0x49, %rax
jae 0x2e7c
movq %r12, %rdi
callq 0x23a0
xorl %r12d, %r12d
incq %rbp
cmpq %rbp, %r13
jne 0x2d5b
jmp 0x2eb4
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %rcx
addq $0x13, %rcx
leaq 0x10(%rsp), %rdi
leaq 0x234b(%rip), %rsi      # 0x51a2
movq %r15, %rdx
xorl %eax, %eax
callq 0x22a0
movq 0x10(%rsp), %rdi
jmp 0x2d8e
callq 0x2451
jmp 0x2e2d
movq %r12, %rdi
callq 0x2417
jmp 0x2e30
leaq 0x20(%rsp), %rdi
callq 0x23e0
jmp 0x2e25
cmpb $0x2e, (%r15)
jne 0x2ea0
cmpb $0x2f, 0x1(%r15)
jne 0x2ea0
cmpb $0x0, 0x2(%r15)
je 0x2f3d
leaq 0x22ce(%rip), %rdi      # 0x5175
movq %r14, %rsi
callq 0x2d07
movq %rax, %r12
jmp 0x2f2b
cmpb $0x0, 0x20(%rsp)
sete %al
movl 0xc(%rsp), %ebx
jmp 0x2ec7
xorl %eax, %eax
xorl %r12d, %r12d
testq %r14, %r14
jne 0x2f05
testb %al, %al
jne 0x2f05
movq 0x5121(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x2460(%rip), %rsi      # 0x5341
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2210
jmp 0x2f05
movups 0x10(%rbx), %xmm0
movups %xmm0, 0x8(%r14)
movups 0x20(%rbx), %xmm0
movups %xmm0, 0x18(%r14)
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
jle 0x2f21
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
incq %rbx
cmpq %rbx, %r13
jne 0x2f0b
movq 0x18(%rsp), %rdi
callq 0x2050
movq %r12, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2477
xorl %r12d, %r12d
jmp 0x2f2b