// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x1050
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x5cbc(%rip), %rsi      # 0x7005
callq 0x1100
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1368
callq 0x1050
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x16d0
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
movl $0x1, %edi
movl $0x10, %esi
callq 0x10d0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
movb -0x40(%rbp), %dl
movl $0x1, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl -0x54(%rbp), %ecx
movb -0x3f(%rbp), %al
leaq -0x30(%rbp), %rsi
andb $0x1, %al
movzbl %al, %r8d
callq 0x1030
testb $0x1, %al
jne 0x13e3
jmp 0x16bd
cmpl $0x1, -0x54(%rbp)
jne 0x153e
movabsq $-0x100000000000000, %rax # imm = 0xFF00000000000000
andq -0x30(%rbp), %rax
shrq $0x38, %rax
movabsq $0xff000000000000, %rcx # imm = 0xFF000000000000
andq -0x30(%rbp), %rcx
shrq $0x28, %rcx
orq %rcx, %rax
movabsq $0xff0000000000, %rcx   # imm = 0xFF0000000000
andq -0x30(%rbp), %rcx
shrq $0x18, %rcx
orq %rcx, %rax
movabsq $0xff00000000, %rcx     # imm = 0xFF00000000
andq -0x30(%rbp), %rcx
shrq $0x8, %rcx
orq %rcx, %rax
movabsq $0xff000000, %rcx       # imm = 0xFF000000
andq -0x30(%rbp), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff0000, %rcx         # imm = 0xFF0000
shlq $0x18, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff00, %rcx           # imm = 0xFF00
shlq $0x28, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff, %rcx
shlq $0x38, %rcx
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movabsq $-0x100000000000000, %rax # imm = 0xFF00000000000000
andq -0x30(%rbp), %rax
shrq $0x38, %rax
movabsq $0xff000000000000, %rcx # imm = 0xFF000000000000
andq -0x30(%rbp), %rcx
shrq $0x28, %rcx
orq %rcx, %rax
movabsq $0xff0000000000, %rcx   # imm = 0xFF0000000000
andq -0x30(%rbp), %rcx
shrq $0x18, %rcx
orq %rcx, %rax
movabsq $0xff00000000, %rcx     # imm = 0xFF00000000
andq -0x30(%rbp), %rcx
shrq $0x8, %rcx
orq %rcx, %rax
movabsq $0xff000000, %rcx       # imm = 0xFF000000
andq -0x30(%rbp), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff0000, %rcx         # imm = 0xFF0000
shlq $0x18, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff00, %rcx           # imm = 0xFF00
shlq $0x28, %rcx
orq %rcx, %rax
movq -0x30(%rbp), %rcx
andq $0xff, %rcx
shlq $0x38, %rcx
orq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
jmp 0x154a
movq -0x30(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movw $0x3, 0x38(%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq $0x1, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
shlq $0x3, %rdi
callq 0x1120
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %eax
imulq %rax, %rdi
callq 0x1120
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0x1692
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x1687
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0xe0, %eax
sarl $0x5, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0x18, %eax
sarl $0x3, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0x7, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx)
cmpq $0x0, -0x18(%rbp)
je 0x1664
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rsi
callq *%rax
jmp 0x1666
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %eax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x15ca
movq -0x28(%rbp), %rdi
callq 0x1040
jmp 0x16b1
cmpq $0x0, -0x18(%rbp)
je 0x16af
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rsi
callq *%rax
jmp 0x16b1
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x20(%rbp), %rdi
callq 0x1070
callq 0x1050
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)