#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 EXIT_FAILURE;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ xorenc(char *, char *, char *);
int main(int argc, char **argv) {
  char input[512], *key;
  if (argc != 3) {
    printf("ERROR: invalid arguments\n\n");
    printf("Usage:\n");
    printf("%s [input] [output]\n", argv[0]);
    return EXIT_FAILURE;
  }
  printf("Key please: ");
  fgets(input, 512, stdin);
  key = malloc(strlen(input) + 1);
  strcpy(key, input);
  xorenc(argv[1], argv[2], key);
  free(key);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d5 <main+0x65>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125e <main+0xee>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1070 <fgets@plt>
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x218(%rbp),%rdx
call   1080 <xorenc@plt>
mov    -0x218(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11f8 <main+0x78>
lea    0xe79(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %rbp,%rdx
call   1090 <xorenc@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    122b <main+0xab>
lea    0xe23(%rip),%rdi
call   1050 <puts@plt>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
mov    (%rbx),%rsi
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%r15d
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"ERROR: invalid arguments\0A\0A\00"
@.str.1 = [8 x i8] c"Usage:\0A\00"
@.str.2 = [21 x i8] c"%s [input] [output]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"Key please: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %40
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 512, i32 %21)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i8*, i8** %7
%37 = call i32 @xorenc(i8* %32, i8* %35, i8* %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %18, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.2 = [21 x i8] c"%s [input] [output]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"Key please: \00"
@stdin = global i32 0
@str = [26 x i8] c"ERROR: invalid arguments\0A\00"
@str.4 = [7 x i8] c"Usage:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0))
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
br label %26
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %4, i32 512, i32 %14)
%16 = call i64 @strlen(i8* %4)
%17 = add nsw i64 %16, 1
%18 = call i8* @malloc(i64 %17)
%19 = call i32 @strcpy(i8* %18, i8* %4)
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @xorenc(i8* %21, i8* %23, i8* %18)
%25 = call i32 @free(i8* %18)
br label %26
26: ; preds = %12, %6
%27 = phi i32 [ %11, %6 ], [ 0, %12 ]
ret i32 %27
}