#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*/ memcpy(int *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, int);
int is_bigendian() {
  int bigendian, littleendian, test;
  unsigned char t[4];
  littleendian = 256;
  bigendian = 256 * 256;
  t[0] = 0;
  t[1] = 1;
  t[2] = 0;
  t[3] = 0;
  memcpy(&test, &t[0], 4);
  if (test == bigendian)
    return (1);
  if (test == littleendian)
    return (0);
  printf("Error in endian test, test= %i ********\n", test);
  return (-1);
}


x86 assembly (clang, -O0):
<is_bigendian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x100,-0xc(%rbp)
movl   $0x10000,-0x8(%rbp)
movb   $0x0,-0x14(%rbp)
movb   $0x1,-0x13(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1170 <is_bigendian+0x50>
movl   $0x1,-0x4(%rbp)
jmp    119e <is_bigendian+0x7e>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1188 <is_bigendian+0x68>
movl   $0x0,-0x4(%rbp)
jmp    119e <is_bigendian+0x7e>
mov    -0x10(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_bigendian>:
push   %rax
movl   $0x100,0x4(%rsp)
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    (%rsp),%esi
cmp    $0x10000,%esi
je     1152 <is_bigendian+0x32>
cmp    $0x100,%esi
jne    1159 <is_bigendian+0x39>
xor    %eax,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Error in endian test, test= %i ********\0A\00"
define i32 @is_bigendian() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i8]
store i32 256, i32* %3
store i32 65536, i32* %2
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 0, i8* %6
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 1, i8* %7
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 0, i8* %8
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 0, i8* %9
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%11 = call i32 @memcpy(i32* %4, i8* %10, i32 4)
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 1, i32* %1
br label %24
16: ; preds = %0
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %1
br label %24
21: ; preds = %16
%22 = load i32, i32* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 -1, i32* %1
br label %24
24: ; preds = %21, %20, %15
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [41 x i8] c"Error in endian test, test= %i ********\0A\00"
define i32 @is_bigendian() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
store i8 0, i8* %4
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
store i8 1, i8* %5
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
store i8 0, i8* %6
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %7
%8 = call i32 @memcpy(i32* %1, i8* %4, i32 4)
%9 = load i32, i32* %1
switch i32 %9, label %11 [
i32 65536, label %13
i32 256, label %10
]
10: ; preds = %0
br label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %13
13: ; preds = %0, %11, %10
%14 = phi i32 [ 0, %10 ], [ -1, %11 ], [ 1, %0 ]
ret i32 %14
}