#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 */
char EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main() {
  FILE *file;
  char *buffer;
  char filename[] = "enctest.txt";
  int size, i;
  char c;
  size = 0, i = 0;
  c = '0';
  printf("THis is a test\n");
  file = fopen(filename, "r");
  if (file == NULL) {
    perror("Error opening file");
    return -1;
  }
  fseek(file, 0L, SEEK_END);
  size = ftell(file);
  fseek(file, 0L, SEEK_SET);
  buffer = (char *)malloc(size * sizeof(char));
  buffer[size] = '\0';
  while ((c = fgetc(file)) != EOF) {
    c = (c - 5);
    buffer[i++] = c;
  }
  buffer[i] = '\0';
  fputs(buffer, stdout);
  fclose(file);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xe58(%rip),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x30,-0x2d(%rbp)
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
lea    -0x24(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1208 <main+0x78>
lea    0xe27(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <main+0x145>
mov    -0x10(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
movslq -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%eax
mov    0x2d6b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a7 <main+0x117>
movsbl -0x2d(%rbp),%eax
sub    $0x5,%eax
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    125f <main+0xcf>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movabs $0x2e74736574636e65,%rax
73 74 2e
mov    %rax,(%rsp)
movl   $0x747874,0x8(%rsp)
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0xe46(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128d <main+0xfd>
mov    %rax,%r14
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebx
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
movslq %ebx,%r15
mov    %r15d,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
movb   $0x0,(%rax,%r15,1)
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2db1(%rip),%r15
cmp    (%r15),%al
je     125b <main+0xcb>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    $0xfb,%al
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
jne    1240 <main+0xb0>
mov    %ebx,%r12d
movb   $0x0,0x0(%r13,%r12,1)
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1050 <fputs@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd7a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    127f <main+0xef>

LLVM IR (-O0):
@__const.main.filename = [12 x i8] c"enctest.txt\00"
@.str = [16 x i8] c"THis is a test\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i8 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [12 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
%8 = bitcast [12 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
store i8 48, i8* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
16: ; preds = %0
%17 = load i32*, i32** %2
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i64 0, i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 @ftell(i32* %20)
store i32 %21, i32* %5
%22 = load i32*, i32** %2
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i64 0, i32 %23)
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %3
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %42, %16
%36 = load i32*, i32** %2
%37 = call signext i8 @fgetc(i32* %36)
store i8 %37, i8* %7
%38 = sext i8 %37 to i32
%39 = load i8, i8* @EOF
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %38, %40
br i1 %41, label %42, label %53
42: ; preds = %35
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 5
%46 = trunc i32 %45 to i8
store i8 %46, i8* %7
%47 = load i8, i8* %7
%48 = load i8*, i8** %3
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 %47, i8* %52
br label %35
53: ; preds = %35
%54 = load i8*, i8** %3
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %3
%59 = load i32, i32* @stdout
%60 = call i32 @fputs(i8* %58, i32 %59)
%61 = load i32*, i32** %2
%62 = call i32 @fclose(i32* %61)
store i32 1, i32* %1
br label %63
63: ; preds = %53, %14
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@__const.main.filename = [12 x i8] c"enctest.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i8 0
@stdout = global i32 0
@str = [15 x i8] c"THis is a test\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%4 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %38
8: ; preds = %0
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %4, i64 0, i32 %9)
%11 = tail call i32 @ftell(i32* %4)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %4, i64 0, i32 %12)
%14 = sext i32 %11 to i64
%15 = tail call i64 @malloc(i32 %11)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 %14
store i8 0, i8* %17
%18 = tail call signext i8 @fgetc(i32* %4)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %32, label %21
21: ; preds = %8, %21
%22 = phi i64 [ %25, %21 ], [ 0, %8 ]
%23 = phi i8 [ %27, %21 ], [ %18, %8 ]
%24 = add i8 %23, -5
%25 = add nuw i64 %22, 1
%26 = getelementptr inbounds i8, i8* %16, i64 %22
store i8 %24, i8* %26
%27 = tail call signext i8 @fgetc(i32* %4)
%28 = load i8, i8* @EOF
%29 = icmp eq i8 %27, %28
br i1 %29, label %30, label %21
30: ; preds = %21
%31 = and i64 %25, 4294967295
br label %32
32: ; preds = %30, %8
%33 = phi i64 [ 0, %8 ], [ %31, %30 ]
%34 = getelementptr inbounds i8, i8* %16, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* @stdout
%36 = tail call i32 @fputs(i8* %16, i32 %35)
%37 = tail call i32 @fclose(i32* %4)
br label %38
38: ; preds = %32, %6
%39 = phi i32 [ -1, %6 ], [ 1, %32 ]
ret i32 %39
}