#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*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(void *, size_t, size_t, int /*<<< orphan*/ *);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
void *readFile(size_t size, size_t count, FILE *file) {
  void *output;
  output = malloc(size * count);
  if (output == NULL) {
    fprintf(stderr, "Could not allocate enough bytes to read into memory\n");
    return NULL;
  }
  if (fread(output, size, count, file) != count) {
    fprintf(stderr,
            "WARNING: Could not read as many bytes as requested from file\n");
  }
  return output;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
imul   -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <readFile+0x53>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11bf <readFile+0x8f>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <fread@plt>
cmp    -0x18(%rbp),%rax
je     11b7 <readFile+0x87>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
imul   %r12,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1174 <readFile+0x44>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    %rbx,%rax
je     1189 <readFile+0x59>
lea    0xec3(%rip),%rsi
jmp    117b <readFile+0x4b>
lea    0xe85(%rip),%rsi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Could not allocate enough bytes to read into memory\0A\00"
@.str.1 = [62 x i8] c"WARNING: Could not read as many bytes as requested from file\0A\00"
define i8* @readFile(i64 %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = mul i64 %9, %10
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %31
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = load i64, i64* %5
%21 = load i64, i64* %6
%22 = load i32*, i32** %7
%23 = call i64 @fread(i8* %19, i64 %20, i64 %21, i32* %22)
%24 = load i64, i64* %6
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %18
%30 = load i8*, i8** %8
store i8* %30, i8** %4
br label %31
31: ; preds = %29, %15
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Could not allocate enough bytes to read into memory\0A\00"
@.str.1 = [62 x i8] c"WARNING: Could not read as many bytes as requested from file\0A\00"
define noalias i8* @readFile(i64 %0, i64 %1, i32* nocapture %2) {
%4 = mul i64 %1, %0
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i64 @fread(i8* %5, i64 %0, i64 %1, i32* %2)
%9 = icmp eq i64 %8, %1
br i1 %9, label %14, label %10
10: ; preds = %7, %3
%11 = phi i8* [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), %7 ]
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* %11)
br label %14
14: ; preds = %10, %7
ret i8* %5
}