#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int littleEndian(void) {
  FILE *fp = fopen("endian", "rb");
  uint32_t bigHex[1];
  bigHex[0] = 0x3f800000;
  fseek(fp, 0, SEEK_SET);
  uint32_t readHex[1];
  float readFloat[1];
  fread(readFloat, sizeof(uint32_t), 1, fp);
  readHex[0] = *(uint32_t *)&readFloat[0];
  fclose(fp);
  int little = 0;
  if (*(uint32_t *)&readFloat[0] == bigHex[0]) {
    little = 1;
  } else if (*(uint32_t *)&readFloat[0] != bigHex[0]) {
    little = -1;
  }
  return little;
}


x86 assembly (clang, -O0):
<littleEndian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x3f800000,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11bf <littleEndian+0x7f>
movl   $0x1,-0x18(%rbp)
jmp    11d7 <littleEndian+0x97>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11d2 <littleEndian+0x92>
movl   $0xffffffff,-0x18(%rbp)
jmp    11d7 <littleEndian+0x97>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<littleEndian>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
cmpl   $0x3f800000,0xc(%rsp)
3f
sete   %al
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"endian\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @littleEndian() {
%1 = alloca i32*
%2 = alloca [1 x i32]
%3 = alloca [1 x i32]
%4 = alloca [1 x float]
%5 = alloca i32
%6 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
store i32 1065353216, i32* %7
%8 = load i32*, i32** %1
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %8, i32 0, i32 %9)
%11 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i32 @fread(float* %11, i32 4, i32 1, i32* %12)
%14 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%15 = bitcast float* %14 to i32*
%16 = load i32, i32* %15
%17 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 %16, i32* %17
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %5
%20 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%21 = bitcast float* %20 to i32*
%22 = load i32, i32* %21
%23 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %23
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %0
store i32 1, i32* %5
br label %36
27: ; preds = %0
%28 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%29 = bitcast float* %28 to i32*
%30 = load i32, i32* %29
%31 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 -1, i32* %5
br label %35
35: ; preds = %34, %27
br label %36
36: ; preds = %35, %26
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"endian\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @littleEndian() {
%1 = alloca [1 x float]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = load i32, i32* @SEEK_SET
%4 = tail call i32 @fseek(i32* %2, i32 0, i32 %3)
%5 = bitcast [1 x float]* %1 to i8*
%6 = getelementptr inbounds [1 x float], [1 x float]* %1, i64 0, i64 0
%7 = call i32 @fread(float* %6, i32 4, i32 1, i32* %2)
%8 = bitcast [1 x float]* %1 to i32*
%9 = tail call i32 @fclose(i32* %2)
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, 1065353216
%12 = select i1 %11, i32 1, i32 -1
ret i32 %12
}