// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
cmpl $0x1, 0x40(%rsi)
jle 0x5945
movq %rsi, %r15
movq %rdi, %rbx
movq 0x38(%rsi), %rax
movq (%rax), %rdx
movq 0x8(%rax), %r14
leaq 0x10(%rsp), %rsi
leaq 0x78(%rsp), %rcx
xorl %r8d, %r8d
callq 0x5b06
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x59f2
jne 0x5969
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e58
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x250c
testl %eax, %eax
js 0x5983
je 0x58bd
movq 0x8(%rsp), %r14
jmp 0x590c
testb $0x10, 0x5c(%rsp)
je 0x599d
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x1e81
testl %eax, %eax
js 0x59b3
leaq 0x78(%rsp), %rsi
leaq 0xc0(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
movl $0x300, %ecx            # imm = 0x300
callq 0x25f3
testl %eax, %eax
js 0x59cd
movq %r14, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x26b3
movl %eax, %edi
xorl %eax, %eax
testl %edi, %edi
jns 0x59f4
movq 0x46c7(%rip), %rax      # 0x9ff8
movq (%rax), %rbx
callq 0x1a87
leaq 0x13f1(%rip), %rsi      # 0x6d31
jmp 0x59e5
movq 0x46ac(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x1388(%rip), %rdi      # 0x6cde
pushq $0x39
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
pushq $-0x1
popq %rax
jmp 0x59f4
movq 0x4688(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq 0x38(%r15), %rax
movq (%rax), %rdx
leaq 0xf91(%rip), %rsi       # 0x6912
jmp 0x59eb
movq 0x466e(%rip), %rcx      # 0x9ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x1a87
leaq 0xf96(%rip), %rsi       # 0x6931
jmp 0x59e5
movq 0x4654(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x136a(%rip), %rsi      # 0x6d18
movq %r14, %rdx
jmp 0x59eb
movq 0x463e(%rip), %rcx      # 0x9ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x1a87
leaq 0xf31(%rip), %rsi       # 0x68fc
jmp 0x59e5
movq 0x4624(%rip), %rcx      # 0x9ff8
movq (%rcx), %rbx
movl %eax, %edi
callq 0x1a87
leaq 0xfd7(%rip), %rsi       # 0x69bc
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1140
movl %ebp, %eax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq