#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 */
int /*<<< orphan*/ lprintf(int, char *, char *, char *, int /*<<< orphan*/);
int p_CopyFile(char *, char *);
int p_DeleteFile(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ system_error();
int p_MoveFile(char *source, char *dest) {
  int i;
  if (rename(source, dest)) {
    if (!(i = p_CopyFile(source, dest))) {
      lprintf(2, "Can't copy %s tp %s : %s\n", source, dest, system_error());
      return 0;
    } else
      return p_DeleteFile(source);
  } else
    return 1;
}


x86 assembly (clang, -O0):
<p_MoveFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <rename@plt>
cmp    $0x0,%rax
je     11e0 <p_MoveFile+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <p_CopyFile@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11cf <p_MoveFile+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <system_error@plt>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %eax,%r8d
mov    $0x2,%edi
lea    0xe42(%rip),%rsi
call   1070 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <p_MoveFile+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <p_DeleteFile@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <p_MoveFile+0x97>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_MoveFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <rename@plt>
test   %rax,%rax
je     117f <p_MoveFile+0x2f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <p_CopyFile@plt>
test   %eax,%eax
je     1186 <p_MoveFile+0x36>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <p_DeleteFile@plt>
mov    $0x1,%ebp
jmp    11a9 <p_MoveFile+0x59>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <system_error@plt>
lea    0xe6a(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
call   1070 <lprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Can't copy %s tp %s : %s\0A\00"
define i32 @p_MoveFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i64 @rename(i8* %7, i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @p_CopyFile(i8* %12, i8* %13)
store i32 %14, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 (...) @system_error()
%20 = call i32 @lprintf(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i32 %19)
store i32 0, i32* %3
br label %25
21: ; preds = %11
%22 = load i8*, i8** %4
%23 = call i32 @p_DeleteFile(i8* %22)
store i32 %23, i32* %3
br label %25
24: ; preds = %2
store i32 1, i32* %3
br label %25
25: ; preds = %24, %21, %16
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [26 x i8] c"Can't copy %s tp %s : %s\0A\00"
define i32 @p_MoveFile(i8* %0, i8* %1) {
%3 = tail call i64 @rename(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @p_CopyFile(i8* %0, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 (...) @system_error()
%10 = tail call i32 @lprintf(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %9)
br label %13
11: ; preds = %5
%12 = tail call i32 @p_DeleteFile(i8* %0)
br label %13
13: ; preds = %2, %11, %8
%14 = phi i32 [ %12, %11 ], [ 0, %8 ], [ 1, %2 ]
ret i32 %14
}