#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 */
struct stat {
  int st_size;
};
typedef int ssize_t;

/* Variables and functions */
int fsop_cp(char const *, char const *, size_t);
scalar_t__ fsop_unlink(char const *);
int /*<<< orphan*/ rename(char const *, char const *);
scalar_t__ stat(char const *, struct stat *);
ssize_t fsop_mv(const char *from, const char *to, size_t block) {
  ssize_t count = 0;
  struct stat st;
  if (!rename(from, to)) {
    if (stat(to, &st) < 0)
      return -1;
    return st.st_size;
  }
  if ((count = fsop_cp(from, to, block)) < 0)
    return -1;
  if (fsop_unlink(from) < 0)
    return -1;
  return count;
}


x86 assembly (clang, -O0):
<fsop_mv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <rename@plt>
cmp    $0x0,%eax
jne    119f <fsop_mv+0x5f>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    1194 <fsop_mv+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <fsop_mv+0xad>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <fsop_mv+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <fsop_cp@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11c8 <fsop_mv+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <fsop_mv+0xad>
mov    -0x10(%rbp),%rdi
call   1040 <fsop_unlink@plt>
cmp    $0x0,%rax
jge    11e7 <fsop_mv+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <fsop_mv+0xad>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsop_mv>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <rename@plt>
test   %eax,%eax
je     1184 <fsop_mv+0x44>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <fsop_cp@plt>
test   %eax,%eax
js     119c <fsop_mv+0x5c>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fsop_unlink@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovs  %eax,%ebx
jmp    11a1 <fsop_mv+0x61>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     119c <fsop_mv+0x5c>
mov    0x8(%rsp),%ebx
jmp    11a1 <fsop_mv+0x61>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @fsop_mv(i8* %0, i8* %1, i64 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = tail call i32 @rename(i8* %0, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = call i64 @stat(i8* %1, %struct.stat* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%13 = load i32, i32* %12
br label %21
14: ; preds = %3
%15 = tail call i32 @fsop_cp(i8* %0, i8* %1, i64 %2)
%16 = icmp slt i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i64 @fsop_unlink(i8* %0)
%19 = icmp slt i64 %18, 0
%20 = select i1 %19, i32 -1, i32 %15
br label %21
21: ; preds = %17, %14, %8, %11
%22 = phi i32 [ %13, %11 ], [ -1, %8 ], [ -1, %14 ], [ %20, %17 ]
ret i32 %22
}