#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*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ readNumOfBytes(int /*<<< orphan*/ *, int, unsigned char *);
int main(void) {
  FILE *fp;
  unsigned char *p_buffer;
  int size = 1;
  fp = fopen("./mnt/random", "r");
  printf("\n\nReading %d bytes from file...\n\n", size);
  readNumOfBytes(fp, size, p_buffer);
  size = 1;
  printf("\n\nReading %d bytes from file...\n\n", size);
  readNumOfBytes(fp, size, p_buffer);
  size = 1;
  printf("\n\nReading %d bytes from file...\n\n", size);
  readNumOfBytes(fp, size, p_buffer);
  size = 1;
  printf("\n\nReading %d bytes from file...\n\n", size);
  readNumOfBytes(fp, size, p_buffer);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <readNumOfBytes@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <readNumOfBytes@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <readNumOfBytes@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <readNumOfBytes@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <readNumOfBytes@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <readNumOfBytes@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <readNumOfBytes@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <readNumOfBytes@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"./mnt/random\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"\0A\0AReading %d bytes from file...\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 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* %4
%7 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32*, i32** %2
%9 = load i32, i32* %4
%10 = load i8*, i8** %3
%11 = call i32 @readNumOfBytes(i32* %8, i32 %9, i8* %10)
store i32 1, i32* %4
%12 = load i32, i32* %4
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32*, i32** %2
%15 = load i32, i32* %4
%16 = load i8*, i8** %3
%17 = call i32 @readNumOfBytes(i32* %14, i32 %15, i8* %16)
store i32 1, i32* %4
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = call i32 @readNumOfBytes(i32* %20, i32 %21, i8* %22)
store i32 1, i32* %4
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %2
%27 = load i32, i32* %4
%28 = load i8*, i8** %3
%29 = call i32 @readNumOfBytes(i32* %26, i32 %27, i8* %28)
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"./mnt/random\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"\0A\0AReading %d bytes from file...\0A\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1)
%3 = tail call i32 @readNumOfBytes(i32* %1, i32 1, i8* undef)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1)
%5 = tail call i32 @readNumOfBytes(i32* %1, i32 1, i8* undef)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1)
%7 = tail call i32 @readNumOfBytes(i32* %1, i32 1, i8* undef)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1)
%9 = tail call i32 @readNumOfBytes(i32* %1, i32 1, i8* undef)
%10 = tail call i32 @fclose(i32* %1)
ret i32 0
}