#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__ EXDEV;
scalar_t__ copyfile(char const *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ rename(char const *, char const *);
int unlink(char const *);
int movefile(const char *src, const char *dest) {
  if (!rename(src, dest))
    return 0;
  if (errno != EXDEV)
    return -1;
  if (copyfile(src, dest))
    return -1;
  return unlink(src);
}


x86 assembly (clang, -O0):
<movefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <rename@plt>
cmp    $0x0,%eax
jne    1162 <movefile+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <movefile+0x87>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
je     1188 <movefile+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <movefile+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <copyfile@plt>
cmp    $0x0,%rax
je     11ab <movefile+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <movefile+0x87>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<movefile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1040 <rename@plt>
test   %eax,%eax
je     117b <movefile+0x4b>
mov    0x2e8e(%rip),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
mov    $0xffffffff,%r14d
cmp    (%rcx),%rax
jne    117e <movefile+0x4e>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <copyfile@plt>
test   %rax,%rax
jne    117e <movefile+0x4e>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <unlink@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EXDEV = global i64 0
define i32 @movefile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = load i8*, i8** %5
%8 = call i32 @rename(i8* %6, i8* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %25
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EXDEV
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %3
br label %25
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i64 @copyfile(i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %3
br label %25
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i32 @unlink(i8* %23)
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %21, %15, %10
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@errno = global i64 0
@EXDEV = global i64 0
define i32 @movefile(i8* %0, i8* %1) {
%3 = tail call i32 @rename(i8* %0, i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EXDEV
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = tail call i64 @copyfile(i8* %0, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @unlink(i8* %0)
br label %14
14: ; preds = %9, %5, %2, %12
%15 = phi i32 [ %13, %12 ], [ 0, %2 ], [ -1, %5 ], [ -1, %9 ]
ret i32 %15
}