#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ malloc(unsigned int);
unsigned int size_of_file(int /*<<< orphan*/ *);
int toupper(char);
unsigned int read_file(const char *fileName, char **pString) {
  char b, *String1;
  unsigned int i, size_file;
  FILE *file_string;
  file_string = fopen(fileName, "rb");
  size_file = size_of_file(file_string);
  String1 = (char *)malloc(size_file * sizeof(char));
  i = 0;
  while (!feof(file_string)) {
    b = fgetc(file_string);
    if (b) {
      String1[i] = (toupper(b) - 64) % 5;
      i++;
    }
  }
  *pString = String1;
  fclose(file_string);
  return i;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <size_of_file@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d7 <read_file+0x67>
jmp    1219 <read_file+0xa9>
mov    -0x30(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
cmpb   $0x0,-0x11(%rbp)
je     1214 <read_file+0xa4>
movsbl -0x11(%rbp),%edi
call   1030 <toupper@plt>
sub    $0x40,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b9 <read_file+0x49>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <size_of_file@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11c1 <read_file+0x51>
mov    %r15,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11dc <read_file+0x6c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11a9 <read_file+0x39>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
test   %al,%al
je     11d0 <read_file+0x60>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
add    $0xffffffc0,%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0xffffffc0,%eax
mov    %ebp,%ecx
mov    %al,(%r15,%rcx,1)
add    $0x1,%ebp
jmp    11d0 <read_file+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @read_file(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = call i32 @size_of_file(i32* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = zext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
store i32 0, i32* %7
br label %20
20: ; preds = %42, %2
%21 = load i32*, i32** %9
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i32*, i32** %9
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %5
%28 = load i8, i8* %5
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %25
%31 = load i8, i8* %5
%32 = call i32 @toupper(i8 signext %31)
%33 = sub nsw i32 %32, 64
%34 = srem i32 %33, 5
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %35, i8* %39
%40 = load i32, i32* %7
%41 = add i32 %40, 1
store i32 %41, i32* %7
br label %42
42: ; preds = %30, %25
br label %20
43: ; preds = %20
%44 = load i8*, i8** %6
%45 = load i8**, i8*** %4
store i8* %44, i8** %45
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @read_file(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @size_of_file(i32* %3)
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @feof(i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %2, %21
%10 = phi i32 [ %22, %21 ], [ 0, %2 ]
%11 = tail call signext i8 @fgetc(i32* %3)
%12 = icmp eq i8 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = tail call i32 @toupper(i8 signext %11)
%15 = add nsw i32 %14, -64
%16 = srem i32 %15, 5
%17 = trunc i32 %16 to i8
%18 = zext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 %17, i8* %19
%20 = add i32 %10, 1
br label %21
21: ; preds = %13, %9
%22 = phi i32 [ %20, %13 ], [ %10, %9 ]
%23 = tail call i32 @feof(i32* %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %9, label %25
25: ; preds = %21, %2
%26 = phi i32 [ 0, %2 ], [ %22, %21 ]
store i8* %6, i8** %1
%27 = tail call i32 @fclose(i32* %3)
ret i32 %26
}