#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 /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ rename(char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlcat(char *, char *, int);
int /*<<< orphan*/ strlcpy(char *, char *, int);
char *strrchr(char *, char);
int main(int argc, char *argv[]) {
  char path[PATH_MAX];
  char *src, *dest, *p;
  struct stat st1, st2;
  int rc;
  if (argc != 3) {
    fprintf(stderr, "usage: mv src dest\n");
    exit(1);
  }
  src = argv[1];
  dest = argv[2];
  if (stat(src, &st1) < 0)
    err(1, "mv");
  if (!S_ISREG(st1.st_mode)) {
    fprintf(stderr, "mv: invalid file type\n");
    exit(1);
  }
  rc = stat(dest, &st2);
  if (!rc && S_ISDIR(st2.st_mode)) {
    p = strrchr(src, '/');
    p = p ? p + 1 : src;
    strlcpy(path, dest, sizeof(path));
    if (strcmp(dest, "/"))
      strlcat(path, "/", sizeof(path));
    strlcat(path, p, sizeof(path));
    dest = path;
  }
  if (rename(src, dest) < 0)
    err(1, "rename");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     121f <main+0x6f>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%eax
jge    125e <main+0xae>
mov    $0x1,%edi
lea    0xdbb(%rip),%rsi
call   10a0 <err@plt>
mov    -0x40(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%eax
jne    128e <main+0xde>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    1356 <main+0x1a6>
mov    -0x48(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1356 <main+0x1a6>
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12e8 <main+0x138>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    12f0 <main+0x140>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    -0x68(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   10b0 <strlcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xd18(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     133b <main+0x18b>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    %eax,%edx
lea    0xcf8(%rip),%rsi
call   1030 <strlcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strlcat@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10c0 <rename@plt>
cmp    $0x0,%rax
jge    137e <main+0x1ce>
mov    $0x1,%edi
lea    0xcb7(%rip),%rsi
call   10a0 <err@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e28(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%edi
jne    12cc <main+0x11c>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%r12
lea    -0x38(%rbp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
test   %eax,%eax
jns    120e <main+0x5e>
lea    0xe10(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    -0x38(%rbp),%edi
call   1090 <S_ISREG@plt>
test   %eax,%eax
je     12de <main+0x12e>
lea    -0x30(%rbp),%rsi
mov    %r12,%rdi
call   1080 <stat@plt>
test   %eax,%eax
je     1233 <main+0x83>
mov    %r12,%rbx
jmp    129a <main+0xea>
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     122e <main+0x7e>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%r13
test   %rax,%rax
cmove  %r15,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   10b0 <strlcpy@plt>
lea    0xdc1(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     128c <main+0xdc>
lea    0xdad(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strlcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1030 <strlcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10c0 <rename@plt>
test   %rax,%rax
jns    12bb <main+0x10b>
lea    0xd7f(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
jmp    12ee <main+0x13e>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"usage: mv src dest\0A\00"
@.str.1 = [3 x i8] c"mv\00"
@.str.2 = [23 x i8] c"mv: invalid file type\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [7 x i8] c"rename\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca %struct.stat
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %6
%17 = alloca i8, i64 %15
store i64 %15, i64* %7
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %8
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %9
%31 = load i8*, i8** %8
%32 = call i32 @stat(i8* %31, %struct.stat* %11)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
%37 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @S_ISREG(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = load i8*, i8** %9
%47 = call i32 @stat(i8* %46, %struct.stat* %12)
store i32 %47, i32* %13
%48 = load i32, i32* %13
%49 = icmp ne i32 %48, 0
br i1 %49, label %80, label %50
50: ; preds = %45
%51 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @S_ISDIR(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %80
55: ; preds = %50
%56 = load i8*, i8** %8
%57 = call i8* @strrchr(i8* %56, i8 signext 47)
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i8*, i8** %10
%62 = getelementptr inbounds i8, i8* %61, i64 1
br label %65
63: ; preds = %55
%64 = load i8*, i8** %8
br label %65
65: ; preds = %63, %60
%66 = phi i8* [ %62, %60 ], [ %64, %63 ]
store i8* %66, i8** %10
%67 = load i8*, i8** %9
%68 = trunc i64 %15 to i32
%69 = call i32 @strlcpy(i8* %17, i8* %67, i32 %68)
%70 = load i8*, i8** %9
%71 = call i64 @strcmp(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %65
%74 = trunc i64 %15 to i32
%75 = call i32 @strlcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %73, %65
%77 = load i8*, i8** %10
%78 = trunc i64 %15 to i32
%79 = call i32 @strlcat(i8* %17, i8* %77, i32 %78)
store i8* %17, i8** %9
br label %80
80: ; preds = %76, %50, %45
%81 = load i8*, i8** %8
%82 = load i8*, i8** %9
%83 = call i64 @rename(i8* %81, i8* %82)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %80
%86 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %85, %80
store i32 0, i32* %3
%88 = load i8*, i8** %6
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"usage: mv src dest\0A\00"
@.str.1 = [3 x i8] c"mv\00"
@.str.2 = [23 x i8] c"mv: invalid file type\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [7 x i8] c"rename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.stat* %3 to i8*
%9 = bitcast %struct.stat* %4 to i8*
%10 = icmp eq i32 %0, 3
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @stat(i8* %17, %struct.stat* %3)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%26 = load i32, i32* %25
%27 = tail call i32 @S_ISREG(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = call i32 @stat(i8* %19, %struct.stat* %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %53
36: ; preds = %33
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%38 = load i32, i32* %37
%39 = tail call i64 @S_ISDIR(i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %36
%42 = tail call i8* @strrchr(i8* dereferenceable(1) %17, i8 signext 47)
%43 = icmp eq i8* %42, null
%44 = getelementptr inbounds i8, i8* %42, i64 1
%45 = select i1 %43, i8* %17, i8* %44
%46 = call i32 @strlcpy(i8* %7, i8* %19, i32 %5)
%47 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %41
%50 = call i32 @strlcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %51
51: ; preds = %49, %41
%52 = call i32 @strlcat(i8* %7, i8* %45, i32 %5)
br label %53
53: ; preds = %51, %36, %33
%54 = phi i8* [ %19, %33 ], [ %7, %51 ], [ %19, %36 ]
%55 = call i64 @rename(i8* %17, i8* %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
ret i32 0
}