#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 /*<<< orphan*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int child;
  char *cpPath = "/bin/cp";
  char *args[] = {cpPath, argv[1], argv[2], NULL};
  if (argc < 2) {
    printf("Wrong Usage (./Practica3_2 originFile destinyFile\n");
  } else {
    child = fork();
    if (child == 0) {
      execv(cpPath, args);
    } else {
      wait(NULL);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a4 <main+0x64>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    11d8 <main+0x98>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ca <main+0x8a>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <execv@plt>
jmp    11d3 <main+0x93>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <wait@plt>
jmp    11d8 <main+0x98>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xeb5(%rip),%rax
mov    %rax,(%rsp)
movups 0x8(%rsi),%xmm0
movups %xmm0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
cmp    $0x1,%edi
jg     1174 <main+0x34>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
jmp    1197 <main+0x57>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1188 <main+0x48>
xor    %edi,%edi
call   1040 <wait@plt>
jmp    1197 <main+0x57>
lea    0xe71(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execv@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/cp\00"
@.str.1 = [51 x i8] c"Wrong Usage (./Practica3_2 originFile destinyFile\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%10 = load i8*, i8** %7
store i8* %10, i8** %9
%11 = getelementptr inbounds i8*, i8** %9, i64 1
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %11
%15 = getelementptr inbounds i8*, i8** %11, i64 1
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
store i8* %18, i8** %15
%19 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* null, i8** %19
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %35
24: ; preds = %2
%25 = call i32 (...) @fork()
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%31 = call i32 @execv(i8* %29, i8** %30)
br label %34
32: ; preds = %24
%33 = call i32 @wait(i32* null)
br label %34
34: ; preds = %32, %28
br label %35
35: ; preds = %34, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/cp\00"
@str = [50 x i8] c"Wrong Usage (./Practica3_2 originFile destinyFile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8*]
%4 = bitcast [4 x i8*]* %3 to i8*
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = bitcast i8** %7 to <2 x i8*>*
%9 = load <2 x i8*>, <2 x i8*>* %8
%10 = bitcast i8** %6 to <2 x i8*>*
store <2 x i8*> %9, <2 x i8*>* %10
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
store i8* null, i8** %11
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = tail call i32 (...) @fork()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5)
br label %22
20: ; preds = %15
%21 = tail call i32 @wait(i32* null)
br label %22
22: ; preds = %18, %20, %13
ret i32 0
}