#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*/ encrypt(char *, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int main() {
  FILE *file;
  char *buffer;
  char filename[] = "text.txt";
  int size, i;
  char c;
  size = 0, i = 0;
  c = '0';
  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) {
    buffer[i++] = c;
    printf("%c", c);
  }
  buffer[i] = '\0';
  fclose(file);
  encrypt(buffer, i, filename);
  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,-0x21(%rbp)
mov    0xe58(%rip),%al
mov    %al,-0x19(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x30,-0x2d(%rbp)
lea    -0x21(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fc <main+0x6c>
lea    0xe20(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cd <main+0x13d>
mov    -0x10(%rbp),%rdi
mov    0x2de1(%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    0x2da7(%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    0x2d77(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a1 <main+0x111>
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)
lea    0xd8b(%rip),%rdi
movsbl -0x2d(%rbp),%esi
call   1040 <printf@plt>
jmp    1253 <main+0xc3>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x21(%rbp),%rdx
call   1050 <encrypt@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movabs $0x7478742e74786574,%rax
74 78 74
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
lea    0xe53(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127e <main+0xee>
mov    %rax,%r14
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
movslq %ebp,%rbp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax,%rbp,1)
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2dc4(%rip),%rbp
cmp    0x0(%rbp),%al
je     1250 <main+0xc0>
xor    %ebx,%ebx
lea    0xdf4(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
movsbl %al,%esi
mov    %r12,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    1230 <main+0xa0>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <encrypt@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd86(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1271 <main+0xe1>

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

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