#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__ access(char *, int /*<<< orphan*/);
scalar_t__ copyfile(char *, char *);
scalar_t__ rename(char *, char *);
scalar_t__ unlink(char *);
int move(char *oldname, char *newname) {
  if (access(newname, 0) == 0)
    return 1;
  if (rename(oldname, newname) == 0)
    return 0;
  if (copyfile(oldname, newname))
    return 1;
  if (unlink(oldname)) {
    if (access(oldname, 0))
      return 0;
    unlink(newname);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1171 <move+0x31>
movl   $0x1,-0x4(%rbp)
jmp    1207 <move+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <rename@plt>
cmp    $0x0,%rax
jne    1194 <move+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1207 <move+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <copyfile@plt>
cmp    $0x0,%rax
je     11b7 <move+0x77>
movl   $0x1,-0x4(%rbp)
jmp    1207 <move+0xc7>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1200 <move+0xc0>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <access@plt>
cmp    $0x0,%rax
je     11eb <move+0xab>
movl   $0x0,-0x4(%rbp)
jmp    1207 <move+0xc7>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <move+0xc7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <access@plt>
test   %rax,%rax
je     117b <move+0x3b>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <rename@plt>
test   %rax,%rax
je     1180 <move+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <copyfile@plt>
test   %rax,%rax
je     1187 <move+0x47>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1180 <move+0x40>
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <access@plt>
test   %rax,%rax
jne    1180 <move+0x40>
mov    %rbx,%rdi
call   1030 <unlink@plt>
jmp    117b <move+0x3b>

LLVM IR (-O0):
define i32 @move(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** %5
%7 = call i64 @access(i8* %6, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %35
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i64 @rename(i8* %11, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 0, i32* %3
br label %35
16: ; preds = %10
%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 %35
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i64 @unlink(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i64 @access(i8* %27, i32 0)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %3
br label %35
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = call i64 @unlink(i8* %32)
store i32 1, i32* %3
br label %35
34: ; preds = %22
store i32 0, i32* %3
br label %35
35: ; preds = %34, %31, %30, %21, %15, %9
%36 = load i32, i32* %3
ret i32 %36
}

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