#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_ctime;
};
typedef int /*<<< orphan*/ currPos;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
scalar_t__ difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int executeCpCommand(char *arg1, char *arg2) {
  char dest[1024], currPos[1024];
  if (getcwd(currPos, sizeof(currPos)) == NULL) {
    perror("getcwd() error");
  }
  strcpy(dest, currPos);
  strcat(dest, "/");
  strncat(dest, arg2, strlen(arg2) - 1);
  struct stat attr1, attr2;
  stat(arg1, &attr1);
  stat(dest, &attr2);
  int timeDiff = difftime(attr2.st_ctime, attr1.st_ctime) > 0 ? 1 : -1;
  FILE *source, *target;
  char ch;
  if (access(arg1, F_OK) == -1) {
    printf("File missing !!! \n");
  } else if (access(arg1, R_OK) == -1) {
    printf("Read Permission, Access Denied !!! \n");
  }
  source = fopen(arg1, "r");
  target = fopen(dest, "w");
  if (source == NULL) {
    printf("Unable to open source file..ERROR in opening file!!\n");
    return -1;
  }
  if (target != NULL && access(dest, W_OK) == -1) {
    printf("Write Permission, Access Denied !!! \n");
    return -1;
  }
  if (target != NULL && timeDiff == 1) {
    printf("Error !!! Destination has a newer file !!! \n");
    return -1;
  }
  while ((ch = fgetc(source)) != EOF)
    fputc(ch, target);
  printf("Copy Successful !!!\n");
  fclose(source);
  fclose(target);
  return 0;
}


