#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 test_abi_endian(void) {
  int result = 1;
  {
    int expect;
    union {
      short s;
      unsigned char c[sizeof(short)];
    } x;
    x.s = 1;
    expect = (x.c[0] == 1 ? 1234 : 4321);
    printf("C "
           "KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]",
           expect, 1234);
    if (1234 == expect) {
      printf(", PASSED\n");
    } else {
      printf(", FAILED\n");
      result = 0;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<test_abi_endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
movw   $0x1,-0x10(%rbp)
movzbl -0x10(%rbp),%edx
mov    $0x10e1,%eax
mov    $0x4d2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x4d2,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x4d2,%eax
cmp    -0x8(%rbp),%eax
jne    1173 <test_abi_endian+0x63>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1188 <test_abi_endian+0x78>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_abi_endian>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x4d2,%esi
mov    $0x4d2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%union.anon = type { i16 }
@.str = [47 x i8] c"C KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]\00"
@.str.1 = [10 x i8] c", PASSED\0A\00"
@.str.2 = [10 x i8] c", FAILED\0A\00"
define i32 @test_abi_endian() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %union.anon
store i32 1, i32* %1
%4 = bitcast %union.anon* %3 to i16*
store i16 1, i16* %4
%5 = bitcast %union.anon* %3 to [2 x i8]*
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 1234, i32 4321
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %12, i32 1234)
%14 = load i32, i32* %2
%15 = icmp eq i32 1234, %14
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [47 x i8] c"C KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]\00"
@str = [9 x i8] c", PASSED\00"
define i32 @test_abi_endian() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 1234, i32 1234)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 1
}