#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 */
int execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ legal_string(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  char *src_dir = "/tmp/";
  char *dest_dir = "/nfs/garbage/incoming/";
  char *move_path = "/bin/mv";
  char *move_file = "mv";
  char *dest_file;
  char *src_file;
  if (argc != 3) {
    fprintf(stderr,
            "FAILURE: usage: tmpfilemove temp_filename real_filename\n");
    exit(1);
  } else {
    src_file = (char *)malloc(strlen(src_dir) + strlen(argv[1]) + 1);
    strcpy(src_file, src_dir);
    strcat(src_file, argv[1]);
    dest_file = (char *)malloc(strlen(dest_dir) + strlen(argv[2]) + 1);
    strcpy(dest_file, dest_dir);
    strcat(dest_file, argv[2]);
    if (!legal_string(src_file)) {
      fprintf(stderr, "FAILURE: illegal characters in source file\n");
      exit(1);
    }
    if (!legal_string(dest_file)) {
      fprintf(stderr, "FAILURE: illegal characters in destination file\n");
      exit(1);
    }
    if (execl(move_path, move_file, src_file, dest_file, (char *)0) == -1) {
      perror("FAILURE");
      exit(1);
    }
  }
  printf("OK\n");
  free(dest_file);
  free(src_file);
  exit(0);
}


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)
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe2e(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe34(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     121b <main+0x6b>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
call   10d0 <legal_string@plt>
cmp    $0x0,%eax
jne    12e4 <main+0x134>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rdi
call   10d0 <legal_string@plt>
cmp    $0x0,%eax
jne    1315 <main+0x165>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <execl@plt>
cmp    $0xffffffff,%eax
jne    134e <main+0x19e>
lea    0xd7c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1353 <main+0x1a3>
lea    0xd69(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    123f <main+0x8f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
lea    0x6(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe23(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    0x10(%rbx),%rdi
call   1060 <strlen@plt>
lea    0x17(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xdf9(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rsi
mov    %r15,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
call   10d0 <legal_string@plt>
test   %eax,%eax
jne    125e <main+0xae>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
jmp    124f <main+0x9f>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %r15,%rdi
call   10d0 <legal_string@plt>
test   %eax,%eax
jne    127c <main+0xcc>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
jmp    124f <main+0x9f>
lea    0xd9a(%rip),%rdi
lea    0xd98(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   10c0 <execl@plt>
cmp    $0xffffffff,%eax
jne    12b3 <main+0x103>
lea    0xe17(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe09(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"/tmp/\00"
@.str.1 = [23 x i8] c"/nfs/garbage/incoming/\00"
@.str.2 = [8 x i8] c"/bin/mv\00"
@.str.3 = [3 x i8] c"mv\00"
@stderr = global i32 0
@.str.4 = [57 x i8] c"FAILURE: usage: tmpfilemove temp_filename real_filename\0A\00"
@.str.5 = [44 x i8] c"FAILURE: illegal characters in source file\0A\00"
@.str.6 = [49 x i8] c"FAILURE: illegal characters in destination file\0A\00"
@.str.7 = [8 x i8] c"FAILURE\00"
@.str.8 = [4 x i8] c"OK\0A\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 i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = call i64 @strlen(i8* %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %20, %24
%26 = add nsw i64 %25, 1
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %11
%29 = load i8*, i8** %11
%30 = load i8*, i8** %6
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %11
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strcat(i8* %32, i8* %35)
%37 = load i8*, i8** %7
%38 = call i64 @strlen(i8* %37)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i64 @strlen(i8* %41)
%43 = add nsw i64 %38, %42
%44 = add nsw i64 %43, 1
%45 = call i64 @malloc(i64 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %10
%47 = load i8*, i8** %10
%48 = load i8*, i8** %7
%49 = call i32 @strcpy(i8* %47, i8* %48)
%50 = load i8*, i8** %10
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @strcat(i8* %50, i8* %53)
%55 = load i8*, i8** %11
%56 = call i32 @legal_string(i8* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %18
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %18
%63 = load i8*, i8** %10
%64 = call i32 @legal_string(i8* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %62
%71 = load i8*, i8** %8
%72 = load i8*, i8** %9
%73 = load i8*, i8** %11
%74 = load i8*, i8** %10
%75 = call i32 @execl(i8* %71, i8* %72, i8* %73, i8* %74, i8* null)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %70
%78 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %70
br label %81
81: ; preds = %80
%82 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%83 = load i8*, i8** %10
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %11
%86 = call i32 @free(i8* %85)
%87 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"/tmp/\00"
@.str.1 = [23 x i8] c"/nfs/garbage/incoming/\00"
@.str.2 = [8 x i8] c"/bin/mv\00"
@.str.3 = [3 x i8] c"mv\00"
@stderr = global i32 0
@.str.4 = [57 x i8] c"FAILURE: usage: tmpfilemove temp_filename real_filename\0A\00"
@.str.5 = [44 x i8] c"FAILURE: illegal characters in source file\0A\00"
@.str.6 = [49 x i8] c"FAILURE: illegal characters in destination file\0A\00"
@.str.7 = [8 x i8] c"FAILURE\00"
@str = [3 x i8] c"OK\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add nsw i64 %11, 6
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %9
%17 = tail call i32 @strcat(i8* %14, i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i64 @strlen(i8* dereferenceable(1) %19)
%21 = add nsw i64 %20, 23
%22 = tail call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %18
%26 = tail call i32 @strcat(i8* %23, i8* %25)
%27 = tail call i32 @legal_string(i8* %14)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %8
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %8
%34 = tail call i32 @legal_string(i8* %23)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %33
%41 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %14, i8* %23, i8* null)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%48 = tail call i32 @free(i8* %23)
%49 = tail call i32 @free(i8* %14)
%50 = tail call i32 @exit(i32 0)
unreachable
}