#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 *read256BMPdata(char *filename) {
  FILE *f = fopen(filename, "rb");
  unsigned char info[1078];
  fread(info, sizeof(unsigned char), 1078, f);
  int width = *(int *)&info[18];
  int height = *(int *)&info[22];
  int size = width * height;
  unsigned char *data = malloc(sizeof(unsigned char) * size);
  fread(data, sizeof(unsigned char), size, f);
  fclose(f);
  int row = 0, col = 0;
  return data;
}


x86 assembly (clang, -O0):
<read256BMPdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x450(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x436,%edx
call   1030 <fread@plt>
mov    -0x43e(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    -0x43a(%rbp),%eax
mov    %eax,-0x458(%rbp)
mov    -0x454(%rbp),%eax
imul   -0x458(%rbp),%eax
mov    %eax,-0x45c(%rbp)
movslq -0x45c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x468(%rbp)
mov    -0x468(%rbp),%rdi
mov    -0x45c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x46c(%rbp)
movl   $0x0,-0x470(%rbp)
mov    -0x468(%rbp),%rax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read256BMPdata>:
push   %rbp
push   %r14
push   %rbx
sub    $0x440,%rsp
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x436,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x16(%rsp),%ebp
imul   0x12(%rsp),%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    $0x440,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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