#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__ EISDIR;
scalar_t__ errno;
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ writestr(int, char *);
int mv(char *src, char *dst) {
  if (rename(src, dst)) {
    if (errno == EISDIR) {
      writestr(2, "mv: ");
      writestr(2, dst);
      writestr(2, ": is dir\n");
    } else {
      writestr(2, "mv: ");
      writestr(2, src);
      writestr(2, ": can't move\n");
    }
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mv>:
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,%rax
je     11d2 <mv+0xb2>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <mv+0x76>
mov    $0x2,%edi
lea    0xe93(%rip),%rsi
call   1030 <writestr@plt>
mov    -0x18(%rbp),%rsi
mov    $0x2,%edi
call   1030 <writestr@plt>
mov    $0x2,%edi
lea    0xe79(%rip),%rsi
call   1030 <writestr@plt>
jmp    11c6 <mv+0xa6>
mov    $0x2,%edi
lea    0xe5e(%rip),%rsi
call   1030 <writestr@plt>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   1030 <writestr@plt>
mov    $0x2,%edi
lea    0xe4e(%rip),%rsi
call   1030 <writestr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <mv+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mv>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <rename@plt>
test   %rax,%rax
je     1190 <mv+0x70>
mov    0x2e9d(%rip),%rax
mov    (%rax),%rax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%rax
lea    0xeb1(%rip),%rsi
cmove  %r14,%rbx
lea    0xeab(%rip),%rax
lea    0xeae(%rip),%r14
cmove  %rax,%r14
mov    $0x2,%edi
call   1030 <writestr@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1030 <writestr@plt>
mov    $0x2,%edi
mov    %r14,%rsi
call   1030 <writestr@plt>
mov    $0xffffffff,%eax
jmp    1192 <mv+0x72>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@EISDIR = global i64 0
@.str = [5 x i8] c"mv: \00"
@.str.1 = [10 x i8] c": is dir\0A\00"
@.str.2 = [14 x i8] c": can't move\0A\00"
define i32 @mv(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 i64 @rename(i8* %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @EISDIR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %5
%17 = call i32 @writestr(i32 2, i8* %16)
%18 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %24
19: ; preds = %10
%20 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32 @writestr(i32 2, i8* %21)
%23 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %19, %14
store i32 -1, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@errno = global i64 0
@EISDIR = global i64 0
@.str = [5 x i8] c"mv: \00"
@.str.1 = [10 x i8] c": is dir\0A\00"
@.str.2 = [14 x i8] c": can't move\0A\00"
define i32 @mv(i8* %0, i8* %1) {
%3 = tail call i64 @rename(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EISDIR
%8 = icmp eq i64 %6, %7
%9 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = select i1 %8, i8* %1, i8* %0
%11 = select i1 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0)
%12 = tail call i32 @writestr(i32 2, i8* %10)
%13 = tail call i32 @writestr(i32 2, i8* %11)
br label %14
14: ; preds = %5, %2
%15 = phi i32 [ 0, %2 ], [ -1, %5 ]
ret i32 %15
}