#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*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
unsigned char *readBMP(char *filename) {
  int i;
  FILE *f = fopen(filename, "rb");
  unsigned char info[54];
  fread(info, sizeof(unsigned char), 54, f);
  int width = *(int *)&info[18];
  int height = *(int *)&info[22];
  int size = 3 * width * height;
  unsigned char *data = malloc(sizeof(unsigned char) * size);
  fread(data, sizeof(unsigned char), size, f);
  fclose(f);
  return data;
}


x86 assembly (clang, -O0):
<readBMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x36,%edx
call   1030 <fread@plt>
mov    -0x3e(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x3a(%rbp),%eax
mov    %eax,-0x58(%rbp)
imul   $0x3,-0x54(%rbp),%eax
imul   -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movslq -0x5c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x5c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x68(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBMP>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x36,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x12(%rsp),%eax
imul   0x16(%rsp),%eax
lea    (%rax,%rax,2),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @readBMP(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [54 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %4
%12 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32 @fread(i8* %12, i32 1, i32 54, i32* %13)
%15 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 18
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %6
%18 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 22
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = mul nsw i32 3, %21
%23 = load i32, i32* %7
%24 = mul nsw i32 %22, %23
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = load i32, i32* %8
%32 = load i32*, i32** %4
%33 = call i32 @fread(i8* %30, i32 1, i32 %31, i32* %32)
%34 = load i32*, i32** %4
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %9
ret i8* %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define noalias i8* @readBMP(i8* nocapture %0) {
%2 = alloca [54 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [54 x i8], [54 x i8]* %2, i64 0, i64 0
%5 = call i32 @fread(i8* %4, i32 1, i32 54, i32* %3)
%6 = getelementptr inbounds [54 x i8], [54 x i8]* %2, i64 0, i64 18
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
%9 = getelementptr inbounds [54 x i8], [54 x i8]* %2, i64 0, i64 22
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = mul nsw i32 %8, 3
%13 = mul nsw i32 %12, %11
%14 = tail call i8* @malloc(i32 %13)
%15 = tail call i32 @fread(i8* %14, i32 1, i32 %13, i32* %3)
%16 = tail call i32 @fclose(i32* %3)
ret i8* %14
}