#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*/ printf(char *, ...);
char tolower(int);
void fnDecryption() {
  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;
  }
  ch = fgetc(pf);
  key = (tolower(ch) - 'c' + 26) % 26;
  printf("%d\n", key);
  fprintf(pfo, "%d\n", key);
  while (ch != EOF) {
    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):
<fnDecryption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <fnDecryption+0x3d>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1299 <fnDecryption+0x139>
lea    0xe7f(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11db <fnDecryption+0x7b>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1299 <fnDecryption+0x139>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
sub    $0x63,%eax
add    $0x1a,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe21(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%eax
je     1299 <fnDecryption+0x139>
mov    -0x18(%rbp),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1a,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%esi
add    $0x41,%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
add    $0x41,%edx
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
jmp    1227 <fnDecryption+0xc7>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnDecryption>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b0 <fnDecryption+0x120>
mov    %rax,%r14
lea    0xe49(%rip),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12ca <fnDecryption+0x13a>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   10a0 <tolower@plt>
movsbl %al,%eax
add    $0xffffffb7,%eax
imul   $0x4ec5,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x13,%ecx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
movswl %ax,%r15d
lea    0xdfe(%rip),%r12
mov    %r12,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1090 <fprintf@plt>
mov    0x2db1(%rip),%r12
cmp    (%r12),%ebp
je     12a1 <fnDecryption+0x111>
mov    $0xffffffb9,%ebx
sub    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   10a0 <tolower@plt>
movsbl %al,%eax
add    %ebx,%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>
mov    %r13,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1250 <fnDecryption+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd60(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xd5e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>

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 = [4 x i8] c"%d\0A\00"
@EOF = global i32 0
@.str.7 = [3 x i8] c"%c\00"
define void @fnDecryption() {
%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 %55
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 %55
18: ; preds = %10
%19 = load i32*, i32** %1
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call signext i8 @tolower(i32 %21)
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 99
%25 = add nsw i32 %24, 26
%26 = srem i32 %25, 26
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %2
%30 = load i32, i32* %3
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %36, %18
%33 = load i32, i32* %4
%34 = load i32, i32* @EOF
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = load i32, i32* %4
%38 = call signext i8 @tolower(i32 %37)
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 97
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = sub nsw i32 %41, %42
%44 = add nsw i32 %43, 26
%45 = srem i32 %44, 26
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 65
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %2
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 65
%52 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = load i32*, i32** %1
%54 = call i32 @fgetc(i32* %53)
store i32 %54, i32* %4
br label %32
55: ; preds = %8, %14, %32
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 = [4 x i8] c"%d\0A\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 @fnDecryption() {
%1 = 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))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %36
5: ; preds = %0
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %1)
br label %36
11: ; preds = %5
%12 = tail call i32 @fgetc(i32* %6)
%13 = tail call signext i8 @tolower(i32 %12)
%14 = sext i8 %13 to i16
%15 = add nsw i16 %14, -73
%16 = srem i16 %15, 26
%17 = sext i16 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%19 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %12, %20
br i1 %21, label %36, label %22
22: ; preds = %11
%23 = sub nsw i32 -71, %17
br label %24
24: ; preds = %22, %24
%25 = phi i32 [ %12, %22 ], [ %33, %24 ]
%26 = tail call signext i8 @tolower(i32 %25)
%27 = sext i8 %26 to i32
%28 = add nsw i32 %23, %27
%29 = srem i32 %28, 26
%30 = add nsw i32 %29, 65
%31 = tail call i32 @putchar(i32 %30)
%32 = tail call i32 @fputc(i32 %30, i32* %1)
%33 = tail call i32 @fgetc(i32* %6)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %24
36: ; preds = %24, %11, %8, %3
ret void
}