// File: /workspace/github_c_makefile_star2_O3/dlbeer[P]ufat/main.c
// Function: cmd_move
static int cmd_move(struct ufat *uf, const struct options *opt)
{
	struct ufat_directory dir;
	struct ufat_dirent src_ent;
	struct ufat_dirent dst_ent;
	int err;
	const char *src_path;
	const char *dst_path;
	const char *new_name;
	char old_name[UFAT_LFN_MAX_UTF8];

	if (opt->argc < 2) {
		fprintf(stderr, "You must specified a source path and "
			"a destination path.\n");
		return -1;
	}

	src_path = opt->argv[0];
	dst_path = opt->argv[1];

	err = find_path(uf, &dir, src_path, &src_ent, NULL);
	if (err < 0)
		return -1;

	if (err) {
		fprintf(stderr, "No such file or directory: %s\n",
			opt->argv[0]);
		return -1;
	}

	ufat_open_root(uf, &dir);
	err = ufat_dir_find_path(&dir, dst_path, &dst_ent, &new_name);

	if (err < 0) {
		fprintf(stderr, "ufat_dir_find_path: %s\n",
			ufat_strerror(err));
		return -1;
	}

	if (!err) {
		/* Is the destination a directory or an existing file? */
		if (!(dst_ent.attributes & UFAT_ATTR_DIRECTORY)) {
			fprintf(stderr, "File already exists: %s\n",
				dst_path);
			return -1;
		}

		/* It's a directory name. Use the old canonical filename. */
		err = ufat_open_subdir(uf, &dir, &dst_ent);
		if (err < 0) {
			fprintf(stderr, "ufat_open_subdir: %s\n",
				ufat_strerror(err));
			return -1;
		}

		err = ufat_get_filename(uf, &src_ent,
					old_name, sizeof(old_name));
		if (err < 0) {
			fprintf(stderr, "ufat_get_filename: %s\n",
				ufat_strerror(err));
			return -1;
		}

		new_name = old_name;
	}

	err = ufat_move(&src_ent, &dir, new_name);
	if (err < 0) {
		fprintf(stderr, "ufat_move: %s\n", ufat_strerror(err));
		return -1;
	}

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x3c0, %rsp            # imm = 0x3C0
cmpl $0x1, 0x40(%rsi)
jle 0x6103
movq %rsi, %r15
movq %rdi, %rbx
movq 0x38(%rsi), %rax
addq $0x38, %r15
movq (%rax), %rdx
movq 0x8(%rax), %r14
leaq 0x10(%rsp), %rsi
leaq 0x78(%rsp), %rcx
xorl %r8d, %r8d
callq 0x6222
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x614f
jne 0x610a
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x24e0
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2c3f
testl %eax, %eax
js 0x6114
je 0x609f
movq 0x8(%rsp), %r14
jmp 0x60e2
testb $0x10, 0x5c(%rsp)
je 0x611d
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x250c
testl %eax, %eax
js 0x613a
leaq 0x78(%rsp), %rsi
leaq 0xc0(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
movl $0x300, %ecx            # imm = 0x300
callq 0x2d27
testl %eax, %eax
js 0x6143
movq %r14, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2dea
movl %eax, %edi
xorl %eax, %eax
testl %edi, %edi
jns 0x614f
callq 0x16bc
jmp 0x614a
callq 0x1754
jmp 0x614a
movq %r15, %rdi
callq 0x1695
jmp 0x614a
movl %eax, %edi
callq 0x172e
jmp 0x614a
movq 0x4ed4(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x1bea(%rip), %rsi      # 0x7d18
movq %r14, %rdx
xorl %eax, %eax
callq 0x1140
jmp 0x614a
movl %eax, %edi
callq 0x1708
jmp 0x614a
movl %eax, %edi
callq 0x16e2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbx
popq %r14
popq %r15
retq