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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rename(char *, char *);
scalar_t__ stat(char *, struct stat *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  struct stat st;
  int dst_exists = 0, dst_isdir = 0;
  int i, err;
  char buf[512];
  if (argc < 3) {
    printf("mv: file1 file.. dest dir\n");
    printf("mv: file1 file2\n");
    return 1;
  }
  if (stat(argv[argc - 1], &st) == 0) {
    dst_exists = 1;
    if (st.st_mode & 0040000)
      dst_isdir = 1;
  }
  if (argc > 3 && (!dst_exists || !dst_isdir)) {
    printf("mv: for multiple files, dest %s should be a directory\n",
           argv[argc - 1]);
    return 1;
  }
  for (i = 1; i < argc - 1; i++) {
    if (stat(argv[i], &st) < 0) {
      printf("mv: cannot stat %s\n", argv[i]);
      err++;
      continue;
    }
    strncpy(buf, argv[argc - 1], sizeof(buf) - 1);
    if (dst_isdir) {
      strncat(buf, "/", sizeof(buf) - strlen(buf) - 1);
      strncat(buf, argv[i], sizeof(buf) - strlen(buf) - 1);
    }
    if (rename(argv[i], buf) < 0)
      err++;
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b9 <main+0x59>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a8 <main+0x248>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    1201 <main+0xa1>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     11fc <main+0x9c>
movl   $0x1,-0x20(%rbp)
jmp    1201 <main+0xa1>
cmpl   $0x3,-0x8(%rbp)
jle    124a <main+0xea>
cmpl   $0x0,-0x1c(%rbp)
je     121f <main+0xbf>
cmpl   $0x0,-0x20(%rbp)
jne    124a <main+0xea>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a8 <main+0x248>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13a2 <main+0x242>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jge    12a9 <main+0x149>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1394 <main+0x234>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x20(%rbp)
je     1364 <main+0x204>
lea    -0x230(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x248(%rbp),%rdi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xd69(%rip),%rsi
call   1060 <strncat@plt>
lea    -0x230(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x238(%rbp)
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rsi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x230(%rbp),%rsi
call   1080 <rename@plt>
cmp    $0x0,%rax
jge    138f <main+0x22f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1394 <main+0x234>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1251 <main+0xf1>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
cmp    $0x2,%edi
jg     11a0 <main+0x30>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
lea    0xece(%rip),%rdi
call   1040 <puts@plt>
jmp    11ec <main+0x7c>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x1(%rbp),%r13d
mov    (%rsi,%r13,8),%rdi
lea    0x10(%rsp),%rsi
call   1080 <stat@plt>
test   %rax,%rax
sete   %al
setne  0xf(%rsp)
mov    $0x4000,%edx
and    0x10(%rsp),%edx
sete   %cl
cmp    $0x3,%ebp
je     1205 <main+0x95>
shr    $0xe,%edx
and    %dl,%al
jne    1205 <main+0x95>
mov    (%rbx,%r13,8),%rsi
lea    0xe1b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
or     %cl,0xf(%rsp)
mov    $0x1,%r14d
lea    0x10(%rsp),%r12
mov    %r13,0x18(%rsp)
jmp    123b <main+0xcb>
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r14,8),%rdi
mov    %r15,%rsi
call   1090 <rename@plt>
shr    $0x3f,%rax
add    %eax,%ebp
add    $0x1,%r14
cmp    %r14,%r13
je     11f1 <main+0x81>
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
call   1080 <stat@plt>
test   %rax,%rax
js     12c0 <main+0x150>
mov    (%rbx,%r13,8),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0xf(%rsp)
jne    1220 <main+0xb0>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %r15,%rdi
lea    0xdc9(%rip),%rsi
call   1070 <strncat@plt>
mov    (%rbx,%r14,8),%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %r15,%rdi
mov    %r13,%rsi
lea    0x10(%rsp),%r12
mov    0x18(%rsp),%r13
call   1070 <strncat@plt>
jmp    1220 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%r14,8),%rsi
lea    0xd6c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
jmp    1230 <main+0xc0>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.2 = [55 x i8] c"mv: for multiple files, dest %s should be a directory\0A\00"
@.str.3 = [20 x i8] c"mv: cannot stat %s\0A\00"
@.str.4 = [2 x i8] c"/\00"
@str = [26 x i8] c"mv: file1 file.. dest dir\00"
@str.5 = [16 x i8] c"mv: file1 file2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [512 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
br label %62
11: ; preds = %2
%12 = add nsw i32 %0, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = call i64 @stat(i8* %15, %struct.stat* %3)
%17 = icmp eq i64 %16, 0
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, 16384
%21 = icmp eq i32 %20, 0
%22 = xor i1 %21, true
%23 = xor i1 %17, true
%24 = select i1 %23, i1 true, i1 %21
%25 = select i1 %17, i1 %22, i1 false
%26 = icmp eq i32 %0, 3
%27 = select i1 %26, i1 true, i1 %25
br i1 %27, label %31, label %28
28: ; preds = %11
%29 = load i8*, i8** %14
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %62
31: ; preds = %11, %57
%32 = phi i64 [ %60, %57 ], [ 1, %11 ]
%33 = phi i32 [ %59, %57 ], [ undef, %11 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %32
%35 = load i8*, i8** %34
%36 = call i64 @stat(i8* %35, %struct.stat* %3)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = load i8*, i8** %34
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %57
41: ; preds = %31
%42 = load i8*, i8** %14
%43 = call i32 @strncpy(i8* %6, i8* %42, i32 511)
br i1 %24, label %52, label %44
44: ; preds = %41
%45 = call i32 @strlen(i8* %6)
%46 = sub i32 511, %45
%47 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %34
%49 = call i32 @strlen(i8* %6)
%50 = sub i32 511, %49
%51 = call i32 @strncat(i8* %6, i8* %48, i32 %50)
br label %52
52: ; preds = %44, %41
%53 = load i8*, i8** %34
%54 = call i64 @rename(i8* %53, i8* %6)
%55 = lshr i64 %54, 63
%56 = trunc i64 %55 to i32
br label %57
57: ; preds = %52, %38
%58 = phi i32 [ %56, %52 ], [ 1, %38 ]
%59 = add nsw i32 %33, %58
%60 = add nuw nsw i64 %32, 1
%61 = icmp eq i64 %60, %13
br i1 %61, label %62, label %31
62: ; preds = %57, %28, %8
%63 = phi i32 [ 1, %8 ], [ 1, %28 ], [ %59, %57 ]
ret i32 %63
}