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

	if (path != NULL && !options->to_stdout) {
		size_t path_nchars, suffix_nchars;

		if (!options->force && has_suffix(path, options->suffix)) {
			msg("%"TS": already has .%"TS" suffix -- skipping",
			    path, options->suffix);
			ret = -2;
			goto out;
		}
		path_nchars = tstrlen(path);
		suffix_nchars = tstrlen(options->suffix);
		newpath = xmalloc((path_nchars + 1 + suffix_nchars + 1) *
					sizeof(tchar));
		tmemcpy(newpath, path, path_nchars);
		newpath[path_nchars] = '.';
		tmemcpy(&newpath[path_nchars + 1], options->suffix,
			suffix_nchars + 1);
	}

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

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

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

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

	ret = write_file_header(&out, options->chunk_size,
				options->compression_level);
	if (ret != 0)
		goto out_close_out;

	ret = do_compress(compressor, &in, &out, options->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 0x1cab
movq 0xf0(%rsp), %rax
testb $0x1, (%rax)
jne 0x1cab
movq 0xf0(%rsp), %rax
testb $0x1, 0x2(%rax)
jne 0x1c07
movq 0xf8(%rsp), %rdi
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x2440
testb $0x1, %al
jne 0x1bd8
jmp 0x1c07
movq 0xf8(%rsp), %rsi
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0xeb0e(%rip), %rdi      # 0x10701
movb $0x0, %al
callq 0x2660
movl $0xfffffffe, 0x24(%rsp) # imm = 0xFFFFFFFE
jmp 0x1ec1
movq 0xf8(%rsp), %rdi
callq 0x1090
movq %rax, 0x18(%rsp)
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1090
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
addq $0x1, %rdi
addq 0x10(%rsp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x2890
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x1140
movq 0xe8(%rsp), %rax
movq 0x18(%rsp), %rcx
movb $0x2e, (%rax,%rcx)
movq 0xe8(%rsp), %rdi
movq 0x18(%rsp), %rax
addq $0x1, %rax
addq %rax, %rdi
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x10(%rsp), %rdx
addq $0x1, %rdx
callq 0x1140
movq 0xf8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2970
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1cd0
jmp 0x1eb4
movq 0xf0(%rsp), %rcx
movb $0x1, %al
testb $0x1, 0x2(%rcx)
movb %al, 0xf(%rsp)
jne 0x1cf4
cmpq $0x0, 0xe8(%rsp)
sete %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
movzbl %al, %edx
andl $0x1, %edx
leaq 0xd0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1f40
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1d20
jmp 0x1e6d
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, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1d55
jmp 0x1e6d
movq 0xf0(%rsp), %rax
testb $0x1, 0x2(%rax)
jne 0x1d8f
movl 0xb8(%rsp), %edi
callq 0x1070
cmpl $0x0, %eax
je 0x1d8f
leaq 0xe9ad(%rip), %rdi      # 0x10728
movb $0x0, %al
callq 0x2660
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x1e2c
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %esi
movq 0xf0(%rsp), %rax
movl 0x4(%rax), %edx
leaq 0xb8(%rsp), %rdi
callq 0x2470
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1dbf
jmp 0x1e2c
movq 0x100(%rsp), %rdi
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0xd0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x24d0
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1df4
jmp 0x1e2c
cmpq $0x0, 0xf8(%rsp)
je 0x1e24
cmpq $0x0, 0xe8(%rsp)
je 0x1e24
movq 0xe8(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x22b0
movl $0x0, 0x24(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x2fd0
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x24(%rsp)
jne 0x1e4c
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1e6b
cmpq $0x0, 0xe8(%rsp)
je 0x1e6b
movq 0xe8(%rsp), %rdi
callq 0x1060
jmp 0x1e6d
leaq 0xd0(%rsp), %rdi
callq 0x2fd0
cmpl $0x0, 0x24(%rsp)
jne 0x1eb2
cmpq $0x0, 0xf8(%rsp)
je 0x1eb2
cmpq $0x0, 0xe8(%rsp)
je 0x1eb2
movq 0xf0(%rsp), %rax
testb $0x1, 0x3(%rax)
jne 0x1eb2
movq 0xf8(%rsp), %rdi
callq 0x1060
jmp 0x1eb4
movq 0xe8(%rsp), %rdi
callq 0x1040
movl 0x24(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax)