#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*/ byteswap_4(float *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fopen_with_error(char const *, char *, char const *);
int /*<<< orphan*/ fread(float *, int, int, int /*<<< orphan*/ *);
scalar_t__ isMachineLittleEndian();
scalar_t__ malloc(int);
int /*<<< orphan*/ syserr(char const *, char const *, char *);
float *readferetraster(const char *fn, int numpix) {
  const char *routine = "readferetraster";
  FILE *fp;
  float *data;
  fp = (FILE *)fopen_with_error(fn, "rb", routine);
  data = (float *)malloc(sizeof(float) * numpix);
  if (!data) {
    syserr("readferetraster", "malloc of data failed", "");
  }
  if (!fread(data, sizeof(float), numpix, fp))
    syserr(routine, fn, "fread");
  if (isMachineLittleEndian())
    byteswap_4(data, numpix);
  fclose(fp);
  return data;
}


x86 assembly (clang, -O0):
<readferetraster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1070 <fopen_with_error@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11da <readferetraster+0x6a>
lea    0xe39(%rip),%rdi
lea    0xe45(%rip),%rsi
lea    0xe3d(%rip),%rdx
call   1050 <syserr@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    120c <readferetraster+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xe22(%rip),%rdx
call   1050 <syserr@plt>
mov    $0x0,%al
call   1060 <isMachineLittleEndian@plt>
cmp    $0x0,%rax
je     1229 <readferetraster+0xb9>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1090 <byteswap_4@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readferetraster>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
lea    0xe8b(%rip),%rsi
lea    0xe74(%rip),%rdx
call   1070 <fopen_with_error@plt>
mov    %rax,%r14
lea    0x0(,%r15,4),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c3 <readferetraster+0x53>
lea    0xe50(%rip),%rdi
lea    0xe5c(%rip),%rsi
lea    0xe54(%rip),%rdx
call   1050 <syserr@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jne    11f0 <readferetraster+0x80>
lea    0xe1f(%rip),%rdi
lea    0xe41(%rip),%rdx
mov    %r12,%rsi
call   1050 <syserr@plt>
xor    %eax,%eax
call   1060 <isMachineLittleEndian@plt>
test   %rax,%rax
je     1207 <readferetraster+0x97>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1090 <byteswap_4@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"readferetraster\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"malloc of data failed\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [6 x i8] c"fread\00"
define float* @readferetraster(i8* %0, i32 %1) {
%3 = tail call i64 @fopen_with_error(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = inttoptr i64 %3 to i32*
%5 = shl i32 %1, 2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to float*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @fread(float* %7, i32 4, i32 %1, i32* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = tail call i64 (...) @isMachineLittleEndian()
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @byteswap_4(float* %7, i32 %1)
br label %21
21: ; preds = %19, %16
%22 = tail call i32 @fclose(i32* %4)
ret float* %7
}