// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r15
movq %rdi, %r14
callq 0x1050
movq %rax, %rbp
andl $0x0, (%rax)
movq (%r14), %rdi
leaq 0x2cf0(%rip), %rsi      # 0x4005
callq 0x10f0
testq %rax, %rax
je 0x1479
movq %rax, %r12
xorps %xmm0, %xmm0
movq %rsp, %r13
movaps %xmm0, (%r13)
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x10c0
movq %rax, %rdx
movq 0x48(%r14), %rax
movzbl 0x10(%rax), %ebx
andl $0x1, %ebx
movl %ebx, %ecx
xorl $0x1, %ecx
movzbl 0x11(%rax), %r8d
andl $0x1, %r8d
movq %r12, %rdi
movq %r13, %rsi
movq %rdx, 0x20(%rsp)
callq 0x1030
testb %al, %al
je 0x1471
movq %rbp, 0x18(%rsp)
movq (%rsp), %rbp
testb %bl, %bl
je 0x1383
addq $-0x8, %rbp
jmp 0x139d
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)
pushq $0x8
popq %rdi
callq 0x1110
movq %rax, %r13
movq %rax, 0x40(%r14)
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
callq 0x1110
movq %rax, (%r13)
cmpq $0x0, 0x8(%rsp)
je 0x1455
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rbx
jae 0x144e
movb (%rdi,%rbx), %al
shrb $0x5, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, (%rcx,%r13)
movq 0x8(%rsp), %rax
movb (%rax,%rbx), %al
shrb $0x3, %al
andb $0x3, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, 0x1(%rcx,%r13)
movq 0x8(%rsp), %rax
movb (%rax,%rbx), %al
andb $0x7, %al
movq 0x40(%r14), %rcx
movq (%rcx), %rcx
movb %al, 0x2(%rcx,%r13)
testq %r15, %r15
je 0x143d
movq 0x30(%r14), %rsi
movq %r13, %rdi
callq *%r15
movzwl 0x38(%r14), %eax
addq %rax, %r13
incq %rbx
movq (%rsp), %rbp
jmp 0x13e4
callq 0x1040
jmp 0x1463
testq %r15, %r15
je 0x1463
movq %rbp, %rdi
movq %rbp, %rsi
callq *%r15
movq 0x20(%rsp), %rax
movq %rax, 0x48(%r14)
movq 0x18(%rsp), %rbp
movq %r12, %rdi
callq 0x1070
movl (%rbp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq