#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*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *const, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *const *argv) {
  printf("One-time pad cryptor.\n");
  if (argc == 4) {
    FILE *input = fopen(argv[1], "rb");
    FILE *output = fopen(argv[2], "wb");
    if (input != NULL && output != NULL) {
      unsigned char buffer[BUFSIZ];
      size_t count, i, j = 0;
      do {
        count = fread(buffer, sizeof *buffer, sizeof buffer, input);
        for (i = 0; i < count; ++i) {
          buffer[i] ^= argv[3][j++];
          if (argv[3][j] == '\0') {
            j = 0;
          }
        }
        fwrite(buffer, sizeof *buffer, count, output);
      } while (count == sizeof buffer);
      fclose(input);
      fclose(output);
    }
  } else
    printf("Usage: %s file_to_crypt crypted_file key\n", argv[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jne    12d5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12d0 <main+0x180>
cmpq   $0x0,-0x20(%rbp)
je     12d0 <main+0x180>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cltq
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1293 <main+0x143>
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x18(%rcx),%rcx
mov    -0x48(%rbp),%rdx
mov    %rdx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x48(%rbp)
movsbl (%rcx,%rdx,1),%esi
mov    -0x40(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
xor    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    127d <main+0x12d>
movq   $0x0,-0x48(%rbp)
jmp    1282 <main+0x132>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1222 <main+0xd2>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x58(%rbp),%rax
cmp    %rax,-0x38(%rbp)
je     11fc <main+0xac>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    12ea <main+0x19a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%ebx
jne    12c3 <main+0x163>
mov    0x8(%r14),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rbx,-0x30(%rbp)
test   %rbx,%rbx
je     12eb <main+0x18b>
mov    %rax,%r12
test   %rax,%rax
je     12eb <main+0x18b>
mov    %r14,-0x40(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %r15d,%r15d
jmp    120c <main+0xac>
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r12,%rcx
call   1080 <fwrite@plt>
cmp    %r13,%r14
jne    12d6 <main+0x176>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    -0x30(%rbp),%rcx
call   1040 <fread@plt>
movslq %eax,%r14
test   %r14d,%r14d
je     11f0 <main+0x90>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
cmp    $0x2,%r14
mov    $0x1,%r8d
cmovae %r14,%r8
cmp    $0x1,%r14d
jne    1270 <main+0x110>
xor    %edx,%edx
test   $0x1,%r8b
je     11f0 <main+0x90>
mov    (%rax,%r15,1),%cl
xor    %cl,(%rbx,%rdx,1)
cmpb   $0x0,0x1(%rax,%r15,1)
lea    0x1(%r15),%rax
mov    $0x0,%r15d
cmovne %rax,%r15
jmp    11f0 <main+0x90>
nopl   0x0(%rax)
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
jmp    1289 <main+0x129>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rdx
cmp    %rdx,%rsi
je     1246 <main+0xe6>
movzbl (%rax,%r15,1),%ecx
xor    %cl,(%rbx,%rdx,1)
cmpb   $0x0,0x1(%rax,%r15,1)
mov    $0x0,%edi
je     12a5 <main+0x145>
add    $0x1,%r15
mov    %r15,%rdi
movzbl (%rax,%rdi,1),%ecx
xor    %cl,0x1(%rbx,%rdx,1)
cmpb   $0x0,0x1(%rax,%rdi,1)
mov    $0x0,%r15d
je     1280 <main+0x120>
add    $0x1,%rdi
mov    %rdi,%r15
jmp    1280 <main+0x120>
mov    (%r14),%rsi
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12eb <main+0x18b>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"One-time pad cryptor.\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@BUFSIZ = global i32 0
@.str.3 = [42 x i8] c"Usage: %s file_to_crypt crypted_file key\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %86
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %85
27: ; preds = %16
%28 = load i32*, i32** %7
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %85
30: ; preds = %27
%31 = load i32, i32* @BUFSIZ
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %8
%34 = alloca i8, i64 %32
store i64 %32, i64* %9
store i64 0, i64* %12
br label %35
35: ; preds = %76, %30
%36 = trunc i64 %32 to i32
%37 = load i32*, i32** %6
%38 = call i32 @fread(i8* %34, i32 1, i32 %36, i32* %37)
%39 = sext i32 %38 to i64
store i64 %39, i64* %10
store i64 0, i64* %11
br label %40
40: ; preds = %69, %35
%41 = load i64, i64* %11
%42 = load i64, i64* %10
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %72
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = load i64, i64* %12
%49 = add i64 %48, 1
store i64 %49, i64* %12
%50 = getelementptr inbounds i8, i8* %47, i64 %48
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = load i64, i64* %11
%54 = getelementptr inbounds i8, i8* %34, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = xor i32 %56, %52
%58 = trunc i32 %57 to i8
store i8 %58, i8* %54
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 3
%61 = load i8*, i8** %60
%62 = load i64, i64* %12
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %44
store i64 0, i64* %12
br label %68
68: ; preds = %67, %44
br label %69
69: ; preds = %68
%70 = load i64, i64* %11
%71 = add i64 %70, 1
store i64 %71, i64* %11
br label %40
72: ; preds = %40
%73 = load i64, i64* %10
%74 = load i32*, i32** %7
%75 = call i32 @fwrite(i8* %34, i32 1, i64 %73, i32* %74)
br label %76
76: ; preds = %72
%77 = load i64, i64* %10
%78 = icmp eq i64 %77, %32
br i1 %78, label %35, label %79
79: ; preds = %76
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
%82 = load i32*, i32** %7
%83 = call i32 @fclose(i32* %82)
%84 = load i8*, i8** %8
br label %85
85: ; preds = %79, %27, %16
br label %91
86: ; preds = %2
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %86, %85
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
@BUFSIZ = global i32 0
@.str.3 = [42 x i8] c"Usage: %s file_to_crypt crypted_file key\0A\00"
@str = [22 x i8] c"One-time pad cryptor.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 4
br i1 %4, label %5, label %84
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp ne i32* %8, null
%13 = icmp ne i32* %11, null
%14 = and i1 %12, %13
br i1 %14, label %15, label %87
15: ; preds = %5
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = tail call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = getelementptr inbounds i8*, i8** %1, i64 3
br label %21
21: ; preds = %77, %15
%22 = phi i64 [ 0, %15 ], [ %78, %77 ]
%23 = call i32 @fread(i8* %19, i32 1, i32 %16, i32* %8)
%24 = sext i32 %23 to i64
%25 = icmp eq i32 %23, 0
br i1 %25, label %77, label %26
26: ; preds = %21
%27 = load i8*, i8** %20
%28 = call i64 @llvm.umax.i64(i64 %24, i64 1)
%29 = and i64 %28, 1
%30 = icmp eq i32 %23, 1
br i1 %30, label %61, label %31
31: ; preds = %26
%32 = and i64 %28, -2
br label %33
33: ; preds = %33, %31
%34 = phi i64 [ %22, %31 ], [ %57, %33 ]
%35 = phi i64 [ 0, %31 ], [ %58, %33 ]
%36 = phi i64 [ 0, %31 ], [ %59, %33 ]
%37 = add i64 %34, 1
%38 = getelementptr inbounds i8, i8* %27, i64 %34
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %19, i64 %35
%41 = load i8, i8* %40
%42 = xor i8 %41, %39
store i8 %42, i8* %40
%43 = getelementptr inbounds i8, i8* %27, i64 %37
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
%46 = select i1 %45, i64 0, i64 %37
%47 = or i64 %35, 1
%48 = add i64 %46, 1
%49 = getelementptr inbounds i8, i8* %27, i64 %46
%50 = load i8, i8* %49
%51 = getelementptr inbounds i8, i8* %19, i64 %47
%52 = load i8, i8* %51
%53 = xor i8 %52, %50
store i8 %53, i8* %51
%54 = getelementptr inbounds i8, i8* %27, i64 %48
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 0
%57 = select i1 %56, i64 0, i64 %48
%58 = add nuw i64 %35, 2
%59 = add i64 %36, 2
%60 = icmp eq i64 %59, %32
br i1 %60, label %61, label %33
61: ; preds = %33, %26
%62 = phi i64 [ undef, %26 ], [ %57, %33 ]
%63 = phi i64 [ %22, %26 ], [ %57, %33 ]
%64 = phi i64 [ 0, %26 ], [ %58, %33 ]
%65 = icmp eq i64 %29, 0
br i1 %65, label %77, label %66
66: ; preds = %61
%67 = add i64 %63, 1
%68 = getelementptr inbounds i8, i8* %27, i64 %63
%69 = load i8, i8* %68
%70 = getelementptr inbounds i8, i8* %19, i64 %64
%71 = load i8, i8* %70
%72 = xor i8 %71, %69
store i8 %72, i8* %70
%73 = getelementptr inbounds i8, i8* %27, i64 %67
%74 = load i8, i8* %73
%75 = icmp eq i8 %74, 0
%76 = select i1 %75, i64 0, i64 %67
br label %77
77: ; preds = %66, %61, %21
%78 = phi i64 [ %22, %21 ], [ %62, %61 ], [ %76, %66 ]
%79 = call i32 @fwrite(i8* %19, i32 1, i64 %24, i32* %11)
%80 = icmp eq i64 %24, %17
br i1 %80, label %21, label %81
81: ; preds = %77
%82 = tail call i32 @fclose(i32* %8)
%83 = tail call i32 @fclose(i32* %11)
tail call void @llvm.stackrestore(i8* %18)
br label %87
84: ; preds = %2
%85 = load i8*, i8** %1
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %5, %81, %84
ret i32 0
}