#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 */
size_t EI_DATA;
char const ELFDATA2LSB;
char const ELFDATA2MSB;
int /*<<< orphan*/ abort();
int needconv(const char *elfhdr) {
  union {
    short s;
    char c[2];
  } endian_test;
  endian_test.s = 1;
  if (endian_test.c[1] == 1)
    return elfhdr[EI_DATA] != ELFDATA2MSB;
  if (endian_test.c[0] == 1)
    return elfhdr[EI_DATA] != ELFDATA2LSB;
  else
    abort();
}


x86 assembly (clang, -O0):
<needconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movw   $0x1,-0x18(%rbp)
movsbl -0x17(%rbp),%eax
cmp    $0x1,%eax
jne    115d <needconv+0x4d>
mov    -0x10(%rbp),%rax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
mov    0x2e88(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <needconv+0x8f>
movsbl -0x18(%rbp),%eax
cmp    $0x1,%eax
jne    1198 <needconv+0x88>
mov    -0x10(%rbp),%rax
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
mov    0x2e6d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <needconv+0x8f>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<needconv>:
mov    0x2ee1(%rip),%rax
mov    (%rax),%rcx
xor    %eax,%eax
cmpb   $0x0,(%rdi,%rcx,1)
setne  %al
ret

LLVM IR (-O0):
%union.anon = type { i16 }
@EI_DATA = global i64 0
@ELFDATA2MSB = constant i8 0
@ELFDATA2LSB = constant i8 0
define i32 @needconv(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %union.anon
store i8* %0, i8** %3
%5 = bitcast %union.anon* %4 to i16*
store i16 1, i16* %5
%6 = bitcast %union.anon* %4 to [2 x i8]*
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %21
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i64, i64* @EI_DATA
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = load i8, i8* @ELFDATA2MSB
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
%20 = zext i1 %19 to i32
store i32 %20, i32* %2
br label %39
21: ; preds = %1
%22 = bitcast %union.anon* %4 to [2 x i8]*
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %22, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = load i64, i64* @EI_DATA
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8, i8* @ELFDATA2LSB
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %32, %34
%36 = zext i1 %35 to i32
store i32 %36, i32* %2
br label %39
37: ; preds = %21
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %27, %11
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@EI_DATA = global i64 0
@ELFDATA2MSB = constant i8 0
@ELFDATA2LSB = constant i8 0
define i32 @needconv(i8* nocapture %0) {
%2 = load i64, i64* @EI_DATA
%3 = getelementptr inbounds i8, i8* %0, i64 %2
%4 = load i8, i8* %3
%5 = icmp ne i8 %4, 0
%6 = zext i1 %5 to i32
ret i32 %6
}