#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(float *, int, int, int /*<<< orphan*/ *);
float *malloc(int);
int /*<<< orphan*/ printf(char *, char const *);
float *read_hdr(const char *filename, int width, int height) {
  int i;
  float *data = NULL;
  FILE *fp;
  fp = fopen(filename, "rb");
  if (!fp) {
    printf("can't open %s\n", filename);
  }
  data = malloc(sizeof(float) * width * height * 3);
  if (!data)
    exit(-1);
  fread(data, sizeof(float), width * height * 3, fp);
  fclose(fp);
  return data;
}


x86 assembly (clang, -O0):
<read_hdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <read_hdr+0x49>
mov    -0x8(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0x10(%rbp),%rcx
imul   %rcx,%rax
imul   $0x3,%rax,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dd <read_hdr+0x7d>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   $0x3,%eax,%edx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hdr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%rbp
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1192 <read_hdr+0x32>
lea    0xe79(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
imul   %r15d,%ebx
lea    0x0(,%rbx,4),%eax
lea    (%rax,%rax,2),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d6 <read_hdr+0x76>
mov    %rax,%rbp
lea    (%rbx,%rbx,2),%edx
mov    %rax,%rdi
mov    $0x4,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define float* @read_hdr(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store float* null, float** %8
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = mul i64 4, %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %20, %22
%24 = mul i64 %23, 3
%25 = trunc i64 %24 to i32
%26 = call float* @malloc(i32 %25)
store float* %26, float** %8
%27 = load float*, float** %8
%28 = icmp ne float* %27, null
br i1 %28, label %31, label %29
29: ; preds = %17
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %17
%32 = load float*, float** %8
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = mul nsw i32 %33, %34
%36 = mul nsw i32 %35, 3
%37 = load i32*, i32** %9
%38 = call i32 @fread(float* %32, i32 4, i32 %36, i32* %37)
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
%41 = load float*, float** %8
ret float* %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define noalias float* @read_hdr(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = mul i32 %1, 12
%10 = mul i32 %9, %2
%11 = tail call float* @malloc(i32 %10)
%12 = icmp eq float* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %8
%16 = mul i32 %2, 3
%17 = mul i32 %16, %1
%18 = tail call i32 @fread(float* %11, i32 4, i32 %17, i32* %4)
%19 = tail call i32 @fclose(i32* %4)
ret float* %11
}