#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;
};

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
char *basename(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ lstat(char *, struct stat *);
char *malloc(size_t);
int mv(char *, char *);
int /*<<< orphan*/ strlcat(char *, char *, size_t);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
int strlen(char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ writestr(int, char *);
int main(int argc, char **argv) {
  char **argp, *buf, *fname, returnval;
  size_t buflen;
  struct stat st;
  if (argc < 3) {
    usage();
    return 1;
  }
  if (lstat(argv[argc - 1], &st) && argc > 3) {
    if (errno == ENOENT) {
      writestr(2, "mv: ");
      writestr(2, argv[argc - 1]);
      writestr(2, ": not found\n");
    }
    return 1;
  }
  if (argc == 3 && !S_ISDIR(st.st_mode))
    return mv(argv[1], argv[2]);
  returnval = 0;
  for (argp = argv + 1; argp < argv + argc - 1; argp++) {
    fname = basename(*argp);
    buflen = strlen(argv[argc - 1]) + strlen(fname) + 2;
    if ((buf = malloc(buflen)) == 0) {
      writestr(2, "mv: out of memory\n");
      exit(0);
    }
    strlcpy(buf, argv[argc - 1], buflen);
    strlcat(buf, "/", buflen);
    strlcat(buf, fname, buflen);
    if (mv(*argp, buf))
      returnval = 1;
    free(buf);
  }
  return returnval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f3 <main+0x33>
mov    $0x0,%al
call   10d0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13de <main+0x21e>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <lstat@plt>
cmp    $0x0,%rax
je     1284 <main+0xc4>
cmpl   $0x3,-0x8(%rbp)
jle    1284 <main+0xc4>
mov    0x2db8(%rip),%rax
mov    (%rax),%rax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%rax
jne    1278 <main+0xb8>
mov    $0x2,%edi
lea    0xdb9(%rip),%rsi
call   10c0 <writestr@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x2,%edi
call   10c0 <writestr@plt>
mov    $0x2,%edi
lea    0xd92(%rip),%rsi
call   10c0 <writestr@plt>
movl   $0x1,-0x4(%rbp)
jmp    13de <main+0x21e>
cmpl   $0x3,-0x8(%rbp)
jne    12bc <main+0xfc>
mov    -0x40(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    12bc <main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <mv@plt>
mov    %eax,-0x4(%rbp)
jmp    13de <main+0x21e>
movb   $0x0,-0x29(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
add    $0xfffffffffffffff8,%rcx
cmp    %rcx,%rax
jae    13d7 <main+0x217>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1080 <basename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    135d <main+0x19d>
mov    $0x2,%edi
lea    0xcc1(%rip),%rsi
call   10c0 <writestr@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x38(%rbp),%rdx
call   10b0 <strlcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xc9b(%rip),%rsi
call   1040 <strlcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <strlcat@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <mv@plt>
cmp    $0x0,%eax
je     13bd <main+0x1fd>
movb   $0x1,-0x29(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    12cc <main+0x10c>
movsbl -0x29(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jg     11e4 <main+0x24>
xor    %eax,%eax
call   10d0 <usage@plt>
mov    $0x1,%ebx
jmp    134b <main+0x18b>
mov    %rsi,%r15
mov    %edi,%ebx
lea    -0x1(%rbx),%r13d
mov    (%rsi,%r13,8),%rdi
mov    %rsp,%rsi
call   1070 <lstat@plt>
cmp    $0x3,%ebx
je     1257 <main+0x97>
test   %rax,%rax
je     1257 <main+0x97>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    0x2dbc(%rip),%rcx
mov    $0x1,%ebx
cmp    (%rcx),%rax
jne    134b <main+0x18b>
lea    0xdd7(%rip),%rsi
mov    $0x2,%edi
call   10c0 <writestr@plt>
mov    (%r15,%r13,8),%rsi
mov    $0x2,%edi
call   10c0 <writestr@plt>
lea    0xdbd(%rip),%rsi
mov    $0x2,%edi
call   10c0 <writestr@plt>
jmp    134b <main+0x18b>
cmp    $0x3,%ebx
jne    126c <main+0xac>
mov    (%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
je     135c <main+0x19c>
mov    %ebx,%eax
lea    (%r15,%rax,8),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%r15),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%rdi
call   1080 <basename@plt>
mov    %rax,%rbx
mov    (%r15,%r13,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %r12d,%eax
add    $0x2,%eax
mov    %r13,%r12
movslq %eax,%r13
mov    %r13,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1377 <main+0x1b7>
mov    %rax,%rbx
mov    %r15,%rax
mov    %r12,%r15
mov    (%rax,%r12,8),%rsi
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r13,%rdx
call   10b0 <strlcpy@plt>
mov    %rbx,%rdi
lea    0xd2e(%rip),%rsi
mov    %r13,%rdx
call   1040 <strlcat@plt>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r13,%rdx
call   1040 <strlcat@plt>
mov    0x0(%rbp),%rdi
mov    %rbx,%rsi
call   1090 <mv@plt>
test   %eax,%eax
movzbl %r14b,%r14d
mov    $0x1,%eax
cmovne %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rbp
cmp    0x8(%rsp),%rbp
mov    %r15,%r13
mov    %r12,%r15
jb     1290 <main+0xd0>
movzbl %r14b,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r15),%rdi
mov    0x10(%r15),%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <mv@plt>
lea    0xc94(%rip),%rsi
mov    $0x2,%edi
call   10c0 <writestr@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [5 x i8] c"mv: \00"
@.str.1 = [13 x i8] c": not found\0A\00"
@.str.2 = [19 x i8] c"mv: out of memory\0A\00"
@.str.3 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i64
%11 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @usage()
store i32 1, i32* %3
br label %124
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %17, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @lstat(i8* %22, %struct.stat* %11)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %16
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 3
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = load i8**, i8*** %5
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @writestr(i32 2, i8* %39)
%41 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %32, %28
store i32 1, i32* %3
br label %124
43: ; preds = %25, %16
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 3
br i1 %45, label %46, label %59
46: ; preds = %43
%47 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @S_ISDIR(i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %46
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @mv(i8* %54, i8* %57)
store i32 %58, i32* %3
br label %124
59: ; preds = %46, %43
store i8 0, i8* %9
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
store i8** %61, i8*** %6
br label %62
62: ; preds = %118, %59
%63 = load i8**, i8*** %6
%64 = load i8**, i8*** %5
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = getelementptr inbounds i8*, i8** %67, i64 -1
%69 = icmp ult i8** %63, %68
br i1 %69, label %70, label %121
70: ; preds = %62
%71 = load i8**, i8*** %6
%72 = load i8*, i8** %71
%73 = call i8* @basename(i8* %72)
store i8* %73, i8** %8
%74 = load i8**, i8*** %5
%75 = load i32, i32* %4
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %74, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @strlen(i8* %79)
%81 = load i8*, i8** %8
%82 = call i32 @strlen(i8* %81)
%83 = add nsw i32 %80, %82
%84 = add nsw i32 %83, 2
%85 = sext i32 %84 to i64
store i64 %85, i64* %10
%86 = load i64, i64* %10
%87 = call i8* @malloc(i64 %86)
store i8* %87, i8** %7
%88 = icmp eq i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %70
%90 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %70
%93 = load i8*, i8** %7
%94 = load i8**, i8*** %5
%95 = load i32, i32* %4
%96 = sub nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
%100 = load i64, i64* %10
%101 = call i32 @strlcpy(i8* %93, i8* %99, i64 %100)
%102 = load i8*, i8** %7
%103 = load i64, i64* %10
%104 = call i32 @strlcat(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i64 %103)
%105 = load i8*, i8** %7
%106 = load i8*, i8** %8
%107 = load i64, i64* %10
%108 = call i32 @strlcat(i8* %105, i8* %106, i64 %107)
%109 = load i8**, i8*** %6
%110 = load i8*, i8** %109
%111 = load i8*, i8** %7
%112 = call i32 @mv(i8* %110, i8* %111)
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %92
store i8 1, i8* %9
br label %115
115: ; preds = %114, %92
%116 = load i8*, i8** %7
%117 = call i32 @free(i8* %116)
br label %118
118: ; preds = %115
%119 = load i8**, i8*** %6
%120 = getelementptr inbounds i8*, i8** %119, i32 1
store i8** %120, i8*** %6
br label %62
121: ; preds = %62
%122 = load i8, i8* %9
%123 = sext i8 %122 to i32
store i32 %123, i32* %3
br label %124
124: ; preds = %121, %51, %42, %14
%125 = load i32, i32* %3
ret i32 %125
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [5 x i8] c"mv: \00"
@.str.1 = [13 x i8] c": not found\0A\00"
@.str.2 = [19 x i8] c"mv: out of memory\0A\00"
@.str.3 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %74
8: ; preds = %2
%9 = add nsw i32 %0, -1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = call i64 @lstat(i8* %12, %struct.stat* %3)
%14 = icmp ne i64 %13, 0
%15 = icmp ne i32 %0, 3
%16 = and i1 %15, %14
br i1 %16, label %17, label %26
17: ; preds = %8
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %74
21: ; preds = %17
%22 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %11
%24 = tail call i32 @writestr(i32 2, i8* %23)
%25 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %74
26: ; preds = %8
%27 = icmp eq i32 %0, 3
br i1 %27, label %28, label %39
28: ; preds = %26
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i32 @S_ISDIR(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = load i8*, i8** %36
%38 = tail call i32 @mv(i8* %35, i8* %37)
br label %74
39: ; preds = %26, %28
%40 = zext i32 %0 to i64
%41 = add nsw i64 %40, -1
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = getelementptr inbounds i8*, i8** %1, i64 1
br label %44
44: ; preds = %39, %60
%45 = phi i8** [ %70, %60 ], [ %43, %39 ]
%46 = phi i8 [ %68, %60 ], [ 0, %39 ]
%47 = load i8*, i8** %45
%48 = tail call i8* @basename(i8* %47)
%49 = load i8*, i8** %11
%50 = tail call i32 @strlen(i8* %49)
%51 = tail call i32 @strlen(i8* %48)
%52 = add i32 %50, 2
%53 = add i32 %52, %51
%54 = sext i32 %53 to i64
%55 = tail call i8* @malloc(i64 %54)
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %44
%58 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%59 = tail call i32 @exit(i32 0)
unreachable
60: ; preds = %44
%61 = load i8*, i8** %11
%62 = tail call i32 @strlcpy(i8* %55, i8* %61, i64 %54)
%63 = tail call i32 @strlcat(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i64 %54)
%64 = tail call i32 @strlcat(i8* %55, i8* %48, i64 %54)
%65 = load i8*, i8** %45
%66 = tail call i32 @mv(i8* %65, i8* %55)
%67 = icmp eq i32 %66, 0
%68 = select i1 %67, i8 %46, i8 1
%69 = tail call i32 @free(i8* %55)
%70 = getelementptr inbounds i8*, i8** %45, i64 1
%71 = icmp ult i8** %70, %42
br i1 %71, label %44, label %72
72: ; preds = %60
%73 = zext i8 %68 to i32
br label %74
74: ; preds = %17, %21, %72, %33, %6
%75 = phi i32 [ 1, %6 ], [ %73, %72 ], [ %38, %33 ], [ 1, %21 ], [ 1, %17 ]
ret i32 %75
}