#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int strlen(char const *);
void crypt(const char *filein, const char *fileout, const char *pwd) {
  int keylen;
  FILE *fin, *fout;
  int c, t;
  keylen = strlen(pwd);
  fin = fopen(filein, "rb");
  fout = fopen(fileout, "wb");
  for (c = 0;; c++) {
    t = getc(fin);
    if (feof(fin))
      break;
    t = t ^ (pwd[c % keylen]);
    putc(t, fout);
  }
  fclose(fin);
  fclose(fout);
}


x86 assembly (clang, -O0):
<crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11d3 <crypt+0x73>
jmp    120d <crypt+0xad>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    -0x3c(%rbp),%eax
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <putc@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11af <crypt+0x4f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe7a(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r13
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   1080 <getc@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11ef <crypt+0x8f>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%eax
cltd
idiv   %r14d
movsbl (%r15,%rdx,1),%edi
xor    %ebx,%edi
mov    %r12,%rsi
call   1050 <putc@plt>
add    $0x1,%ebp
mov    %r13,%rdi
call   1080 <getc@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11c0 <crypt+0x60>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define void @crypt(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %9
store i32 0, i32* %10
br label %18
18: ; preds = %39, %3
%19 = load i32*, i32** %8
%20 = call i32 @getc(i32* %19)
store i32 %20, i32* %11
%21 = load i32*, i32** %8
%22 = call i64 @feof(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %42
25: ; preds = %18
%26 = load i32, i32* %11
%27 = load i8*, i8** %6
%28 = load i32, i32* %10
%29 = load i32, i32* %7
%30 = srem i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = xor i32 %26, %34
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = load i32*, i32** %9
%38 = call i32 @putc(i32 %36, i32* %37)
br label %39
39: ; preds = %25
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %18
42: ; preds = %24
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define void @crypt(i8* nocapture %0, i8* nocapture %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @getc(i32* %5)
%8 = tail call i64 @feof(i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %3, %10
%11 = phi i32 [ %21, %10 ], [ %7, %3 ]
%12 = phi i32 [ %20, %10 ], [ 0, %3 ]
%13 = srem i32 %12, %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = xor i32 %11, %17
%19 = tail call i32 @putc(i32 %18, i32* %6)
%20 = add nuw nsw i32 %12, 1
%21 = tail call i32 @getc(i32* %5)
%22 = tail call i64 @feof(i32* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %10, label %24
24: ; preds = %10, %3
%25 = tail call i32 @fclose(i32* %5)
%26 = tail call i32 @fclose(i32* %6)
ret void
}