// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x1040
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xd19(%rip), %rsi       # 0x2005
callq 0x1090
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x130b
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x153f
leaq -0x420(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1050
leaq -0x420(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
leaq -0x448(%rbp), %rdx
callq 0x1780
movslq -0x448(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movslq -0x444(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x440(%rbp), %edx
movl $0x3, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x38(%rax)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x10c0
movq -0x20(%rbp), %rdi
callq 0x1080
movq %rax, -0x450(%rbp)
movq -0x450(%rbp), %rdi
callq 0x10b0
movq %rax, -0x458(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
movq -0x458(%rbp), %rdi
movq -0x450(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1050
movq -0x20(%rbp), %rdi
callq 0x1060
movl -0x440(%rbp), %edx
movq 0x2bde(%rip), %rax      # 0x3fd0
movq 0x2bdf(%rip), %rcx      # 0x3fd8
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rax
movq -0x458(%rbp), %rdi
movq -0x450(%rbp), %rsi
leaq -0x448(%rbp), %rdx
leaq -0x448(%rbp), %rcx
addq $0x4, %rcx
callq *%rax
movq %rax, -0x468(%rbp)
movq -0x458(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
shlq $0x3, %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl 0x38(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x450(%rbp)
movq $0x0, -0x470(%rbp)
movq -0x470(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x1529
movq -0x450(%rbp), %rdi
callq 0x10b0
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x470(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x470(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x468(%rbp), %rsi
movq -0x470(%rbp), %rax
imulq -0x450(%rbp), %rax
addq %rax, %rsi
movq -0x450(%rbp), %rdx
callq 0x10a0
cmpq $0x0, -0x18(%rbp)
je 0x1510
movq -0x18(%rbp), %rax
movq -0x470(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rsi
callq *%rax
jmp 0x1512
movq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x470(%rbp)
jmp 0x1485
movq -0x468(%rbp), %rdi
callq 0x1030
callq 0x1040
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
nopl (%rax,%rax)