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


x86 assembly (clang, -O0):
<writeferetraster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1060 <fopen_with_error@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <isMachineLittleEndian@plt>
cmp    $0x0,%rax
je     11b3 <writeferetraster+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <byteswap_4@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1080 <fwrite@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
je     11ef <writeferetraster+0x8f>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xe2a(%rip),%rdx
call   1040 <syserr@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeferetraster>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9b(%rip),%rsi
lea    0xe83(%rip),%rdx
call   1060 <fopen_with_error@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <isMachineLittleEndian@plt>
test   %rax,%rax
je     119b <writeferetraster+0x3b>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <byteswap_4@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
cmp    %ebp,%eax
je     11c7 <writeferetraster+0x67>
lea    0xe48(%rip),%rdi
lea    0xe55(%rip),%rdx
mov    %r14,%rsi
call   1040 <syserr@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"writeferetraster\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"fwrite\00"
define float* @writeferetraster(i8* %0, float* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store float* %1, float** %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %4
%10 = load i8*, i8** %7
%11 = call i64 @fopen_with_error(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %8
%13 = call i64 (...) @isMachineLittleEndian()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load float*, float** %5
%17 = load i32, i32* %6
%18 = call i32 @byteswap_4(float* %16, i32 %17)
br label %19
19: ; preds = %15, %3
%20 = load i32, i32* %6
%21 = load float*, float** %5
%22 = load i32, i32* %6
%23 = load i32*, i32** %8
%24 = call i32 @fwrite(float* %21, i32 4, i32 %22, i32* %23)
%25 = icmp ne i32 %20, %24
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = call i32 @syserr(i8* %27, i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %26, %19
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
%33 = load float*, float** %5
ret float* %33
}

LLVM IR (-O2):
@.str = [17 x i8] c"writeferetraster\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"fwrite\00"
define float* @writeferetraster(i8* %0, float* returned %1, i32 %2) {
%4 = 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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = inttoptr i64 %4 to i32*
%6 = tail call i64 (...) @isMachineLittleEndian()
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @byteswap_4(float* %1, i32 %2)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @fwrite(float* %1, i32 4, i32 %2, i32* %5)
%12 = icmp eq i32 %11, %2
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @syserr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @fclose(i32* %5)
ret float* %1
}