#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 /*<<< orphan*/ int16_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
scalar_t__ utilIsLittleEndian();
int16_t utilReadInt16(const unsigned char *buf) {
  int16_t i;
  if (utilIsLittleEndian()) {
    ((unsigned char *)&i)[0] = buf[1];
    ((unsigned char *)&i)[1] = buf[0];
    return i;
  } else {
    memcpy((unsigned char *)&i, buf, 2);
    return i;
  }
}


x86 assembly (clang, -O0):
<utilReadInt16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <utilIsLittleEndian@plt>
cmp    $0x0,%rax
je     115b <utilReadInt16+0x3b>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x13(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1173 <utilReadInt16+0x53>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilReadInt16>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <utilIsLittleEndian@plt>
test   %rax,%rax
je     1143 <utilReadInt16+0x23>
mov    0x1(%rbx),%al
mov    %al,0xc(%rsp)
mov    (%rbx),%al
mov    %al,0xd(%rsp)
jmp    1155 <utilReadInt16+0x35>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @utilReadInt16(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i64 (...) @utilIsLittleEndian()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = bitcast i32* %4 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 %10, i8* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = bitcast i32* %4 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %15, i8* %17
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %24
19: ; preds = %1
%20 = bitcast i32* %4 to i8*
%21 = load i8*, i8** %3
%22 = call i32 @memcpy(i8* %20, i8* %21, i32 2)
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %19, %7
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @utilReadInt16(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @utilIsLittleEndian()
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
store i8 %8, i8* %3
%9 = load i8, i8* %0
%10 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %9, i8* %10
br label %13
11: ; preds = %1
%12 = call i32 @memcpy(i8* %3, i8* %0, i32 2)
br label %13
13: ; preds = %11, %6
%14 = load i32, i32* %2
ret i32 %14
}