// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x37f5
cmpl $0x5, -0x8(%rbp)
jle 0x386e
movq 0x47fc(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x28bc(%rip), %rsi      # 0x60c9
movb $0x0, %al
callq 0x2200
movq 0x47dd(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x28da(%rip), %rsi      # 0x6106
movb $0x0, %al
callq 0x2200
movq 0x47be(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x28e4(%rip), %rsi      # 0x612f
movb $0x0, %al
callq 0x2200
leaq 0x27ab(%rip), %rdi      # 0x6004
xorl %eax, %eax
movl %eax, %esi
callq 0x2830
movl $0x1, -0x4(%rbp)
jmp 0x3ba2
cmpl $0x2, -0x8(%rbp)
jne 0x39f5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2120
cmpl $0x0, %eax
jge 0x38ca
callq 0x2060
cmpl $0x2, (%rax)
jne 0x38ca
movq 0x4756(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x288e(%rip), %rsi      # 0x6142
movb $0x0, %al
callq 0x2200
callq 0x2060
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ba2
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x2170
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq 0x2711(%rip), %rdi      # 0x6004
leaq -0xf0(%rbp), %rsi
callq 0x2830
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0xf8(%rbp)
jne 0x391f
callq 0x2060
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ba2
cmpq $0x0, -0xd8(%rbp)
jne 0x395e
movq 0x46c8(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x26d4(%rip), %rsi      # 0x600e
movb $0x0, %al
callq 0x2200
leaq 0x26bc(%rip), %rdi      # 0x6004
xorl %eax, %eax
movl %eax, %esi
callq 0x2830
callq 0x2060
movl $0x4f, (%rax)
jmp 0x39da
movl $0x1, %edi
leaq 0x293c(%rip), %rsi      # 0x62a6
callq 0x22c0
leaq -0xf0(%rbp), %rdi
callq *-0xd8(%rbp)
movq %rax, %rsi
leaq 0x27d4(%rip), %rdi      # 0x615a
movb $0x0, %al
callq 0x2140
movq -0xd0(%rbp), %rax
movups -0xb0(%rbp), %xmm0
movq %rsp, %rcx
movups %xmm0, 0x40(%rcx)
movups -0xf0(%rbp), %xmm0
movups -0xe0(%rbp), %xmm1
movups -0xd0(%rbp), %xmm2
movups -0xc0(%rbp), %xmm3
movups %xmm3, 0x30(%rcx)
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
callq *%rax
callq 0x2060
movl $0x0, (%rax)
movq -0xf8(%rbp), %rdi
callq 0x2390
callq 0x2060
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ba2
jmp 0x39f7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x276f(%rip), %rsi      # 0x6175
callq 0x21d0
movl %eax, %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0xfc(%rbp)
movq -0x10(%rbp), %rax
movl -0xfc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rax
movl -0xfc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rax
movl -0xfc(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x108(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpl $0x0, -0xfc(%rbp)
setne %al
andb $0x1, %al
movb %al, -0x120(%rbp)
movl $0x1, -0x13c(%rbp)
movq 0x2732(%rip), %rax      # 0x61f0
movq %rax, -0x158(%rbp)
movq 0x272c(%rip), %rax      # 0x61f8
movq %rax, -0x150(%rbp)
movq 0x2726(%rip), %rax      # 0x6200
movq %rax, -0x148(%rbp)
movq 0x2720(%rip), %rax      # 0x6208
movq %rax, -0x170(%rbp)
movq 0x271a(%rip), %rax      # 0x6210
movq %rax, -0x168(%rbp)
movq 0x2714(%rip), %rax      # 0x6218
movq %rax, -0x160(%rbp)
leaq -0x13c(%rbp), %rax
movq %rax, 0x46df(%rip)      # 0x81f8
leaq -0x158(%rbp), %rax
movq %rax, 0x46d9(%rip)      # 0x8200
leaq -0x170(%rbp), %rax
movq %rax, 0x46d3(%rip)      # 0x8208
leaq -0x1b0(%rbp), %rdi
callq 0x21b0
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
callq 0x2220
leaq -0x178(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x16b4(%rip), %rdx     # 0x24b0
leaq -0x138(%rbp), %rcx
callq 0x22e0
leaq -0x1b0(%rbp), %rdi
callq 0x2310
leaq 0x4675(%rip), %rdi      # 0x81f8
callq 0x4ad0
movq -0x178(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2350
callq 0x2060
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nop