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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int main() {
  union {
    short s;
    char c[sizeof(short)];
  } un;
  un.s = 0x0102;
  if (sizeof(short) == 2) {
    if (un.c[0] == 1 && un.c[1] == 2) {
      printf("big-endian\n");
    } else if (un.c[0] == 2 && un.c[1] == 1) {
      printf("little-endian\n");
    } else {
      printf("unknown\n");
    }
  } else {
    printf("sizeof(short) = %lu\n", sizeof(short));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x102,-0x8(%rbp)
movsbl -0x8(%rbp),%eax
cmp    $0x1,%eax
jne    1152 <main+0x42>
movsbl -0x7(%rbp),%eax
cmp    $0x2,%eax
jne    1152 <main+0x42>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <main+0x82>
movsbl -0x8(%rbp),%eax
cmp    $0x2,%eax
jne    117f <main+0x6f>
movsbl -0x7(%rbp),%eax
cmp    $0x1,%eax
jne    117f <main+0x6f>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118d <main+0x7d>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <main+0x82>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%union.anon = type { i16 }
@.str = [12 x i8] c"big-endian\0A\00"
@.str.1 = [15 x i8] c"little-endian\0A\00"
@.str.2 = [9 x i8] c"unknown\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %union.anon
store i32 0, i32* %1
%3 = bitcast %union.anon* %2 to i16*
store i16 258, i16* %3
%4 = bitcast %union.anon* %2 to [2 x i8]*
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = bitcast %union.anon* %2 to [2 x i8]*
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %34
17: ; preds = %9, %0
%18 = bitcast %union.anon* %2 to [2 x i8]*
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %18, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %31
23: ; preds = %17
%24 = bitcast %union.anon* %2 to [2 x i8]*
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %24, i64 0, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %33
31: ; preds = %23, %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
br label %34
34: ; preds = %33, %15
ret i32 0
}

LLVM IR (-O2):
@str = [14 x i8] c"little-endian\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret i32 0
}