#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*/ test;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char, ...);
int /*<<< orphan*/ printf(char const *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  const char *output_format;
  union {
    unsigned char bytes[sizeof(int)];
    unsigned int i32val;
    struct {
      unsigned short a;
      unsigned short b;
    } i16val;
  } test;
  if (argc == 2)
    output_format = argv[1];
  else
    output_format = "-D%s";
  if (sizeof(int) != sizeof(test)) {
    fprintf(stderr, "Error: Size of int is %i; size of union is %i!\n",
            sizeof(int), sizeof(test));
    exit(1);
  }
  if (sizeof(int) != 4) {
    fprintf(stderr, "Error: Size of int is %i; expecting 4\n", sizeof(int));
    exit(2);
  }
  test.bytes[0] = (char)0x12;
  test.bytes[1] = (char)0x34;
  test.bytes[2] = (char)0x56;
  test.bytes[3] = (char)0x78;
  switch (test.i32val) {
  case 0x12345678:
    printf(output_format, "BIG_ENDIAN");
    break;
  case 0x78563412:
    printf(output_format, "LITTLE_ENDIAN");
    break;
  default:
    fprintf(stderr, "Error: Unknown endianness; %02x,%02x,%02x,%02x = %08x\n",
            test.bytes[0], test.bytes[1], test.bytes[2], test.bytes[3],
            test.i32val);
    exit(3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1161 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    116c <main+0x3c>
lea    0xe98(%rip),%rax
mov    %rax,-0x18(%rbp)
movb   $0x12,-0x20(%rbp)
movb   $0x34,-0x1f(%rbp)
movb   $0x56,-0x1e(%rbp)
movb   $0x78,-0x1d(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x12345678,%eax
je     11a5 <main+0x75>
jmp    1192 <main+0x62>
mov    -0x24(%rbp),%eax
sub    $0x78563412,%eax
je     11ba <main+0x8a>
jmp    11cf <main+0x9f>
mov    -0x18(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <printf@plt>
jmp    120a <main+0xda>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1030 <printf@plt>
jmp    120a <main+0xda>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%dl
movzbl -0x1f(%rbp),%ecx
movzbl -0x1e(%rbp),%r8d
movzbl -0x1d(%rbp),%r9d
mov    -0x20(%rbp),%eax
lea    0xe2b(%rip),%rsi
movsbl %dl,%edx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    111c <main+0xc>
mov    0x8(%rsi),%rdi
jmp    1123 <main+0x13>
lea    0xedd(%rip),%rdi
lea    0xedb(%rip),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%union.anon = type { i32 }
@.str = [5 x i8] c"-D%s\00"
@.str.1 = [11 x i8] c"BIG_ENDIAN\00"
@.str.2 = [14 x i8] c"LITTLE_ENDIAN\00"
@stderr = global i32 0
@.str.3 = [55 x i8] c"Error: Unknown endianness; %02x,%02x,%02x,%02x = %08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %union.anon
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
br label %15
14: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
br label %15
15: ; preds = %14, %10
%16 = bitcast %union.anon* %7 to [4 x i8]*
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %16, i64 0, i64 0
store i8 18, i8* %17
%18 = bitcast %union.anon* %7 to [4 x i8]*
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 1
store i8 52, i8* %19
%20 = bitcast %union.anon* %7 to [4 x i8]*
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %20, i64 0, i64 2
store i8 86, i8* %21
%22 = bitcast %union.anon* %7 to [4 x i8]*
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %22, i64 0, i64 3
store i8 120, i8* %23
%24 = bitcast %union.anon* %7 to i32*
%25 = load i32, i32* %24
switch i32 %25, label %32 [
i32 305419896, label %26
i32 2018915346, label %29
]
26: ; preds = %15
%27 = load i8*, i8** %6
%28 = call i32 @printf(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %53
29: ; preds = %15
%30 = load i8*, i8** %6
%31 = call i32 @printf(i8* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %53
32: ; preds = %15
%33 = load i32, i32* @stderr
%34 = bitcast %union.anon* %7 to [4 x i8]*
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %34, i64 0, i64 0
%36 = load i8, i8* %35
%37 = bitcast %union.anon* %7 to [4 x i8]*
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %37, i64 0, i64 1
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = bitcast %union.anon* %7 to [4 x i8]*
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %41, i64 0, i64 2
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = bitcast %union.anon* %7 to [4 x i8]*
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %45, i64 0, i64 3
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = bitcast %union.anon* %7 to i32*
%50 = load i32, i32* %49
%51 = call i32 (i32, i8*, i8, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i8 signext %36, i32 %40, i32 %44, i32 %48, i32 %50)
%52 = call i32 @exit(i32 3)
unreachable
53: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"-D%s\00"
@.str.2 = [14 x i8] c"LITTLE_ENDIAN\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %4, %2
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = tail call i32 @printf(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}