#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 int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IRUSR;
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ hasDirectoryFlag(char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ processDirectory(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ processFile(int /*<<< orphan*/ *, char *);
int main(int ac, char *av[]) {
  DIR *sourceDir;
  DIR *targetDir;
  if (hasDirectoryFlag(av[1])) {
    if (ac < 4) {
      printf("Please specify source and target directories\n");
      exit(1);
    }
    sourceDir = opendir(av[2]);
    if (sourceDir == NULL) {
      printf("Cannot open directory %s\n", av[2]);
      exit(1);
    }
    targetDir = opendir(av[3]);
    if (targetDir == NULL) {
      printf("Creating directory %s\n", av[3]);
      mkdir(av[3], S_IRUSR | S_IWUSR | S_IXUSR);
    }
    printf("Copying files from %s to %s\n", av[2], av[3]);
    processDirectory(sourceDir, av[2], av[3]);
    closedir(sourceDir);
    closedir(targetDir);
  } else {
    if (ac != 2) {
      printf("Please specify single file to backup\n");
      exit(1);
    }
    sourceDir = opendir(".");
    if (sourceDir == NULL) {
      printf("Cannot open directory");
      exit(1);
    }
    printf("Backing up %s\n", av[1]);
    processFile(sourceDir, av[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <hasDirectoryFlag@plt>
cmp    $0x0,%rax
je     12b3 <main+0x133>
cmpl   $0x4,-0x8(%rbp)
jge    11cf <main+0x4f>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120b <main+0x8b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1265 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d8b(%rip),%rax
or     (%rax),%esi
mov    0x2d8a(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
call   1090 <processDirectory@plt>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
jmp    132f <main+0x1af>
cmpl   $0x2,-0x8(%rbp)
je     12d5 <main+0x155>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdc6(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1308 <main+0x188>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <processFile@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1090 <hasDirectoryFlag@plt>
test   %rax,%rax
je     124b <main+0xbb>
cmp    $0x3,%ebp
jle    128f <main+0xff>
mov    0x10(%rbx),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1298 <main+0x108>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1050 <opendir@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1213 <main+0x83>
mov    0x18(%rbx),%rsi
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dda(%rip),%rax
mov    0x2de3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x18(%rbx),%rdi
mov    0x2ddc(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
mov    %r14,%rdi
call   10a0 <processDirectory@plt>
mov    %r14,%rdi
call   1070 <closedir@plt>
mov    %r15,%rdi
call   1070 <closedir@plt>
jmp    1282 <main+0xf2>
cmp    $0x2,%ebp
jne    12b4 <main+0x124>
lea    0xdf7(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     12ca <main+0x13a>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   1080 <processFile@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe04(%rip),%rdi
jmp    12bb <main+0x12b>
mov    0x10(%rbx),%rsi
lea    0xd5d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd7f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"Please specify source and target directories\0A\00"
@.str.1 = [26 x i8] c"Cannot open directory %s\0A\00"
@.str.2 = [23 x i8] c"Creating directory %s\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@.str.3 = [29 x i8] c"Copying files from %s to %s\0A\00"
@.str.4 = [38 x i8] c"Please specify single file to backup\0A\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [22 x i8] c"Cannot open directory\00"
@.str.7 = [15 x i8] c"Backing up %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @hasDirectoryFlag(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %73
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @opendir(i8* %22)
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32* @opendir(i8* %35)
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %53
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = load i32, i32* @S_IRUSR
%48 = load i32, i32* @S_IWUSR
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IXUSR
%51 = or i32 %49, %50
%52 = call i32 @mkdir(i8* %46, i32 %51)
br label %53
53: ; preds = %39, %32
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %56, i8* %59)
%61 = load i32*, i32** %6
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 3
%67 = load i8*, i8** %66
%68 = call i32 @processDirectory(i32* %61, i8* %64, i8* %67)
%69 = load i32*, i32** %6
%70 = call i32 @closedir(i32* %69)
%71 = load i32*, i32** %7
%72 = call i32 @closedir(i32* %71)
br label %96
73: ; preds = %2
%74 = load i32, i32* %4
%75 = icmp ne i32 %74, 2
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %73
%80 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %80, i32** %6
%81 = load i32*, i32** %6
%82 = icmp eq i32* %81, null
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %79
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %89)
%91 = load i32*, i32** %6
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 @processFile(i32* %91, i8* %94)
br label %96
96: ; preds = %86, %53
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"Cannot open directory %s\0A\00"
@.str.2 = [23 x i8] c"Creating directory %s\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@.str.3 = [29 x i8] c"Copying files from %s to %s\0A\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [22 x i8] c"Cannot open directory\00"
@.str.7 = [15 x i8] c"Backing up %s\0A\00"
@str = [37 x i8] c"Please specify single file to backup\00"
@str.8 = [45 x i8] c"Please specify source and target directories\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i64 @hasDirectoryFlag(i8* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %45, label %7
7: ; preds = %2
%8 = icmp slt i32 %0, 4
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @opendir(i8* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32* @opendir(i8* %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %36
26: ; preds = %21
%27 = load i8*, i8** %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %22
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = load i32, i32* @S_IXUSR
%34 = or i32 %32, %33
%35 = tail call i32 @mkdir(i8* %29, i32 %34)
br label %36
36: ; preds = %26, %21
%37 = load i8*, i8** %13
%38 = load i8*, i8** %22
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %13
%41 = load i8*, i8** %22
%42 = tail call i32 @processDirectory(i32* %15, i8* %40, i8* %41)
%43 = tail call i32 @closedir(i32* %15)
%44 = tail call i32 @closedir(i32* %24)
br label %61
45: ; preds = %2
%46 = icmp eq i32 %0, 2
br i1 %46, label %50, label %47
47: ; preds = %45
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %45
%51 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %50
%57 = load i8*, i8** %3
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %57)
%59 = load i8*, i8** %3
%60 = tail call i32 @processFile(i32* %51, i8* %59)
br label %61
61: ; preds = %56, %36
ret i32 0
}