#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ fsop_cpdir(char const *, char const *, size_t);
scalar_t__ fsop_path_exists(char const *);
scalar_t__ fsop_rmdir(char const *);
int /*<<< orphan*/ rename(char const *, char const *);
scalar_t__ rmdir(char const *);
int fsop_mvdir(const char *src, const char *dest, size_t block) {
  if (!rename(src, dest))
    return 0;
  if (fsop_path_exists(dest)) {
    if (rmdir(dest) < 0)
      return -1;
  }
  if (fsop_cpdir(src, dest, block) < 0)
    return -1;
  if (fsop_rmdir(src) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<fsop_mvdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <rename@plt>
cmp    $0x0,%eax
jne    1186 <fsop_mvdir+0x36>
movl   $0x0,-0x4(%rbp)
jmp    120a <fsop_mvdir+0xba>
mov    -0x18(%rbp),%rdi
call   1050 <fsop_path_exists@plt>
cmp    $0x0,%rax
je     11bd <fsop_mvdir+0x6d>
mov    -0x18(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    11b8 <fsop_mvdir+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <fsop_mvdir+0xba>
jmp    11bd <fsop_mvdir+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <fsop_cpdir@plt>
cmp    $0x0,%rax
jge    11e4 <fsop_mvdir+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <fsop_mvdir+0xba>
mov    -0x10(%rbp),%rdi
call   1030 <fsop_rmdir@plt>
cmp    $0x0,%rax
jge    1203 <fsop_mvdir+0xb3>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <fsop_mvdir+0xba>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsop_mvdir>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1070 <rename@plt>
test   %eax,%eax
je     11a2 <fsop_mvdir+0x52>
mov    %rbx,%rdi
call   1050 <fsop_path_exists@plt>
test   %rax,%rax
je     1181 <fsop_mvdir+0x31>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
test   %rax,%rax
js     11a6 <fsop_mvdir+0x56>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <fsop_cpdir@plt>
test   %rax,%rax
js     11a6 <fsop_mvdir+0x56>
mov    %r15,%rdi
call   1030 <fsop_rmdir@plt>
sar    $0x3f,%rax
jmp    11ab <fsop_mvdir+0x5b>
xor    %eax,%eax
jmp    11ab <fsop_mvdir+0x5b>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @fsop_mvdir(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i8*, i8** %5
%9 = load i8*, i8** %6
%10 = call i32 @rename(i8* %8, i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 0, i32* %4
br label %36
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i64 @fsop_path_exists(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = call i64 @rmdir(i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %36
22: ; preds = %17
br label %23
23: ; preds = %22, %13
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = load i64, i64* %7
%27 = call i64 @fsop_cpdir(i8* %24, i8* %25, i64 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -1, i32* %4
br label %36
30: ; preds = %23
%31 = load i8*, i8** %5
%32 = call i64 @fsop_rmdir(i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %4
br label %36
35: ; preds = %30
store i32 0, i32* %4
br label %36
36: ; preds = %35, %34, %29, %21, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @fsop_mvdir(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @rename(i8* %0, i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i64 @fsop_path_exists(i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @rmdir(i8* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %9, %6
%13 = tail call i64 @fsop_cpdir(i8* %0, i8* %1, i64 %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i64 @fsop_rmdir(i8* %0)
%17 = ashr i64 %16, 63
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %15, %12, %9, %3
%20 = phi i32 [ 0, %3 ], [ -1, %9 ], [ -1, %12 ], [ %18, %15 ]
ret i32 %20
}