#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ isalpha(int);
int /*<<< orphan*/ printf(char *, ...);
char tolower(int);
void fnEncryption() {
  FILE *pf, *pfo;
  int key, ch;
  pfo = fopen("out.dat", "w");
  if (!pfo) {
    printf("Can not create the file\n");
    return;
  }
  pf = fopen("in.dat", "r");
  if (!pf) {
    printf("Can not open the file\n");
    fclose(pfo);
    return;
  }
  fscanf(pf, "%d", &key);
  ch = fgetc(pf);
  while (ch != EOF) {
    if (isalpha(ch)) {
      ch = tolower(ch) - 'a';
      ch = (ch + key + 26) % 26;
      printf("%c", ch + 'A');
      fprintf(pfo, "%c", ch + 'A');
    }
    ch = fgetc(pf);
  }
}


x86 assembly (clang, -O0):
<fnEncryption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
lea    0xe72(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <fnEncryption+0x3d>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129f <fnEncryption+0x11f>
lea    0xe5f(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11fb <fnEncryption+0x7b>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    129f <fnEncryption+0x11f>
mov    -0x8(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%eax
je     129f <fnEncryption+0x11f>
mov    -0x18(%rbp),%edi
call   1090 <isalpha@plt>
cmp    $0x0,%rax
je     128e <fnEncryption+0x10e>
mov    -0x18(%rbp),%edi
call   1080 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
add    $0x1a,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%esi
add    $0x41,%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
add    $0x41,%edx
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x18(%rbp)
jmp    121b <fnEncryption+0x9b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnEncryption>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe62(%rip),%rdi
lea    0xe63(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1200 <fnEncryption+0x70>
mov    %rax,%r14
lea    0xe51(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1216 <fnEncryption+0x86>
mov    %rax,%rbx
lea    0xe3f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    0x2df8(%rip),%r15
cmp    (%r15),%eax
jne    1234 <fnEncryption+0xa4>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
mov    %eax,%ebp
jmp    124f <fnEncryption+0xbf>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     11f5 <fnEncryption+0x65>
mov    %ebp,%edi
call   10a0 <isalpha@plt>
test   %rax,%rax
je     1240 <fnEncryption+0xb0>
mov    %ebp,%edi
call   1090 <tolower@plt>
movsbl %al,%eax
mov    0x4(%rsp),%ecx
add    %ecx,%eax
add    $0xffffffb9,%eax
movslq %eax,%rbp
imul   $0x4ec4ec4f,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%ebp
add    $0x41,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
jmp    1240 <fnEncryption+0xb0>

LLVM IR (-O0):
@.str = [8 x i8] c"out.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"Can not create the file\0A\00"
@.str.3 = [7 x i8] c"in.dat\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [23 x i8] c"Can not open the file\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.7 = [3 x i8] c"%c\00"
define void @fnEncryption() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %51
10: ; preds = %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %1
%12 = load i32*, i32** %1
%13 = icmp ne i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
br label %51
18: ; preds = %10
%19 = load i32*, i32** %1
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%21 = load i32*, i32** %1
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %4
br label %23
23: ; preds = %48, %18
%24 = load i32, i32* %4
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %51
27: ; preds = %23
%28 = load i32, i32* %4
%29 = call i64 @isalpha(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %27
%32 = load i32, i32* %4
%33 = call signext i8 @tolower(i32 %32)
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 97
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = add nsw i32 %36, %37
%39 = add nsw i32 %38, 26
%40 = srem i32 %39, 26
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 65
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = load i32*, i32** %2
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 65
%47 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %31, %27
%49 = load i32*, i32** %1
%50 = call i32 @fgetc(i32* %49)
store i32 %50, i32* %4
br label %23
51: ; preds = %8, %14, %23
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"out.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"in.dat\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%d\00"
@EOF = global i32 0
@str = [24 x i8] c"Can not create the file\00"
@str.8 = [22 x i8] c"Can not open the file\00"
define void @fnEncryption() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %36
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%12 = tail call i32 @fclose(i32* %3)
br label %36
13: ; preds = %7
%14 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%15 = call i32 @fgetc(i32* %8)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %36, label %18
18: ; preds = %13, %32
%19 = phi i32 [ %33, %32 ], [ %15, %13 ]
%20 = call i64 @isalpha(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %18
%23 = call signext i8 @tolower(i32 %19)
%24 = sext i8 %23 to i32
%25 = load i32, i32* %1
%26 = add nsw i32 %24, -71
%27 = add i32 %26, %25
%28 = srem i32 %27, 26
%29 = add nsw i32 %28, 65
%30 = call i32 @putchar(i32 %29)
%31 = call i32 @fputc(i32 %29, i32* %3)
br label %32
32: ; preds = %22, %18
%33 = call i32 @fgetc(i32* %8)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %18
36: ; preds = %32, %13, %10, %5
ret void
}