#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, unsigned char *);
main() {
  unsigned char ch;
  FILE *fpIn, *fpOut;
  int i;
  unsigned char key[7] = {0xAB, 0x56, 0xC2, 0xB2, 0x53, 0x9E, 0x3E};
  fpIn = fopen("ptext.txt", "r");
  fpOut = fopen("ctext.txt", "w");
  i = 0;
  while (fscanf(fpIn, "%c", &ch) != EOF) {
    if (ch != '\n') {
      fprintf(fpOut, "%02X", ch ^ key[i % 7]);
      i++;
    }
  }
  fclose(fpIn);
  fclose(fpOut);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0x23(%rbp)
mov    0xea5(%rip),%ax
mov    %ax,-0x1f(%rbp)
mov    0xe9d(%rip),%al
mov    %al,-0x1d(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
lea    -0x5(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     1212 <main+0xd2>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     120d <main+0xcd>
mov    -0x18(%rbp),%rdi
movzbl -0x5(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%eax
movslq %edx,%rcx
movzbl -0x23(%rbp,%rcx,1),%ecx
xor    %ecx,%eax
lea    0xe26(%rip),%rsi
movzbl %al,%edx
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <main+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xea1(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
mov    0x2e56(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    11b9 <main+0x79>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
lea    0xe5c(%rip),%r15
lea    0x7(%rsp),%r12
jmp    11e4 <main+0xa4>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%rbp),%rax
je     1198 <main+0x58>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
je     11d0 <main+0x90>
movslq %r13d,%r13
imul   $0xffffffff92492493,%r13,%rcx
shr    $0x20,%rcx
add    %r13d,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %r13d,%ecx
movslq %ecx,%rcx
lea    0xde2(%rip),%rdx
xor    (%rcx,%rdx,1),%al
movzbl %al,%edx
mov    %r14,%rdi
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%r13d
jmp    11d0 <main+0x90>

LLVM IR (-O0):
@__const.main.key = [7 x i8] c"\ABV\C2\B2S\9E>"
@.str = [10 x i8] c"ptext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"ctext.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.5 = [5 x i8] c"%02X\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [7 x i8]
store i32 0, i32* %1
%7 = bitcast [7 x i8]* %6 to i8*
%8 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %4
store i32 0, i32* %5
br label %10
10: ; preds = %34, %0
%11 = load i32*, i32** %3
%12 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%13 = load i64, i64* @EOF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %10
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = load i8, i8* %2
%22 = zext i8 %21 to i32
%23 = load i32, i32* %5
%24 = srem i32 %23, 7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = xor i32 %22, %28
%30 = trunc i32 %29 to i8
%31 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %30)
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %19, %15
br label %10
35: ; preds = %10
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@__const.main.key = [7 x i8] c"\ABV\C2\B2S\9E>"
@.str = [10 x i8] c"ptext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"ctext.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.5 = [5 x i8] c"%02X\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %24, label %7
7: ; preds = %0, %19
%8 = phi i32 [ %20, %19 ], [ 0, %0 ]
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 10
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = srem i32 %8, 7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [7 x i8], [7 x i8]* @__const.main.key, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = xor i8 %15, %9
%17 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %16)
%18 = add nsw i32 %8, 1
br label %19
19: ; preds = %11, %7
%20 = phi i32 [ %18, %11 ], [ %8, %7 ]
%21 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %7
24: ; preds = %19, %0
%25 = call i32 @fclose(i32* %2)
%26 = call i32 @fclose(i32* %3)
ret i32 0
}