#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ execl(char *, char *, char const *, char const *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void copy(char const *source, char const *dest) {
  int childExitStatus;
  pid_t pid;
  int status;
  char const *error_msg = "Error copying template! Quitting...\n";
  if (!source || !dest) {
  }
  pid = fork();
  if (pid == 0) {
    execl("/bin/cp", "/bin/cp", source, dest, (char *)0);
  } else if (pid < 0) {
    printf("%s", error_msg);
    exit(-1);
  } else {
    pid_t ws = waitpid(pid, &childExitStatus, WNOHANG);
    if (ws == -1) {
      printf("%s", error_msg);
      exit(-1);
    }
    if (WIFEXITED(childExitStatus)) {
      status = WEXITSTATUS(childExitStatus);
    } else if (WIFSIGNALED(childExitStatus)) {
    } else if (WIFSTOPPED(childExitStatus)) {
    }
  }
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe59(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c1 <copy+0x31>
cmpq   $0x0,-0x10(%rbp)
jne    11c6 <copy+0x36>
jmp    11c6 <copy+0x36>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fd <copy+0x6d>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   10a0 <execl@plt>
jmp    12c5 <copy+0x135>
cmpq   $0x0,-0x20(%rbp)
jge    1222 <copy+0x92>
mov    -0x30(%rbp),%rsi
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1261 <copy+0xd1>
mov    -0x30(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1283 <copy+0xf3>
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x24(%rbp)
jmp    12bb <copy+0x12b>
mov    -0x14(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     129a <copy+0x10a>
jmp    12b6 <copy+0x126>
mov    -0x14(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     12b1 <copy+0x121>
jmp    12b1 <copy+0x121>
jmp    12b6 <copy+0x126>
jmp    12bb <copy+0x12b>
jmp    12c0 <copy+0x130>
jmp    12c5 <copy+0x135>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     11dd <copy+0x4d>
js     1217 <copy+0x87>
mov    0x2e39(%rip),%rcx
mov    (%rcx),%edx
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1070 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     1217 <copy+0x87>
mov    0x4(%rsp),%edi
call   1080 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     11fc <copy+0x6c>
call   1060 <WEXITSTATUS@plt>
jmp    120f <copy+0x7f>
lea    0xe41(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <execl@plt>
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
jne    120f <copy+0x7f>
mov    0x4(%rsp),%edi
call   1050 <WIFSTOPPED@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0f(%rip),%rdi
lea    0xddb(%rip),%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Error copying template! Quitting...\0A\00"
@.str.1 = [8 x i8] c"/bin/cp\00"
@.str.2 = [3 x i8] c"%s\00"
@WNOHANG = global i32 0
define void @copy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %2
br label %16
16: ; preds = %15, %12
%17 = call i64 (...) @fork()
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22, i8* null)
br label %62
24: ; preds = %16
%25 = load i64, i64* %6
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %24
%32 = load i64, i64* %6
%33 = load i32, i32* @WNOHANG
%34 = call i64 @waitpid(i64 %32, i32* %5, i32 %33)
store i64 %34, i64* %9
%35 = load i64, i64* %9
%36 = icmp eq i64 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %31
%42 = load i32, i32* %5
%43 = call i64 @WIFEXITED(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %5
%47 = call i32 @WEXITSTATUS(i32 %46)
store i32 %47, i32* %7
br label %60
48: ; preds = %41
%49 = load i32, i32* %5
%50 = call i64 @WIFSIGNALED(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
br label %59
53: ; preds = %48
%54 = load i32, i32* %5
%55 = call i64 @WIFSTOPPED(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %53
br label %58
58: ; preds = %57, %53
br label %59
59: ; preds = %58, %52
br label %60
60: ; preds = %59, %45
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61, %20
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Error copying template! Quitting...\0A\00"
@.str.1 = [8 x i8] c"/bin/cp\00"
@.str.2 = [3 x i8] c"%s\00"
@WNOHANG = global i32 0
define void @copy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* null)
br label %34
9: ; preds = %2
%10 = icmp slt i64 %5, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %9
%15 = load i32, i32* @WNOHANG
%16 = call i64 @waitpid(i64 %5, i32* %3, i32 %15)
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
%22 = load i32, i32* %3
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = load i32, i32* %3
br i1 %24, label %28, label %26
26: ; preds = %21
%27 = call i32 @WEXITSTATUS(i32 %25)
br label %34
28: ; preds = %21
%29 = call i64 @WIFSIGNALED(i32 %25)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %3
%33 = call i64 @WIFSTOPPED(i32 %32)
br label %34
34: ; preds = %26, %28, %31, %7
ret void
}