// File: /workspace/github_c_makefile_star2_O3/albinoloverats[P]hide/src/jpeg.c
// Function: read_jpeg
static int read_jpeg(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;

	jpeg_message_t msg = { 0x00, NULL };
	jpeg_image_t *image = calloc(1, sizeof (jpeg_image_t));
	data_info_t extra = *(data_info_t *)image_info->extra;
	jpeg_load_e action = extra.hide ? JPEG_LOAD_READ : JPEG_LOAD_FIND;

	if (!jpeg_decode_data(fp, &msg, image, action, extra.fill))
		goto clean_up;

	if (action == JPEG_LOAD_FIND)
	{
		msg.size = htonll(msg.size);
		memcpy(msg.data, &msg.size, sizeof msg.size);
		msg.size = ntohll(msg.size) + sizeof msg.size;
	}
	else
		msg.size -= sizeof msg.size; /* available capacity */

	image_info->bpp = 3;
	image_info->width = msg.size;
	image_info->height = 1;
	image_info->buffer = malloc(sizeof (uint8_t *) * image_info->height);
	image_info->buffer[0] = malloc(image_info->width * image_info->bpp);
	/* (if necessary) copy message.data into image_info->buffer */
	if (msg.data)
	{
		for (uint64_t x = 0, i = 0; i < msg.size; x += image_info->bpp, i++)
		{
			image_info->buffer[0][x + 0] = (msg.data[i] & 0xE0) >> 5;
			image_info->buffer[0][x + 1] = (msg.data[i] & 0x18) >> 3;
			image_info->buffer[0][x + 2] = (msg.data[i] & 0x07);
			if (progress_update)
				progress_update(x, image_info->width);
		}
		free(msg.data);
	}
	else if (progress_update)
		progress_update(image_info->width, image_info->width);

	/* store the image data where we can get it back later */
	image_info->extra = image;

clean_up:
	fclose(fp);
	return errno;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %r14
callq 0x1050
movq %rax, %rbx
movl $0x0, (%rax)
movq (%r14), %rdi
leaq 0x3ae1(%rip), %rsi      # 0x5005
callq 0x10f0
testq %rax, %rax
je 0x168e
movq %rax, %r15
xorps %xmm0, %xmm0
movq %rsp, %rbp
movaps %xmm0, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x10c0
movq %rax, %rdx
movq 0x48(%r14), %rax
movzbl 0x10(%rax), %r13d
andl $0x1, %r13d
movl %r13d, %ecx
xorl $0x1, %ecx
movzbl 0x11(%rax), %r8d
andl $0x1, %r8d
movq %r15, %rdi
movq %rbp, %rsi
movq %rdx, 0x10(%rsp)
callq 0x1030
testb %al, %al
je 0x1686
movq (%rsp), %rbp
testb %r13b, %r13b
je 0x1594
addq $-0x8, %rbp
jmp 0x15ae
bswapq %rbp
movq %rbp, (%rsp)
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
movq (%rsp), %rbp
bswapq %rbp
addq $0x8, %rbp
movq %rbp, (%rsp)
movw $0x3, 0x38(%r14)
movq %rbp, 0x30(%r14)
movq $0x1, 0x28(%r14)
movl $0x8, %edi
callq 0x1110
movq %rax, %r13
movq %rax, 0x40(%r14)
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
callq 0x1110
movq %rax, (%r13)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x166f
testq %rbp, %rbp
je 0x1668
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
movb (%rax,%r13), %al
shrb $0x5, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, (%rcx,%rbp)
movq 0x8(%rsp), %rax
movb (%rax,%r13), %al
shrb $0x3, %al
andb $0x3, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, 0x1(%rcx,%rbp)
movq 0x8(%rsp), %rax
movb (%rax,%r13), %al
andb $0x7, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, 0x2(%rcx,%rbp)
testq %r12, %r12
je 0x1652
movq 0x30(%r14), %rsi
movq %rbp, %rdi
callq *%r12
movzwl 0x38(%r14), %eax
addq %rax, %rbp
incq %r13
cmpq (%rsp), %r13
jb 0x15fe
movq 0x8(%rsp), %rdi
callq 0x1040
jmp 0x167d
testq %r12, %r12
je 0x167d
movq %rbp, %rdi
movq %rbp, %rsi
callq *%r12
movq 0x10(%rsp), %rax
movq %rax, 0x48(%r14)
movq %r15, %rdi
callq 0x1070
movl (%rbx), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq