#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 scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void show_endian(const char *label, void *p, size_t n, uint8_t lsb) {
  uint8_t *q = p;
  printf("%s is %s endian (", label, *q == lsb ? "little" : "big");
  for (size_t i = 0; i < n; ++i)
    printf(" %02X" + (i == 0), *q++);
  printf(")\n");
}


x86 assembly (clang, -O0):
<show_endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rdi
lea    0xed3(%rip),%rdx
lea    0xec5(%rip),%rax
cmp    %rdi,%rcx
cmove  %rax,%rdx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11bb <show_endian+0xab>
cmpq   $0x0,-0x30(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
lea    0xe8f(%rip),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    116a <show_endian+0x5a>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_endian>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rsi
cmp    %rcx,(%r12)
lea    0xed6(%rip),%rax
lea    0xed6(%rip),%rdx
cmove  %rax,%rdx
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     118f <show_endian+0x6f>
lea    0xebc(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x1,%rbx
mov    %r15,%rdi
adc    $0x0,%rdi
mov    (%r12,%rbx,8),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <show_endian+0x50>
lea    0xe8d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"%s is %s endian (\00"
@.str.1 = [7 x i8] c"little\00"
@.str.2 = [4 x i8] c"big\00"
@.str.3 = [6 x i8] c" %02X\00"
@.str.4 = [3 x i8] c")\0A\00"
define void @show_endian(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i8*, i8** %6
%12 = bitcast i8* %11 to i64*
store i64* %12, i64** %9
%13 = load i8*, i8** %5
%14 = load i64*, i64** %9
%15 = load i64, i64* %14
%16 = load i64, i64* %8
%17 = icmp eq i64 %15, %16
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %19)
store i64 0, i64* %10
br label %21
21: ; preds = %35, %4
%22 = load i64, i64* %10
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i64, i64* %10
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %29
%31 = load i64*, i64** %9
%32 = getelementptr inbounds i64, i64* %31, i32 1
store i64* %32, i64** %9
%33 = load i64, i64* %31
%34 = call i32 (i8*, ...) @printf(i8* %30, i64 %33)
br label %35
35: ; preds = %25
%36 = load i64, i64* %10
%37 = add i64 %36, 1
store i64 %37, i64* %10
br label %21
38: ; preds = %21
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%s is %s endian (\00"
@.str.1 = [7 x i8] c"little\00"
@.str.2 = [4 x i8] c"big\00"
@.str.3 = [6 x i8] c" %02X\00"
@str = [2 x i8] c")\00"
define void @show_endian(i8* %0, i8* nocapture %1, i64 %2, i64 %3) {
%5 = bitcast i8* %1 to i64*
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, %3
%8 = select i1 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
%10 = icmp eq i64 %2, 0
br i1 %10, label %11, label %13
11: ; preds = %13, %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
13: ; preds = %4, %13
%14 = phi i64 [ %22, %13 ], [ 0, %4 ]
%15 = phi i64* [ %19, %13 ], [ %5, %4 ]
%16 = icmp eq i64 %14, 0
%17 = zext i1 %16 to i64
%18 = getelementptr inbounds [6 x i8], [6 x i8]* @.str.3, i64 0, i64 %17
%19 = getelementptr inbounds i64, i64* %15, i64 1
%20 = load i64, i64* %15
%21 = tail call i32 (i8*, ...) @printf(i8* %18, i64 %20)
%22 = add nuw i64 %14, 1
%23 = icmp eq i64 %22, %2
br i1 %23, label %11, label %13
}