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

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

	uint8_t header[1024];
	fread(header, 1, sizeof header, fp);

	WebPBitstreamFeatures feat;
	WebPGetFeatures(header, sizeof header, &feat);

	image_info->width = feat.width;
	image_info->height = feat.height;
	image_info->bpp = feat.has_alpha ? 4 : 3;

	fseek(fp, 0, SEEK_END);
	uint64_t l = ftell(fp);
	uint8_t *raw = malloc(l);
	fseek(fp, 0, SEEK_SET);

	fread(raw, 1, l, fp);
	fclose(fp);

	uint8_t *(*webpdecode)(const uint8_t *, size_t, int *, int *) = feat.has_alpha ? WebPDecodeRGBA : WebPDecodeRGB;
	uint8_t *img = webpdecode(raw, l, &feat.width, &feat.height);
	free(raw);

	image_info->buffer = malloc(sizeof (uint8_t *) * image_info->height);
	l = image_info->width * image_info->bpp;
	for (uint64_t y = 0; y < image_info->height; y++)
	{
		image_info->buffer[y] = malloc(l);
		memcpy(image_info->buffer[y], img + y * l, l);
		if (progress_update)
			progress_update(y, image_info->height);
	}
	free(img);

	return errno;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rsi, %r14
movq %rdi, %r15
callq 0x1040
movq %rax, %rbx
andl $0x0, (%rax)
movq (%r15), %rdi
leaq 0xd60(%rip), %rsi       # 0x2005
callq 0x1090
testq %rax, %rax
je 0x1371
movq %rax, %r13
movq %rbx, 0x10(%rsp)
leaq 0x40(%rsp), %rbx
pushq $0x1
popq %rsi
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movq %rax, %rcx
callq 0x1050
leaq 0x18(%rsp), %r12
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r12, %rdx
movl $0x209, %ecx            # imm = 0x209
callq 0x10d0
movslq (%r12), %rax
movq %rax, 0x30(%r15)
leaq 0x1c(%rsp), %rcx
movslq (%rcx), %rax
movq %rax, 0x28(%r15)
cmpl $0x1, 0x4(%rcx)
movw $0x4, %ax
sbbw $0x0, %ax
movw %ax, 0x38(%r15)
xorl %r12d, %r12d
pushq $0x2
popq %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x10c0
movq %r13, %rdi
callq 0x1080
movq %rax, %rbx
movq %rax, %rdi
callq 0x10b0
movq %rax, %rbp
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10c0
movq %rbp, %rdi
pushq $0x1
popq %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x1050
movq %r13, %rdi
callq 0x1060
leaq 0x1c(%rsp), %rcx
cmpl $0x0, 0x4(%rcx)
jne 0x1378
movq 0x2c61(%rip), %rax      # 0x3fd0
jmp 0x137f
movl (%rbx), %eax
jmp 0x140f
movq 0x2c59(%rip), %rax      # 0x3fd8
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x18(%rsp), %rdx
callq *%rax
movq %rax, %r13
movq %rbp, %rdi
callq 0x1030
movq 0x28(%r15), %rbx
leaq (,%rbx,8), %rdi
callq 0x10b0
movq %rax, 0x40(%r15)
movzwl 0x38(%r15), %ebp
imulq 0x30(%r15), %rbp
movq %r13, 0x8(%rsp)
cmpq %rbx, %r12
jae 0x13fe
movq %rbp, %rdi
callq 0x10b0
movq 0x40(%r15), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x40(%r15), %rax
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10a0
testq %r14, %r14
je 0x13f2
movq 0x28(%r15), %rsi
movq %r12, %rdi
callq *%r14
incq %r12
movq 0x28(%r15), %rbx
addq %rbp, %r13
jmp 0x13bb
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x10(%rsp), %rax
movl (%rax), %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq