// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]xpack/programs/xpack.c
// Function: decompress_file
static int
decompress_file(struct xpack_decompressor *decompressor, const tchar *path,
		const struct options *options)
{
	tchar *newpath = NULL;
	struct file_stream in;
	struct file_stream out;
	struct xpack_file_header hdr;
	struct stat stbuf;
	int ret;
	int ret2;

	if (path != NULL && !options->to_stdout) {
		const tchar *suffix = get_suffix(path, options->suffix);
		if (suffix == NULL) {
			msg("\"%"TS"\" does not end with the .%"TS" suffix -- "
			    "skipping", path, options->suffix);
			ret = -2;
			goto out;
		}
		newpath = xmalloc((suffix - path + 1) * sizeof(tchar));
		tmemcpy(newpath, path, suffix - path);
		newpath[suffix - path] = '\0';
	}

	ret = xopen_for_read(path, &in);
	if (ret != 0)
		goto out_free_newpath;

	if (!options->force && isatty(in.fd)) {
		msg("Refusing to read compressed data from terminal.  "
		    "Use -f to override.\nFor help, use -h.");
		ret = -1;
		goto out_close_in;
	}

	ret = stat_file(&in, &stbuf, options->force || newpath == NULL);
	if (ret != 0)
		goto out_close_in;

	ret = xread(&in, &hdr, sizeof(hdr));
	if (ret < 0)
		goto out_close_in;
	if (ret != sizeof(hdr)) {
		msg("%"TS": not in XPACK format", in.name);
		ret = -1;
		goto out_close_in;
	}
	bswap_file_header(&hdr);

	if (memcmp(hdr.magic, XPACK_MAGIC, sizeof(hdr.magic)) != 0) {
		msg("%"TS": not in XPACK format", in.name);
		ret = -1;
		goto out_close_in;
	}

	if (hdr.version != 1) {
		msg("%"TS": unsupported version (%d)", in.name, hdr.version);
		ret = -1;
		goto out_close_in;
	}

	if (hdr.header_size < sizeof(hdr)) {
		msg("%"TS": incorrect header size (%"PRIu16")", in.name,
		    hdr.header_size);
		ret = -1;
		goto out_close_in;
	}

	if (hdr.chunk_size < 1024 || hdr.chunk_size > 67108864) {
		msg("%"TS": unsupported chunk size (%"PRIu32")", in.name,
		    hdr.chunk_size);
		ret = -1;
		goto out_close_in;
	}

	ret = skip_bytes(&in, hdr.header_size - sizeof(hdr));
	if (ret != 0)
		goto out_close_in;

	ret = xopen_for_write(newpath, options->force, &out);
	if (ret != 0)
		goto out_close_in;

	ret = do_decompress(decompressor, &in, &out, hdr.chunk_size);
	if (ret != 0)
		goto out_close_out;

	if (path != NULL && newpath != NULL)
		restore_metadata(&out, newpath, &stbuf);
	ret = 0;
out_close_out:
	ret2 = xclose(&out);
	if (ret == 0)
		ret = ret2;
	if (ret != 0 && newpath != NULL)
		tunlink(newpath);
out_close_in:
	xclose(&in);
	if (ret == 0 && path != NULL && newpath != NULL && !options->keep)
		tunlink(path);
out_free_newpath:
	free(newpath);
out:
	return ret;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movq $0x0, 0xe8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x17e6
movq 0xf0(%rsp), %rax
testb $0x1, (%rax)
jne 0x17e6
movq 0xf8(%rsp), %rdi
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1ed0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x1780
movq 0xf8(%rsp), %rsi
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0xed68(%rip), %rdi      # 0x104d4
movb $0x0, %al
callq 0x2660
movl $0xfffffffe, 0x14(%rsp) # imm = 0xFFFFFFFE
jmp 0x1b53
movq 0x8(%rsp), %rdi
movq 0xf8(%rsp), %rax
subq %rax, %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x2890
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0xf8(%rsp), %rax
subq %rax, %rdx
callq 0x1140
movq 0xe8(%rsp), %rax
movq 0x8(%rsp), %rcx
movq 0xf8(%rsp), %rdx
subq %rdx, %rcx
movb $0x0, (%rax,%rcx)
movq 0xf8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2970
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x180b
jmp 0x1b46
movq 0xf0(%rsp), %rax
testb $0x1, 0x2(%rax)
jne 0x1845
movl 0xd0(%rsp), %edi
callq 0x1070
cmpl $0x0, %eax
je 0x1845
leaq 0xecd5(%rip), %rdi      # 0x10506
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
movq 0xf0(%rsp), %rcx
movb $0x1, %al
testb $0x1, 0x2(%rcx)
movb %al, 0x7(%rsp)
jne 0x1869
cmpq $0x0, 0xe8(%rsp)
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
movzbl %al, %edx
andl $0x1, %edx
leaq 0xd0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1f40
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1895
jmp 0x1aff
leaq 0xd0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl $0x10, %edx
callq 0x2cb0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jge 0x18bf
jmp 0x1aff
movslq 0x14(%rsp), %rax
cmpq $0x10, %rax
je 0x18ed
movq 0xd8(%rsp), %rsi
leaq 0xec84(%rip), %rdi      # 0x1055d
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
leaq 0xa8(%rsp), %rdi
callq 0x2040
leaq 0xa8(%rsp), %rax
movq (%rax), %rax
movabsq $0x4b43415058, %rcx     # imm = 0x4B43415058
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x1940
movq 0xd8(%rsp), %rsi
leaq 0xec31(%rip), %rdi      # 0x1055d
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
movzbl 0xb6(%rsp), %eax
cmpl $0x1, %eax
je 0x1978
movq 0xd8(%rsp), %rsi
movzbl 0xb6(%rsp), %edx
leaq 0xec11(%rip), %rdi      # 0x10575
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
movzwl 0xb4(%rsp), %eax
cmpq $0x10, %rax
jae 0x19b1
movq 0xd8(%rsp), %rsi
movzwl 0xb4(%rsp), %edx
leaq 0xebf5(%rip), %rdi      # 0x10592
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
cmpl $0x400, 0xb0(%rsp) # imm = 0x400
jb 0x19cb
cmpl $0x4000000, 0xb0(%rsp) # imm = 0x4000000
jbe 0x19f5
movq 0xd8(%rsp), %rsi
movl 0xb0(%rsp), %edx
leaq 0xebd0(%rip), %rdi      # 0x105b1
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
jmp 0x1aff
movzwl 0xb4(%rsp), %eax
movl %eax, %esi
subq $0x10, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x2db0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1a20
jmp 0x1aff
movq 0xe8(%rsp), %rdi
movq 0xf0(%rsp), %rax
movb 0x2(%rax), %al
leaq 0xb8(%rsp), %rdx
andb $0x1, %al
movzbl %al, %esi
callq 0x2b00
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1a55
jmp 0x1aff
movq 0x100(%rsp), %rdi
movl 0xb0(%rsp), %ecx
leaq 0xd0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x2070
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1a86
jmp 0x1abe
cmpq $0x0, 0xf8(%rsp)
je 0x1ab6
cmpq $0x0, 0xe8(%rsp)
je 0x1ab6
movq 0xe8(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x22b0
movl $0x0, 0x14(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x2fd0
movl %eax, 0x10(%rsp)
cmpl $0x0, 0x14(%rsp)
jne 0x1ade
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x1afd
cmpq $0x0, 0xe8(%rsp)
je 0x1afd
movq 0xe8(%rsp), %rdi
callq 0x1060
jmp 0x1aff
leaq 0xd0(%rsp), %rdi
callq 0x2fd0
cmpl $0x0, 0x14(%rsp)
jne 0x1b44
cmpq $0x0, 0xf8(%rsp)
je 0x1b44
cmpq $0x0, 0xe8(%rsp)
je 0x1b44
movq 0xf0(%rsp), %rax
testb $0x1, 0x3(%rax)
jne 0x1b44
movq 0xf8(%rsp), %rdi
callq 0x1060
jmp 0x1b46
movq 0xe8(%rsp), %rdi
callq 0x1040
movl 0x14(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nop