// File: /workspace/github_c_makefile_star2_O1/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 0x6205
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 0x6324
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x6251
jne 0x620c
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25a4
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2d88
testl %eax, %eax
js 0x6216
jne 0x61e2
testb $0x10, 0x5c(%rsp)
je 0x621f
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x25d0
testl %eax, %eax
js 0x623c
leaq 0x78(%rsp), %rsi
leaq 0xc0(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
movl $0x300, %ecx            # imm = 0x300
callq 0x2ee5
testl %eax, %eax
js 0x6245
movq %r14, 0x8(%rsp)
movq 0x8(%rsp), %rdx
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2fd3
movl %eax, %edi
xorl %eax, %eax
testl %edi, %edi
jns 0x6251
callq 0x16e2
jmp 0x624c
callq 0x177a
jmp 0x624c
movq %r15, %rdi
callq 0x16bb
jmp 0x624c
movl %eax, %edi
callq 0x1754
jmp 0x624c
movq 0x4dd2(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x1ae8(%rip), %rsi      # 0x7d18
movq %r14, %rdx
xorl %eax, %eax
callq 0x1140
jmp 0x624c
movl %eax, %edi
callq 0x172e
jmp 0x624c
movl %eax, %edi
callq 0x1708
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbx
popq %r14
popq %r15
retq