// File: /workspace/github_c_makefile_star2_O3/albinoloverats[P]hide/src/hide.c
// Function: main
int main(int argc, char **argv)
{
	if (argc < 2 || argc > 5)
	{
		fprintf(stderr, "Usage: %s [-f] <source image> <file to hide> <output image>\n", argv[0]);
		fprintf(stderr, "       %s [-f] <image> <recovered file>\n", argv[0]);
		fprintf(stderr, "       %s <image>\n", argv[0]);
		find_supported_formats(DIR_LIBRARY, NULL);
		return EXIT_FAILURE;
	}
	else if (argc == 2)
	{
		struct stat s;
		if (stat(argv[1], &s) < 0 && errno == ENOENT)
		{
			fprintf(stderr, "Could not read file %s\n", argv[1]);
			return errno;
		}
		image_info_t image_info = { argv[1], NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL };
#ifndef __DEBUG_JPEG__
		void *so = find_supported_formats(DIR_LIBRARY, &image_info);
		if (!so)
			return errno;
#else
		extern uint64_t info_jpeg(image_info_t *image_info);
		extern void free_jpeg(image_info_t image_info);
		image_info.info = info_jpeg;
		image_info.free = free_jpeg;
#endif
		if (!image_info.info)
		{
			fprintf(stderr, "Unsupported image format\n");
			find_supported_formats(DIR_LIBRARY, NULL);
			errno = EFTYPE;
		}
		else
		{
			setlocale(LC_NUMERIC, "");
			printf("File capacity: %'" PRIu64 " bytes\n", image_info.info(&image_info));
			image_info.free(image_info);
			errno = EXIT_SUCCESS;
		}
#ifndef __DEBUG_JPEG__
		dlclose(so);
#endif
		return errno;
	}

	int o = strcmp(argv[1], "-f") ? 0 : 1;

	hide_files_t files = { argv[o + 1], argv[o + 2], argv[o + 3] };
	process_options_t options = { files, o };

#ifndef __DEBUG__
	{
		cli_status_e ui_status = CLI_INIT;
		cli_progress_s ui_current = { 0, 1, NULL }; /* updated after reading image */
		cli_progress_s ui_total   = { 0, 3, NULL }; /* maximum of 3 steps (read, update, write) */
		ui.status = &ui_status;
		ui.current = &ui_current;
		ui.total = &ui_total;
	}
	/*
	 * TODO start process() in own thread, then call cli_display()
	 *
	 * remember that process() will have to set the status once it's finished
	 */
	pthread_t t;
	pthread_attr_t a;
	pthread_attr_init(&a);
	pthread_attr_setdetachstate(&a, PTHREAD_CREATE_JOINABLE);
	pthread_create(&t, &a, process, &options);
	pthread_attr_destroy(&a);

	cli_display(&ui);

	pthread_join(t, NULL);
#else
	process(&options);
#endif

	return errno;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
movq %rsi, %rbx
leal -0x6(%rdi), %eax
cmpl $-0x5, %eax
jbe 0x357a
cmpl $0x2, %edi
jne 0x3484
movq 0x8(%rbx), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x2120
testl %eax, %eax
jns 0x33dd
callq 0x2060
cmpl $0x2, (%rax)
je 0x35ac
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movups %xmm0, 0x38(%rsi)
movups %xmm0, 0x28(%rsi)
movups %xmm0, 0x18(%rsi)
movups %xmm0, 0x8(%rsi)
movq $0x0, 0x48(%rsi)
movq 0x8(%rbx), %rax
movq %rax, (%rsi)
leaq 0x1bf9(%rip), %rdi      # 0x5004
callq 0x2d07
testq %rax, %rax
je 0x355f
movq %rax, %rbx
cmpq $0x0, 0x88(%rsp)
je 0x359d
leaq 0x1e44(%rip), %rsi      # 0x5276
movl $0x1, %edi
callq 0x22c0
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq *0x18(%r14)
leaq 0x1d0b(%rip), %rdi      # 0x515a
xorl %ebp, %ebp
movq %rax, %rsi
xorl %eax, %eax
callq 0x2140
movl $0xa, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq *0x20(%r14)
callq 0x2060
movq %rax, %r14
movl %ebp, (%rax)
movq %rbx, %rdi
callq 0x23a0
jmp 0x3567
movq 0x8(%rbx), %rax
movl $0x3, %ecx
movl $0x2, %edx
movl $0x1, %esi
cmpb $0x2d, (%rax)
jne 0x34b5
cmpb $0x66, 0x1(%rax)
jne 0x34b5
cmpb $0x0, 0x2(%rax)
sete %al
je 0x3589
leaq 0x8(%rbx), %rsi
jmp 0x34bb
xorl %eax, %eax
leaq (%rbx,%rsi,8), %rsi
movq (%rsi), %rsi
movq (%rbx,%rdx,8), %rdx
movq (%rbx,%rcx,8), %rcx
leaq 0x70(%rsp), %rbx
movq %rsi, (%rbx)
movq %rdx, 0x8(%rbx)
movq %rcx, 0x10(%rbx)
movb %al, 0x18(%rbx)
leaq 0x54(%rsp), %rax
movq %rax, 0x4d23(%rip)      # 0x8208
leaq 0x4d1c(%rip), %r14      # 0x8208
leaq 0xc0(%rsp), %rax
movq %rax, 0x4d15(%rip)      # 0x8210
leaq 0x58(%rsp), %rax
movq %rax, 0x4d11(%rip)      # 0x8218
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x21d0
movq %r15, %rdi
xorl %esi, %esi
callq 0x2230
leaq -0xa9c(%rip), %rdx      # 0x2a8c
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x22e0
movq %r15, %rdi
callq 0x2310
movq %r14, %rdi
callq 0x2528
movq (%r12), %rdi
xorl %esi, %esi
callq 0x2360
callq 0x2060
movl (%rax), %eax
jmp 0x356a
callq 0x2060
movq %rax, %r14
movl (%r14), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x24c9
movl $0x1, %eax
jmp 0x356a
movl $0x4, %ecx
movl $0x3, %edx
movl $0x2, %esi
jmp 0x34b7
callq 0x2499
movl $0x4f, %ebp
jmp 0x346d
movq %rax, %r14
movq 0x4a42(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x8(%rbx), %rdx
leaq 0x1b7e(%rip), %rsi      # 0x5142
xorl %eax, %eax
callq 0x2210
jmp 0x3567