#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 (2 != sizeof(short)) {
    printf("sizeof(short) = %ld.\n", sizeof(short));
    return -1;
  }
  if (0x01 == un.c[0] && 0x02 == un.c[1]) {
    printf("big-endian.\n");
  } else if (0x02 == un.c[0] && 0x01 == un.c[1]) {
    printf("little-endian.\n");
  } else {
    printf("unknown.\n");
  }
  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),%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    115a <main+0x4a>
movsbl -0x7(%rbp),%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
jne    115a <main+0x4a>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <main+0x92>
movsbl -0x8(%rbp),%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
jne    118f <main+0x7f>
movsbl -0x7(%rbp),%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    118f <main+0x7f>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119d <main+0x8d>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <main+0x92>
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 = [13 x i8] c"big-endian.\0A\00"
@.str.1 = [16 x i8] c"little-endian.\0A\00"
@.str.2 = [10 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 1, %7
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 2, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 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 2, %21
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 1, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %33
31: ; preds = %23, %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 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 = [15 x i8] c"little-endian.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret i32 0
}