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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int main() {
  union {
    u_int16_t i;
    u_int8_t c[2];
  } u;
  FILE *f;
  u.i = 0xAFFE;
  f = fopen("endianess.h", "w+");
  if (u.c[0] == 0xAF) {
    fprintf(f, "#define WORDS_BIGENDIAN 1\n");
  } else {
    fprintf(f, "#define WORDS_LITTLEENDIAN 1\n");
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xaffe,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0xaf,-0x10(%rbp)
jne    117f <main+0x4f>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
jmp    118f <main+0x5f>
mov    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
lea    0xec1(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { [2 x i32] }
@.str = [12 x i8] c"endianess.h\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [27 x i8] c"#define WORDS_BIGENDIAN 1\0A\00"
@.str.3 = [30 x i8] c"#define WORDS_LITTLEENDIAN 1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %union.anon
%3 = alloca i32*
store i32 0, i32* %1
%4 = bitcast %union.anon* %2 to i32*
store i32 45054, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = bitcast %union.anon* %2 to [2 x i32]*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 175
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32*, i32** %3
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %16
13: ; preds = %0
%14 = load i32*, i32** %3
%15 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"endianess.h\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.3 = [30 x i8] c"#define WORDS_LITTLEENDIAN 1\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 29, i64 1, i32* %1)
%3 = tail call i32 @fclose(i32* %1)
ret i32 0
}