#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*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ encryptDecrypt(char *, char *);
int fopen(char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char *argv[]) {
  ;
  printf("ENCDEC 1.1\n");
  char dir[255];
  if (argc < 2)
    strcpy(dir, "/mnt/usbDrive/toCrypt");
  else {
    strcpy(dir, argv[1]);
  }
  char filenameIn[255];
  strcpy(filenameIn, dir);
  printf("%s\n", filenameIn);
  char filenameOut[255];
  if (strcmp(filenameIn, "/mnt/usbDrive/toCrypt") == 0) {
    strcpy(filenameOut, "/mnt/usbDrive/crypted.xor");
  } else if (strcmp(filenameIn, "/mnt/usbDrive/toDecrypt.xor") == 0) {
    strcpy(filenameOut, "/mnt/usbDrive/decrypted");
  } else {
    strcpy(filenameOut, dir);
    strcat(filenameOut, ".xor");
  }
  printf("%s\n", filenameOut);
  char buffIn[1024];
  char buffOut[1024];
  close(fopen(filenameOut, "w"));
  int fd1 = open(filenameIn, O_RDONLY);
  int fd2 = open(filenameOut, O_RDWR);
  if (filenameIn != NULL) {
    int bytes = read(fd1, &buffIn, 1024);
    printf("%s\n", buffOut);
    encryptDecrypt(buffIn, buffOut);
    write(fd2, &buffOut, bytes);
    close(fd1);
    close(fd2);
  } else {
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11e9 <main+0x49>
lea    -0x110(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fd <main+0x5d>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x210(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    125a <main+0xba>
lea    -0x310(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12ba <main+0x11a>
lea    -0x210(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    128f <main+0xef>
lea    -0x310(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12b5 <main+0x115>
lea    -0x310(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x310(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   10c0 <strcat@plt>
jmp    12ba <main+0x11a>
lea    -0x310(%rbp),%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x310(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   10b0 <fopen@plt>
mov    %eax,%edi
call   1070 <close@plt>
lea    -0x210(%rbp),%rdi
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0xb14(%rbp)
lea    -0x310(%rbp),%rdi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0xb18(%rbp)
mov    -0xb14(%rbp),%edi
lea    -0x710(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0xb1c(%rbp)
lea    -0xb10(%rbp),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x710(%rbp),%rdi
lea    -0xb10(%rbp),%rsi
call   1050 <encryptDecrypt@plt>
mov    -0xb18(%rbp),%edi
lea    -0xb10(%rbp),%rsi
mov    -0xb1c(%rbp),%edx
call   1040 <write@plt>
mov    -0xb14(%rbp),%edi
call   1070 <close@plt>
mov    -0xb18(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xb20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb00,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jge    11ce <main+0x2e>
lea    0xe34(%rip),%rsi
jmp    11d2 <main+0x32>
mov    0x8(%rbx),%rsi
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xdfc(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     124e <main+0xae>
lea    0xe18(%rip),%rsi
lea    0x100(%rsp),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1257 <main+0xb7>
mov    %rsp,%rbx
lea    0x200(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
jmp    1266 <main+0xc6>
lea    0xdc1(%rip),%rsi
jmp    125e <main+0xbe>
lea    0xdee(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xdec(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
mov    %eax,%edi
call   1070 <close@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
lea    0x100(%rsp),%rdi
call   10a0 <open@plt>
mov    %eax,%r15d
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
lea    0x700(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%r12d
lea    0x300(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <encryptDecrypt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <write@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xb00,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ENCDEC 1.1\0A\00"
@.str.1 = [22 x i8] c"/mnt/usbDrive/toCrypt\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [26 x i8] c"/mnt/usbDrive/crypted.xor\00"
@.str.4 = [28 x i8] c"/mnt/usbDrive/toDecrypt.xor\00"
@.str.5 = [24 x i8] c"/mnt/usbDrive/decrypted\00"
@.str.6 = [5 x i8] c".xor\00"
@.str.7 = [2 x i8] c"w\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
%7 = alloca [255 x i8]
%8 = alloca [255 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %2
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
br label %26
26: ; preds = %20, %17
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %52
38: ; preds = %26
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %51
45: ; preds = %38
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%47 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%48 = call i32 @strcpy(i8* %46, i8* %47)
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %45, %42
br label %52
52: ; preds = %51, %35
%53 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%56 = call i32 @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%57 = call i32 @close(i32 %56)
%58 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%59 = load i32, i32* @O_RDONLY
%60 = call i32 @open(i8* %58, i32 %59)
store i32 %60, i32* %11
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%62 = load i32, i32* @O_RDWR
%63 = call i32 @open(i8* %61, i32 %62)
store i32 %63, i32* %12
%64 = load i32, i32* %11
%65 = bitcast [1024 x i8]* %9 to i8**
%66 = call i32 @read(i32 %64, i8** %65, i32 1024)
store i32 %66, i32* %13
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%71 = call i32 @encryptDecrypt(i8* %69, i8* %70)
%72 = load i32, i32* %12
%73 = bitcast [1024 x i8]* %10 to i8**
%74 = load i32, i32* %13
%75 = call i32 @write(i32 %72, i8** %73, i32 %74)
%76 = load i32, i32* %11
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %12
%79 = call i32 @close(i32 %78)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"/mnt/usbDrive/toCrypt\00"
@.str.3 = [26 x i8] c"/mnt/usbDrive/crypted.xor\00"
@.str.4 = [28 x i8] c"/mnt/usbDrive/toDecrypt.xor\00"
@.str.5 = [24 x i8] c"/mnt/usbDrive/decrypted\00"
@.str.6 = [5 x i8] c".xor\00"
@.str.7 = [2 x i8] c"w\00"
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@str = [11 x i8] c"ENCDEC 1.1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%10 = icmp slt i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
br label %14
14: ; preds = %2, %11
%15 = phi i8* [ %13, %11 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %2 ]
%16 = call i32 @strcpy(i8* %9, i8* %15)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* %9)
%19 = call i32 @puts(i8* %17)
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%21 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %33
25: ; preds = %14
%26 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %33
30: ; preds = %25
%31 = call i32 @strcpy(i8* %20, i8* %9)
%32 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %28, %30, %23
%34 = call i32 @puts(i8* %20)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i32 @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @O_RDONLY
%40 = call i32 @open(i8* %17, i32 %39)
%41 = load i32, i32* @O_RDWR
%42 = call i32 @open(i8* %20, i32 %41)
%43 = bitcast [1024 x i8]* %6 to i8**
%44 = call i32 @read(i32 %40, i8** %43, i32 1024)
%45 = call i32 @puts(i8* %36)
%46 = call i32 @encryptDecrypt(i8* %35, i8* %36)
%47 = bitcast [1024 x i8]* %7 to i8**
%48 = call i32 @write(i32 %42, i8** %47, i32 %44)
%49 = call i32 @close(i32 %40)
%50 = call i32 @close(i32 %42)
ret i32 0
}