#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*/ assert(int);
scalar_t__ memcmp(char *, char *, int);
int is_little_endian() {
  static int retval = -1;
  if (retval == -1) {
    int n = 1;
    char *p = (char *)&n;
    char x[] = {1, 0, 0, 0};
    assert(sizeof(int) == 4);
    if (memcmp(p, x, 4) == 0) {
      retval = 1;
    } else {
      retval = 0;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<is_little_endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0xffffffff,0x2f01(%rip)
jne    1191 <is_little_endian+0x71>
movl   $0x1,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb6(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1182 <is_little_endian+0x62>
movl   $0x1,0x2eb3(%rip)
jmp    118c <is_little_endian+0x6c>
movl   $0x0,0x2ea4(%rip)
jmp    1191 <is_little_endian+0x71>
mov    0x2e99(%rip),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_little_endian>:
push   %rax
mov    0x2f09(%rip),%eax
cmp    $0xffffffff,%eax
je     112e <is_little_endian+0xe>
pop    %rcx
ret
movl   $0x1,0x4(%rsp)
movl   $0x1,(%rsp)
mov    $0x1,%edi
call   1040 <assert@plt>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
mov    %eax,0x2ec6(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@is_little_endian.retval = internal global i32 -1
@__const.is_little_endian.x = [4 x i8] c"\01\00\00\00"
define i32 @is_little_endian() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = load i32, i32* @is_little_endian.retval
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %17
6: ; preds = %0
store i32 1, i32* %1
%7 = bitcast i32* %1 to i8*
store i8* %7, i8** %2
%8 = bitcast [4 x i8]* %3 to i8*
%9 = call i32 @assert(i32 1)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%12 = call i64 @memcmp(i8* %10, i8* %11, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %6
store i32 1, i32* @is_little_endian.retval
br label %16
15: ; preds = %6
store i32 0, i32* @is_little_endian.retval
br label %16
16: ; preds = %15, %14
br label %17
17: ; preds = %16, %0
%18 = load i32, i32* @is_little_endian.retval
ret i32 %18
}

LLVM IR (-O2):
@is_little_endian.retval = internal unnamed_addr global i32 -1
define i32 @is_little_endian() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @is_little_endian.retval
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%7 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%8 = tail call i32 @assert(i32 1)
%9 = call i64 @memcmp(i8* %6, i8* %7, i32 4)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
store i32 %11, i32* @is_little_endian.retval
br label %12
12: ; preds = %5, %0
%13 = phi i32 [ %11, %5 ], [ %3, %0 ]
ret i32 %13
}