x86 assembly (clang, -O0):
<executeCpCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
jne    121a <executeCpCommand+0x3a>
lea    0xdeb(%rip),%rdi
call   10f0 <perror@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x860(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x860(%rbp),%rdi
mov    -0x858(%rbp),%rsi
mov    %rax,%rdx
sub    $0x1,%rdx
call   1090 <strncat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x828(%rbp),%rsi
call   10c0 <stat@plt>
lea    -0x420(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   10c0 <stat@plt>
mov    -0x830(%rbp),%edi
mov    -0x828(%rbp),%esi
call   1070 <difftime@plt>
mov    %rax,%rdx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovg  %ecx,%eax
mov    %eax,-0x834(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
jne    12f6 <executeCpCommand+0x116>
lea    0xd25(%rip),%rdi
call   1060 <printf@plt>
jmp    1322 <executeCpCommand+0x142>
mov    -0x10(%rbp),%rdi
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
jne    131d <executeCpCommand+0x13d>
lea    0xd0c(%rip),%rdi
call   1060 <printf@plt>
jmp    1322 <executeCpCommand+0x142>
mov    -0x10(%rbp),%rdi
lea    0xce0(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x840(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xd02(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x840(%rbp)
jne    1379 <executeCpCommand+0x199>
lea    0xce3(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1461 <executeCpCommand+0x281>
cmpq   $0x0,-0x848(%rbp)
je     13bd <executeCpCommand+0x1dd>
lea    -0x420(%rbp),%rdi
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
jne    13bd <executeCpCommand+0x1dd>
lea    0xcd4(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1461 <executeCpCommand+0x281>
cmpq   $0x0,-0x848(%rbp)
je     13f0 <executeCpCommand+0x210>
cmpl   $0x1,-0x834(%rbp)
jne    13f0 <executeCpCommand+0x210>
lea    0xcc7(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1461 <executeCpCommand+0x281>
jmp    13f5 <executeCpCommand+0x215>
mov    -0x840(%rbp),%rdi
call   10a0 <fgetc@plt>
mov    %al,-0x849(%rbp)
movsbl %al,%eax
mov    0x2bd7(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1436 <executeCpCommand+0x256>
mov    -0x849(%rbp),%al
mov    -0x848(%rbp),%rsi
movsbl %al,%edi
call   10b0 <fputc@plt>
jmp    13f5 <executeCpCommand+0x215>
lea    0xc96(%rip),%rdi
call   1060 <printf@plt>
mov    -0x840(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x848(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<executeCpCommand>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x410(%rsp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
je     1386 <executeCpCommand+0x1a6>
lea    0x10(%rsp),%r14
lea    0x410(%rsp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xde6(%rip),%rsi
mov    %r14,%rdi
call   1100 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strncat@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <stat@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   10c0 <stat@plt>
mov    (%rsp),%edi
mov    0x8(%rsp),%esi
call   1070 <difftime@plt>
mov    %rax,%r14
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
je     12a4 <executeCpCommand+0xc4>
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
jne    12b0 <executeCpCommand+0xd0>
lea    0xe0a(%rip),%rdi
jmp    12ab <executeCpCommand+0xcb>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
lea    0xd56(%rip),%rsi
mov    %r15,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbx
lea    0xd48(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10e0 <fopen@plt>
test   %rbx,%rbx
je     1306 <executeCpCommand+0x126>
mov    %rax,%r15
test   %rax,%rax
je     130f <executeCpCommand+0x12f>
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   10d0 <access@plt>
cmp    $0xffffffff,%eax
je     1368 <executeCpCommand+0x188>
test   %r14,%r14
jle    130f <executeCpCommand+0x12f>
lea    0xd23(%rip),%rdi
jmp    136f <executeCpCommand+0x18f>
lea    0xd6b(%rip),%rdi
jmp    136f <executeCpCommand+0x18f>
mov    %rbx,%rdi
call   10a0 <fgetc@plt>
mov    0x2cca(%rip),%r14
cmp    (%r14),%al
je     1348 <executeCpCommand+0x168>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
mov    %r15,%rsi
call   10b0 <fputc@plt>
mov    %rbx,%rdi
call   10a0 <fgetc@plt>
cmp    (%r14),%al
jne    1330 <executeCpCommand+0x150>
lea    0xcc4(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1379 <executeCpCommand+0x199>
lea    0xce4(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xc73(%rip),%rdi
call   10f0 <perror@plt>
jmp    120d <executeCpCommand+0x2d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"getcwd() error\00"
@.str.1 = [2 x i8] c"/\00"
@F_OK = global i32 0
@.str.2 = [19 x i8] c"File missing !!! \0A\00"
@R_OK = global i32 0
@.str.3 = [37 x i8] c"Read Permission, Access Denied !!! \0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [53 x i8] c"Unable to open source file..ERROR in opening file!!\0A\00"
@W_OK = global i32 0
@.str.7 = [38 x i8] c"Write Permission, Access Denied !!! \0A\00"
@.str.8 = [45 x i8] c"Error !!! Destination has a newer file !!! \0A\00"
@EOF = global i8 0
@.str.9 = [21 x i8] c"Copy Successful !!!\0A\00"
define i32 @executeCpCommand(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca %struct.stat
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32* @getcwd(i8* %14, i32 1024)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i64 @strlen(i8* %27)
%29 = sub nsw i64 %28, 1
%30 = call i32 @strncat(i8* %25, i8* %26, i64 %29)
%31 = load i8*, i8** %4
%32 = call i32 @stat(i8* %31, %struct.stat* %8)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @stat(i8* %33, %struct.stat* %9)
%35 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @difftime(i32 %36, i32 %38)
%40 = icmp sgt i64 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 1, i32 -1
store i32 %42, i32* %10
%43 = load i8*, i8** %4
%44 = load i32, i32* @F_OK
%45 = call i32 @access(i8* %43, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %19
%48 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %57
49: ; preds = %19
%50 = load i8*, i8** %4
%51 = load i32, i32* @R_OK
%52 = call i32 @access(i8* %50, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
br label %57
57: ; preds = %56, %47
%58 = load i8*, i8** %4
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %59, i32** %11
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%61 = call i32* @fopen(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %61, i32** %12
%62 = load i32*, i32** %11
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %66
64: ; preds = %57
%65 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
66: ; preds = %57
%67 = load i32*, i32** %12
%68 = icmp ne i32* %67, null
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* @W_OK
%72 = call i32 @access(i8* %70, i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
76: ; preds = %69, %66
%77 = load i32*, i32** %12
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %84
79: ; preds = %76
%80 = load i32, i32* %10
%81 = icmp eq i32 %80, 1
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
84: ; preds = %79, %76
br label %85
85: ; preds = %92, %84
%86 = load i32*, i32** %11
%87 = call signext i8 @fgetc(i32* %86)
store i8 %87, i8* %13
%88 = sext i8 %87 to i32
%89 = load i8, i8* @EOF
%90 = sext i8 %89 to i32
%91 = icmp ne i32 %88, %90
br i1 %91, label %92, label %96
92: ; preds = %85
%93 = load i8, i8* %13
%94 = load i32*, i32** %12
%95 = call i32 @fputc(i8 signext %93, i32* %94)
br label %85
96: ; preds = %85
%97 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%98 = load i32*, i32** %11
%99 = call i32 @fclose(i32* %98)
%100 = load i32*, i32** %12
%101 = call i32 @fclose(i32* %100)
store i32 0, i32* %3
br label %102
102: ; preds = %96, %82, %74, %64
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"getcwd() error\00"
@.str.1 = [2 x i8] c"/\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@W_OK = global i32 0
@EOF = global i8 0
@str = [20 x i8] c"Copy Successful !!!\00"
@str.10 = [44 x i8] c"Error !!! Destination has a newer file !!! \00"
@str.11 = [37 x i8] c"Write Permission, Access Denied !!! \00"
@str.12 = [52 x i8] c"Unable to open source file..ERROR in opening file!!\00"
@str.13 = [36 x i8] c"Read Permission, Access Denied !!! \00"
@str.14 = [18 x i8] c"File missing !!! \00"
define i32 @executeCpCommand(i8* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32* @getcwd(i8* %8, i32 1024)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @strcpy(i8* %7, i8* %8)
%15 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i64 @strlen(i8* dereferenceable(1) %1)
%17 = add nsw i64 %16, -1
%18 = call i32 @strncat(i8* %7, i8* %1, i64 %17)
%19 = bitcast %struct.stat* %5 to i8*
%20 = bitcast %struct.stat* %6 to i8*
%21 = call i32 @stat(i8* %0, %struct.stat* %5)
%22 = call i32 @stat(i8* %7, %struct.stat* %6)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @difftime(i32 %24, i32 %26)
%28 = icmp sgt i64 %27, 0
%29 = load i32, i32* @F_OK
%30 = call i32 @access(i8* %0, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %36, label %32
32: ; preds = %13
%33 = load i32, i32* @R_OK
%34 = call i32 @access(i8* %0, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %32, %13
%37 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0), %13 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.13, i64 0, i64 0), %32 ]
%38 = call i32 @puts(i8* dereferenceable(1) %37)
br label %39
39: ; preds = %36, %32
%40 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32* %40, null
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
br label %70
45: ; preds = %39
%46 = icmp eq i32* %41, null
br i1 %46, label %47, label %51
47: ; preds = %57, %45
%48 = call signext i8 @fgetc(i32* %40)
%49 = load i8, i8* @EOF
%50 = icmp eq i8 %48, %49
br i1 %50, label %66, label %60
51: ; preds = %45
%52 = load i32, i32* @W_OK
%53 = call i32 @access(i8* %7, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.11, i64 0, i64 0))
br label %70
57: ; preds = %51
br i1 %28, label %58, label %47
58: ; preds = %57
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0))
br label %70
60: ; preds = %47, %60
%61 = phi i8 [ %63, %60 ], [ %48, %47 ]
%62 = call i32 @fputc(i8 signext %61, i32* %41)
%63 = call signext i8 @fgetc(i32* %40)
%64 = load i8, i8* @EOF
%65 = icmp eq i8 %63, %64
br i1 %65, label %66, label %60
66: ; preds = %60, %47
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%68 = call i32 @fclose(i32* %40)
%69 = call i32 @fclose(i32* %41)
br label %70
70: ; preds = %66, %58, %55, %43
%71 = phi i32 [ -1, %43 ], [ -1, %55 ], [ -1, %58 ], [ 0, %66 ]
ret i32 %71
}