int main() {
  char *p0, *p1, *p2, *p3;
  int n, n0, n1, n2, n3;
  n = 0x01020304;
  p0 = ((char *)&n) + 0;
  p1 = ((char *)&n) + 1;
  p2 = ((char *)&n) + 2;
  p3 = ((char *)&n) + 3;
  n0 = (n & 0xff000000) >> 24;
  n1 = (n & 0x00ff0000) >> 16;
  n2 = (n & 0x0000ff00) >> 8;
  n3 = (n & 0x000000ff) >> 0;
  printf("Big/Little Endian Testing...\n");
  printf("n is at address: 0x%x with value: 0x%x\n", &n, n);
  printf("n is in sequence of [0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x]\n",
         p0, *p0, p1, *p1, p2, *p2, p3, *p3);
  if ((*p0 == n0) && (*p1 == n1) && (*p2 == n2) && (*p3 == n3))
    printf("Endian test : This is a big endian machine.\n");
  else if ((*p0 == n3) && (*p1 == n2) && (*p2 == n1) && (*p3 == n0))
    printf("Endian test : This is a little endian machine.\n");
  else
    printf("Endian test : This is a unknown endian machine.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1020304,-0x2c(%rbp)
lea    -0x2c(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x2c(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x2c(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
lea    -0x2c(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
sar    $0x0,%eax
mov    %eax,-0x3c(%rbp)
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%edx
lea    0xe7c(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%rax
movsbl (%rax),%r8d
mov    -0x20(%rbp),%r9
mov    -0x20(%rbp),%rax
movsbl (%rax),%r11d
mov    -0x28(%rbp),%r10
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
lea    0xe64(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x30(%rbp),%eax
jne    1249 <main+0x139>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x34(%rbp),%eax
jne    1249 <main+0x139>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x38(%rbp),%eax
jne    1249 <main+0x139>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x3c(%rbp),%eax
jne    1249 <main+0x139>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12af <main+0x19f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x3c(%rbp),%eax
jne    129c <main+0x18c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x38(%rbp),%eax
jne    129c <main+0x18c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x34(%rbp),%eax
jne    129c <main+0x18c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    -0x30(%rbp),%eax
jne    129c <main+0x18c>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12aa <main+0x19a>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12af <main+0x19f>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x1020304,0xc(%rsp)
01
lea    0xd(%rsp),%r15
lea    0xe(%rsp),%r14
lea    0xf(%rsp),%r12
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
lea    0xc(%rsp),%r13
mov    %r13,%rsi
mov    $0x1020304,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xc(%rsp),%edx
movsbl 0xd(%rsp),%r8d
movsbl 0xe(%rsp),%r10d
movsbl 0xf(%rsp),%ebx
sub    $0x8,%rsp
lea    0xe9c(%rip),%rdi
mov    %r13,%rsi
mov    %r15,%rcx
mov    %r14,%r9
xor    %eax,%eax
push   %rbx
push   %r12
push   %r10
call   1040 <printf@plt>
add    $0x20,%rsp
mov    0xc(%rsp),%bl
mov    0xd(%rsp),%al
mov    0xe(%rsp),%dl
mov    0xf(%rsp),%cl
cmp    $0x1,%bl
jne    11d1 <main+0xb1>
cmp    $0x2,%al
jne    11d1 <main+0xb1>
cmp    $0x3,%dl
jne    11d1 <main+0xb1>
cmp    $0x4,%cl
jne    11d1 <main+0xb1>
lea    0xf17(%rip),%rdi
jmp    11f4 <main+0xd4>
xor    $0x4,%bl
xor    $0x3,%al
or     %bl,%al
xor    $0x2,%dl
xor    $0x1,%cl
or     %dl,%cl
lea    0xed0(%rip),%rdx
lea    0xe99(%rip),%rdi
or     %al,%cl
cmove  %rdx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Big/Little Endian Testing...\0A\00"
@.str.1 = [40 x i8] c"n is at address: 0x%x with value: 0x%x\0A\00"
@.str.2 = [66 x i8] c"n is in sequence of [0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x]\0A\00"
@.str.3 = [45 x i8] c"Endian test : This is a big endian machine.\0A\00"
@.str.4 = [48 x i8] c"Endian test : This is a little endian machine.\0A\00"
@.str.5 = [49 x i8] c"Endian test : This is a unknown endian machine.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 16909060, i32* %6
%11 = bitcast i32* %6 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8* %12, i8** %2
%13 = bitcast i32* %6 to i8*
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8* %14, i8** %3
%15 = bitcast i32* %6 to i8*
%16 = getelementptr inbounds i8, i8* %15, i64 2
store i8* %16, i8** %4
%17 = bitcast i32* %6 to i8*
%18 = getelementptr inbounds i8, i8* %17, i64 3
store i8* %18, i8** %5
%19 = load i32, i32* %6
%20 = and i32 %19, -16777216
%21 = lshr i32 %20, 24
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = and i32 %22, 16711680
%24 = ashr i32 %23, 16
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = and i32 %25, 65280
%27 = ashr i32 %26, 8
store i32 %27, i32* %9
%28 = load i32, i32* %6
%29 = and i32 %28, 255
%30 = ashr i32 %29, 0
store i32 %30, i32* %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 %32)
%34 = load i8*, i8** %2
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i8*, i8** %3
%39 = load i8*, i8** %3
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = load i8*, i8** %4
%43 = load i8*, i8** %4
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = load i8*, i8** %5
%47 = load i8*, i8** %5
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %37, i8* %38, i32 %41, i8* %42, i32 %45, i8* %46, i32 %49)
%51 = load i8*, i8** %2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = load i32, i32* %7
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %76
56: ; preds = %0
%57 = load i8*, i8** %3
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = load i32, i32* %8
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %76
62: ; preds = %56
%63 = load i8*, i8** %4
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = load i32, i32* %9
%67 = icmp eq i32 %65, %66
br i1 %67, label %68, label %76
68: ; preds = %62
%69 = load i8*, i8** %5
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = load i32, i32* %10
%73 = icmp eq i32 %71, %72
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %105
76: ; preds = %68, %62, %56, %0
%77 = load i8*, i8** %2
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = load i32, i32* %10
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %102
82: ; preds = %76
%83 = load i8*, i8** %3
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = load i32, i32* %9
%87 = icmp eq i32 %85, %86
br i1 %87, label %88, label %102
88: ; preds = %82
%89 = load i8*, i8** %4
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = load i32, i32* %8
%93 = icmp eq i32 %91, %92
br i1 %93, label %94, label %102
94: ; preds = %88
%95 = load i8*, i8** %5
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = load i32, i32* %7
%99 = icmp eq i32 %97, %98
br i1 %99, label %100, label %102
100: ; preds = %94
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
br label %104
102: ; preds = %94, %88, %82, %76
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %104
104: ; preds = %102, %100
br label %105
105: ; preds = %104, %74
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"n is at address: 0x%x with value: 0x%x\0A\00"
@.str.2 = [66 x i8] c"n is in sequence of [0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x, 0x%x:0x%x]\0A\00"
@str = [29 x i8] c"Big/Little Endian Testing...\00"
@str.6 = [48 x i8] c"Endian test : This is a unknown endian machine.\00"
@str.7 = [47 x i8] c"Endian test : This is a little endian machine.\00"
@str.8 = [44 x i8] c"Endian test : This is a big endian machine.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 16909060, i32* %1
%3 = getelementptr inbounds i8, i8* %2, i64 1
%4 = getelementptr inbounds i8, i8* %2, i64 2
%5 = getelementptr inbounds i8, i8* %2, i64 3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32 16909060)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32 %9, i8* %3, i32 %11, i8* %4, i32 %13, i8* %5, i32 %15)
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 1
%19 = load i8, i8* %3
%20 = icmp eq i8 %19, 2
%21 = select i1 %18, i1 %20, i1 false
%22 = load i8, i8* %4
%23 = icmp eq i8 %22, 3
%24 = select i1 %21, i1 %23, i1 false
%25 = load i8, i8* %5
%26 = icmp eq i8 %25, 4
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %37, label %28
28: ; preds = %0
%29 = icmp eq i8 %17, 4
%30 = icmp eq i8 %19, 3
%31 = select i1 %29, i1 %30, i1 false
%32 = icmp eq i8 %22, 2
%33 = select i1 %31, i1 %32, i1 false
%34 = icmp eq i8 %25, 1
%35 = select i1 %33, i1 %34, i1 false
%36 = select i1 %35, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @str.6, i64 0, i64 0)
br label %37
37: ; preds = %28, %0
%38 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.8, i64 0, i64 0), %0 ], [ %36, %28 ]
%39 = call i32 @puts(i8* dereferenceable(1) %38)
ret i32 0
}