#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 CheckEnd();
int EXIT_SUCCESS;
int check_end();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  short int x;
  char x0, x1;
  x = 0x1122;
  x0 = ((char *)&x)[0];
  x1 = ((char *)&x)[1];
  printf("x0 = 0x%x, x1 = 0x%x\n", x0, x1);
  if (x0 == 0x22 && x1 == 0x11) {
    printf("小端\n");
  } else {
    printf("大端\n");
  }
  if (check_end() == 1) {
    printf("大端\n");
  } else {
    printf("小端\n");
  }
  if (CheckEnd() == 1) {
    printf("大端\n");
  } else {
    printf("小端\n");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x1122,-0x6(%rbp)
mov    -0x6(%rbp),%al
mov    %al,-0x7(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x8(%rbp)
movsbl -0x7(%rbp),%esi
movsbl -0x8(%rbp),%edx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x7(%rbp),%eax
cmp    $0x22,%eax
jne    1194 <main+0x64>
movsbl -0x8(%rbp),%eax
cmp    $0x11,%eax
jne    1194 <main+0x64>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11a2 <main+0x72>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <check_end@plt>
cmp    $0x1,%eax
jne    11c5 <main+0x95>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d3 <main+0xa3>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <CheckEnd@plt>
cmp    $0x1,%eax
jne    11f6 <main+0xc6>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1204 <main+0xd4>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
mov    $0x22,%esi
mov    $0x11,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeb3(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1040 <check_end@plt>
cmp    $0x1,%eax
lea    0xea1(%rip),%r14
mov    %rbx,%rdi
cmove  %r14,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <CheckEnd@plt>
cmp    $0x1,%eax
cmove  %r14,%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"x0 = 0x%x, x1 = 0x%x\0A\00"
@.str.1 = [8 x i8] c"\E5\B0\8F\E7\AB\AF\0A\00"
@.str.2 = [8 x i8] c"\E5\A4\A7\E7\AB\AF\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8
%4 = alloca i8
store i32 0, i32* %1
store i16 4386, i16* %2
%5 = bitcast i16* %2 to i8*
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
store i8 %7, i8* %3
%8 = bitcast i16* %2 to i8*
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
store i8 %10, i8* %4
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 34
br i1 %18, label %19, label %25
19: ; preds = %0
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 17
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %27
25: ; preds = %19, %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = call i32 (...) @check_end()
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = call i32 (...) @CheckEnd()
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@.str = [22 x i8] c"x0 = 0x%x, x1 = 0x%x\0A\00"
@EXIT_SUCCESS = global i32 0
@str.4 = [7 x i8] c"\E5\B0\8F\E7\AB\AF\00"
@str.6 = [7 x i8] c"\E5\A4\A7\E7\AB\AF\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 34, i32 17)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0))
%3 = tail call i32 (...) @check_end()
%4 = icmp eq i32 %3, 1
%5 = select i1 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 (...) @CheckEnd()
%8 = icmp eq i32 %7, 1
%9 = select i1 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0)
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}