#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 *);
void byteorder() {
  union {
    short value;
    char union_bytes[sizeof(short)];
  } test;
  test.value = 0x102;
  if ((test.union_bytes[0] == 1) && (test.union_bytes[1] == 2)) {
    printf("big endian\n");
  } else if ((test.union_bytes[0] == 2) && (test.union_bytes[1] == 1)) {
    printf("little endian\n");
  } else {
    printf("unknown...\n");
  }
}


x86 assembly (clang, -O0):
<byteorder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movw   $0x102,-0x8(%rbp)
movsbl -0x8(%rbp),%eax
cmp    $0x1,%eax
jne    1149 <byteorder+0x39>
movsbl -0x7(%rbp),%eax
cmp    $0x2,%eax
jne    1149 <byteorder+0x39>
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <byteorder+0x75>
movsbl -0x8(%rbp),%eax
cmp    $0x2,%eax
jne    1174 <byteorder+0x64>
movsbl -0x7(%rbp),%eax
cmp    $0x1,%eax
jne    1174 <byteorder+0x64>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    1180 <byteorder+0x70>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <byteorder+0x75>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byteorder>:
lea    0xee9(%rip),%rdi
jmp    1030 <puts@plt>

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

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