// File: /workspace/github_c_makefile_star2_O0/albinoloverats[P]hide/src/bmp.c
// Function: read_bmp
static int read_bmp(image_info_t *image_info, void (*progress_update)(uint64_t, uint64_t))
{
	errno = EXIT_SUCCESS;

	FILE *bmp = fopen(image_info->file, "rb");
	if (!bmp)
		return errno;

	fseek(bmp, 0x12, SEEK_SET);
	uint32_t dword;
	fread(&dword, sizeof dword, 1, bmp);
	image_info->width = from_little_endian_32(dword);
	fread(&dword, sizeof dword, 1, bmp);
	image_info->height = from_little_endian_32(dword);

	fseek(bmp, 0x1C, SEEK_SET);
	uint16_t word;
	fread(&word, sizeof word, 1, bmp);
	switch (from_little_endian_16(word))
	{
		case 32:
			image_info->bpp = 4;
			break;
		case 24:
			image_info->bpp = 3;
			break;
		default:
			errno = ENOTSUP;
			goto done;
	}
	fread(&dword, sizeof dword, 1, bmp);
	if (dword != BI_RGB)
	{
		errno = ENOTSUP;
		goto done;
	}

	bmp_extra_t *extra = malloc(sizeof (bmp_extra_t));
	fseek(bmp, 0x0A, SEEK_SET);
	fread(&extra->size, sizeof extra->size, 1, bmp);
	extra->size = from_little_endian_32(extra->size);
	extra->data = malloc(extra->size);
	fseek(bmp, 0x00, SEEK_SET);
	fread(extra->data, extra->size, 1, bmp);
	image_info->extra = extra;

	uint32_t padding = image_info->width % 4;
	if (padding == 4)
		padding = 0;

	image_info->buffer = malloc(sizeof (uint8_t *) * image_info->height);
	fseek(bmp, extra->size, SEEK_SET);
	for (uint64_t y = 0; y < image_info->height; y++)
	{
		image_info->buffer[y] = malloc(image_info->width * image_info->bpp);
		fread(image_info->buffer[y], image_info->width, image_info->bpp, bmp);
		uint32_t ignored = 0x00;
		if (padding)
			fread(&ignored, padding, 1, bmp);
		if (progress_update)
			progress_update(y, image_info->height);
	}

done:
	fclose(bmp);

	return errno;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x1040
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xd4b(%rip), %rsi       # 0x2004
callq 0x1070
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12d8
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x15bf
movq -0x20(%rbp), %rdi
movl $0x12, %esi
xorl %edx, %edx
movl %edx, -0x54(%rbp)
callq 0x1090
movq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %rdi
movq %rdi, -0x68(%rbp)
movl $0x4, %esi
movq %rsi, -0x60(%rbp)
movl $0x1, %edx
movq %rdx, -0x50(%rbp)
callq 0x1050
movl -0x24(%rbp), %edi
callq 0x1820
movl %eax, %edi
callq 0x10c0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rcx
callq 0x1050
movl -0x24(%rbp), %edi
callq 0x1820
movl %eax, %edi
callq 0x10c0
movl -0x54(%rbp), %edx
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rdi
movl $0x1c, %esi
callq 0x1090
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x26(%rbp), %rdi
movl $0x2, %esi
callq 0x1050
movzwl -0x26(%rbp), %edi
callq 0x1860
movzwl %ax, %edi
callq 0x10a0
movzwl %ax, %ecx
movl %ecx, -0x48(%rbp)
subw $0x18, %ax
je 0x13b5
jmp 0x139f
movl -0x48(%rbp), %eax
subl $0x20, %eax
jne 0x13c1
jmp 0x13a9
movq -0x10(%rbp), %rax
movw $0x4, 0x38(%rax)
jmp 0x13d1
movq -0x10(%rbp), %rax
movw $0x3, 0x38(%rax)
jmp 0x13d1
callq 0x1040
movl $0x5f, (%rax)
jmp 0x15ac
movq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x1050
cmpl $0x0, -0x24(%rbp)
je 0x13fe
callq 0x1040
movl $0x5f, (%rax)
jmp 0x15ac
movl $0x10, %edi
callq 0x1080
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movl $0xa, %esi
xorl %edx, %edx
callq 0x1090
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x1050
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x1820
movl %eax, %edi
callq 0x10c0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x1080
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1090
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
movq -0x20(%rbp), %rcx
movl $0x1, %edx
callq 0x1050
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
andq $0x3, %rax
movl %eax, -0x34(%rbp)
cmpl $0x4, -0x34(%rbp)
jne 0x14ba
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
shlq $0x3, %rdi
callq 0x1080
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1090
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x15aa
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %eax
imulq %rax, %rdi
callq 0x1080
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %eax
movl %eax, %edx
movq -0x20(%rbp), %rcx
callq 0x1050
movl $0x0, -0x44(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x157e
movl -0x34(%rbp), %eax
movl %eax, %esi
movq -0x20(%rbp), %rcx
leaq -0x44(%rbp), %rdi
movl $0x1, %edx
callq 0x1050
cmpq $0x0, -0x18(%rbp)
je 0x1597
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rsi
callq *%rax
jmp 0x1599
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x14f1
jmp 0x15ac
movq -0x20(%rbp), %rdi
callq 0x1060
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)