#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 */
typedef int ptrdiff_t;

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
char *ptrdiff_t_endianness(void) {
  unsigned char arr[sizeof(ptrdiff_t)];
  if (sizeof(ptrdiff_t) == 1) {
    return NULL;
  }
  memset(arr, 0, sizeof arr);
  arr[0] = 1;
  if (*((ptrdiff_t *)arr) == 1) {
    return "little-endian";
  }
  memset(arr, 0, sizeof arr);
  arr[sizeof arr - 1] = 1;
  if (*((ptrdiff_t *)arr) == 1) {
    return "big-endian";
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ptrdiff_t_endianness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x1,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1146 <ptrdiff_t_endianness+0x36>
lea    0xec3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <ptrdiff_t_endianness+0x6c>
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x1,-0x9(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1174 <ptrdiff_t_endianness+0x64>
lea    0xea3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <ptrdiff_t_endianness+0x6c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrdiff_t_endianness>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x1,0xc(%rsp)
cmpl   $0x1,0xc(%rsp)
jne    113b <ptrdiff_t_endianness+0x2b>
lea    0xec7(%rip),%rbx
jmp    1163 <ptrdiff_t_endianness+0x53>
lea    0xc(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movb   $0x1,0xf(%rsp)
cmpl   $0x1,0xc(%rsp)
lea    0xeaf(%rip),%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"little-endian\00"
@.str.1 = [11 x i8] c"big-endian\00"
define i8* @ptrdiff_t_endianness() {
%1 = alloca i8*
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 4)
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
store i8 1, i8* %5
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %1
br label %21
11: ; preds = %0
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 4)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 1, i8* %14
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %11
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %21
20: ; preds = %11
store i8* null, i8** %1
br label %21
21: ; preds = %20, %19, %10
%22 = load i8*, i8** %1
ret i8* %22
}

LLVM IR (-O2):
@.str = [14 x i8] c"little-endian\00"
@.str.1 = [11 x i8] c"big-endian\00"
define i8* @ptrdiff_t_endianness() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @memset(i8* %2, i32 0, i32 4)
store i8 1, i8* %2
%4 = load i32, i32* %1
%5 = icmp eq i32 %4, 1
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = bitcast i32* %1 to [4 x i8]*
%8 = call i32 @memset(i8* %2, i32 0, i32 4)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 3
store i8 1, i8* %9
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 1
%12 = select i1 %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* null
br label %13
13: ; preds = %6, %0
%14 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %0 ], [ %12, %6 ]
ret i8* %14
}