#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 EOF;
int /*<<< orphan*/ XOR(int, char);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int strlen(char *);
void encrypt_data(FILE *in, FILE *out, char *key) {
  int idx = 0;
  int btoenc;
  while ((btoenc = fgetc(in)) != EOF) {
    fputc(XOR(btoenc, key[idx % strlen(key)]), out);
    idx++;
  }
}


x86 assembly (clang, -O0):
<encrypt_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
je     11c7 <encrypt_data+0x87>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%esi
call   1060 <XOR@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <encrypt_data+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <fgetc@plt>
mov    0x2e88(%rip),%r13
cmp    0x0(%r13),%eax
je     11a8 <encrypt_data+0x68>
mov    %eax,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movsbl (%r12,%rdx,1),%esi
mov    %ebx,%edi
call   1060 <XOR@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
jne    1170 <encrypt_data+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @encrypt_data(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %14, %3
%10 = load i32*, i32** %4
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %8
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = load i32, i32* %8
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = srem i32 %17, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @XOR(i32 %15, i8 signext %23)
%25 = load i32*, i32** %5
%26 = call i32 @fputc(i32 %24, i32* %25)
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %9
29: ; preds = %9
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @encrypt_data(i32* nocapture %0, i32* nocapture %1, i8* %2) {
%4 = tail call i32 @fgetc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %21, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %18, %7 ], [ %4, %3 ]
%9 = phi i32 [ %17, %7 ], [ 0, %3 ]
%10 = tail call i32 @strlen(i8* %2)
%11 = srem i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @XOR(i32 %8, i8 signext %14)
%16 = tail call i32 @fputc(i32 %15, i32* %1)
%17 = add nuw nsw i32 %9, 1
%18 = tail call i32 @fgetc(i32* %0)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %7
21: ; preds = %7, %3
ret void
}