#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void readNumOfBytes(FILE *fp, int size, unsigned char *p_buffer) {
  static int bytesRead = 0;
  int flag = 0;
  int oldSize = 0;
  printf("First entering funcall:\nsize = %d\nbytesRead = %d\n", size,
         bytesRead);
  if (size > 0) {
    p_buffer = (unsigned char *)malloc(sizeof(unsigned char) * size);
    if (fp == NULL)
      printf("Sorry, file does not exist!\n\n");
    else {
      fread(p_buffer, 1, size, fp);
      if (feof(fp)) {
        oldSize = size;
        size = ftell(fp);
        flag = 1;
      }
      if (flag) {
        if (bytesRead >= size) {
          size = 0;
          printf("\nError: File ran out of data!\n");
        } else {
          printf("Sorry, there was less than %d bytes of data in the file!\n",
                 oldSize);
          printf("The size was adjusted accordingly...\n\n");
          size -= bytesRead;
        }
      }
      for (int i = 0; i < size && i >= 0; i++) {
        printf("%02x ", p_buffer[i]);
        if (!((i + 1) % 10))
          printf("\n");
      }
      printf("\n\n\n");
      bytesRead += size;
    }
  }
}


x86 assembly (clang, -O0):
<readNumOfBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%esi
mov    0x2ed2(%rip),%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    130f <readNumOfBytes+0x1bf>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c3 <readNumOfBytes+0x73>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130a <readNumOfBytes+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1204 <readNumOfBytes+0xb4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1269 <readNumOfBytes+0x119>
mov    0x2e38(%rip),%eax
cmp    -0xc(%rbp),%eax
jl     1237 <readNumOfBytes+0xe7>
movl   $0x0,-0xc(%rbp)
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <readNumOfBytes+0x114>
mov    -0x20(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df0(%rip),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1269 <readNumOfBytes+0x119>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    128b <readNumOfBytes+0x13b>
cmpl   $0x0,-0x24(%rbp)
setge  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    129b <readNumOfBytes+0x14b>
jmp    12ed <readNumOfBytes+0x19d>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12da <readNumOfBytes+0x18a>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12df <readNumOfBytes+0x18f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1270 <readNumOfBytes+0x120>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    0x2d48(%rip),%eax
mov    %eax,0x2d42(%rip)
jmp    130f <readNumOfBytes+0x1bf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNumOfBytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2ed5(%rip),%edx
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    12b9 <readNumOfBytes+0x149>
mov    %r15d,%edi
call   1090 <malloc@plt>
test   %rbx,%rbx
je     127d <readNumOfBytes+0x10d>
mov    %rax,%r14
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     121b <readNumOfBytes+0xab>
mov    %rbx,%rdi
call   1070 <ftell@plt>
cmp    %eax,0x2e77(%rip)
jge    1297 <readNumOfBytes+0x127>
mov    %eax,%r13d
lea    0xe3d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
sub    0x2e4a(%rip),%r13d
mov    %r13d,%r15d
jle    12a6 <readNumOfBytes+0x136>
mov    %r15d,%r13d
xor    %r12d,%r12d
jmp    1238 <readNumOfBytes+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    %r12,%r13
je     12a6 <readNumOfBytes+0x136>
mov    %r12,%rbx
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%r15d
add    $0xffffffff,%r15d
movzbl (%r14,%r12,1),%esi
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12
cmp    %ebx,%r15d
jne    1230 <readNumOfBytes+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1230 <readNumOfBytes+0xc0>
lea    0xe35(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xdfd(%rip),%rdi
call   1040 <puts@plt>
xor    %r13d,%r13d
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
add    %r13d,0x2da3(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@readNumOfBytes.bytesRead = internal global i32 0
@.str = [50 x i8] c"First entering funcall:\0Asize = %d\0AbytesRead = %d\0A\00"
@.str.1 = [30 x i8] c"Sorry, file does not exist!\0A\0A\00"
@.str.2 = [31 x i8] c"\0AError: File ran out of data!\0A\00"
@.str.3 = [58 x i8] c"Sorry, there was less than %d bytes of data in the file!\0A\00"
@.str.4 = [39 x i8] c"The size was adjusted accordingly...\0A\0A\00"
@.str.5 = [6 x i8] c"%02x \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [4 x i8] c"\0A\0A\0A\00"
define void @readNumOfBytes(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* @readNumOfBytes.bytesRead
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %89
15: ; preds = %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
%22 = load i32*, i32** %4
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %88
26: ; preds = %15
%27 = load i8*, i8** %6
%28 = load i32, i32* %5
%29 = load i32*, i32** %4
%30 = call i32 @fread(i8* %27, i32 1, i32 %28, i32* %29)
%31 = load i32*, i32** %4
%32 = call i64 @feof(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32, i32* %5
store i32 %35, i32* %8
%36 = load i32*, i32** %4
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %5
store i32 1, i32* %7
br label %38
38: ; preds = %34, %26
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %38
%42 = load i32, i32* @readNumOfBytes.bytesRead
%43 = load i32, i32* %5
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
store i32 0, i32* %5
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %54
47: ; preds = %41
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* @readNumOfBytes.bytesRead
%52 = load i32, i32* %5
%53 = sub nsw i32 %52, %51
store i32 %53, i32* %5
br label %54
54: ; preds = %47, %45
br label %55
55: ; preds = %54, %38
store i32 0, i32* %9
br label %56
56: ; preds = %80, %55
%57 = load i32, i32* %9
%58 = load i32, i32* %5
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i32, i32* %9
%62 = icmp sge i32 %61, 0
br label %63
63: ; preds = %60, %56
%64 = phi i1 [ false, %56 ], [ %62, %60 ]
br i1 %64, label %65, label %83
65: ; preds = %63
%66 = load i8*, i8** %6
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
%75 = srem i32 %74, 10
%76 = icmp ne i32 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %65
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %79
79: ; preds = %77, %65
br label %80
80: ; preds = %79
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %56
83: ; preds = %63
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%85 = load i32, i32* %5
%86 = load i32, i32* @readNumOfBytes.bytesRead
%87 = add nsw i32 %86, %85
store i32 %87, i32* @readNumOfBytes.bytesRead
br label %88
88: ; preds = %83, %24
br label %89
89: ; preds = %88, %3
ret void
}

LLVM IR (-O2):
@readNumOfBytes.bytesRead = internal unnamed_addr global i32 0
@.str = [50 x i8] c"First entering funcall:\0Asize = %d\0AbytesRead = %d\0A\00"
@.str.3 = [58 x i8] c"Sorry, there was less than %d bytes of data in the file!\0A\00"
@.str.5 = [6 x i8] c"%02x \00"
@str = [3 x i8] c"\0A\0A\00"
@str.8 = [38 x i8] c"The size was adjusted accordingly...\0A\00"
@str.9 = [30 x i8] c"\0AError: File ran out of data!\00"
@str.10 = [29 x i8] c"Sorry, file does not exist!\0A\00"
define void @readNumOfBytes(i32* %0, i32 %1, i8* nocapture readnone %2) {
%4 = load i32, i32* @readNumOfBytes.bytesRead
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %51
7: ; preds = %3
%8 = tail call i64 @malloc(i32 %1)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i32* %0, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
br label %51
13: ; preds = %7
%14 = tail call i32 @fread(i8* %9, i32 1, i32 %1, i32* %0)
%15 = tail call i64 @feof(i32* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %13
%18 = tail call i32 @ftell(i32* %0)
%19 = load i32, i32* @readNumOfBytes.bytesRead
%20 = icmp slt i32 %19, %18
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.9, i64 0, i64 0))
br label %32
23: ; preds = %17
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.8, i64 0, i64 0))
%26 = load i32, i32* @readNumOfBytes.bytesRead
%27 = sub nsw i32 %18, %26
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %13, %23
%30 = phi i32 [ %27, %23 ], [ %1, %13 ]
%31 = zext i32 %30 to i64
br label %37
32: ; preds = %49, %21, %23
%33 = phi i32 [ %27, %23 ], [ 0, %21 ], [ %30, %49 ]
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%35 = load i32, i32* @readNumOfBytes.bytesRead
%36 = add nsw i32 %35, %33
store i32 %36, i32* @readNumOfBytes.bytesRead
br label %51
37: ; preds = %29, %49
%38 = phi i64 [ 0, %29 ], [ %43, %49 ]
%39 = getelementptr inbounds i8, i8* %9, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %38, 1
%44 = trunc i64 %43 to i32
%45 = urem i32 %44, 10
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = tail call i32 @putchar(i32 10)
br label %49
49: ; preds = %37, %47
%50 = icmp eq i64 %43, %31
br i1 %50, label %32, label %37
51: ; preds = %11, %32, %3
ret void
}