// File: /workspace/github_c_makefile_star2_O1/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 $0x438, %rsp            # imm = 0x438
movq %rsi, %r14
movq %rdi, %r15
callq 0x1040
movq %rax, %rbx
movl $0x0, (%rax)
movq (%r15), %rdi
leaq 0xd5b(%rip), %rsi       # 0x2005
callq 0x1090
testq %rax, %rax
je 0x1374
movq %rax, %r12
movq %rbx, (%rsp)
leaq 0x30(%rsp), %rbx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movq %rax, %rcx
callq 0x1050
leaq 0x8(%rsp), %r13
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r13, %rdx
movl $0x209, %ecx            # imm = 0x209
callq 0x10d0
movslq (%r13), %rax
movq %rax, 0x30(%r15)
leaq 0xc(%rsp), %rbp
movslq (%rbp), %rax
movq %rax, 0x28(%r15)
cmpl $0x1, 0x4(%rbp)
movw $0x4, %ax
sbbw $0x0, %ax
movw %ax, 0x38(%r15)
movq %r12, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x10c0
movq %r12, %rdi
callq 0x1080
movq %rax, %rbx
movq %rax, %rdi
callq 0x10b0
movq %rax, %r13
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10c0
movl $0x1, %esi
movq %r13, %rdi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x1050
movq %r12, %rdi
callq 0x1060
cmpl $0x0, 0x4(%rbp)
jne 0x137b
movq 0x2c5e(%rip), %rax      # 0x3fd0
jmp 0x1382
movl (%rbx), %eax
jmp 0x1410
movq 0x2c56(%rip), %rax      # 0x3fd8
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x8(%rsp), %rdx
movq %rbp, %rcx
callq *%rax
movq %rax, %rbx
movq %r13, %rdi
callq 0x1030
movq 0x28(%r15), %rdi
shlq $0x3, %rdi
callq 0x10b0
movq %rax, 0x40(%r15)
cmpq $0x0, 0x28(%r15)
je 0x1402
movzwl 0x38(%r15), %r13d
imulq 0x30(%r15), %r13
xorl %ebp, %ebp
movq %rbx, %r12
movq %r13, %rdi
callq 0x10b0
movq 0x40(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x10a0
testq %r14, %r14
je 0x13f6
movq 0x28(%r15), %rsi
movq %rbp, %rdi
callq *%r14
incq %rbp
addq %r13, %r12
cmpq 0x28(%r15), %rbp
jb 0x13c4
movq %rbx, %rdi
callq 0x1030
movq (%rsp), %rax
movl (%rax), %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq