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

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


x86 assembly (clang, -O0):
<utilReadInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <utilIsLittleEndian@plt>
cmp    $0x0,%rax
je     116f <utilReadInt32+0x4f>
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <utilReadInt32+0x67>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%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):
<utilReadInt32>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <utilIsLittleEndian@plt>
test   %rax,%rax
je     1151 <utilReadInt32+0x31>
mov    0x3(%rbx),%al
mov    %al,0xc(%rsp)
mov    0x2(%rbx),%al
mov    %al,0xd(%rsp)
mov    0x1(%rbx),%al
mov    %al,0xe(%rsp)
mov    (%rbx),%al
mov    %al,0xf(%rsp)
jmp    1163 <utilReadInt32+0x43>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @utilReadInt32(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 %29
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 3
%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 2
%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 i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = bitcast i32* %4 to i8*
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8 %20, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = bitcast i32* %4 to i8*
%27 = getelementptr inbounds i8, i8* %26, i64 3
store i8 %25, i8* %27
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %34
29: ; preds = %1
%30 = bitcast i32* %4 to i8*
%31 = load i8*, i8** %3
%32 = call i32 @memcpy(i8* %30, i8* %31, i32 4)
%33 = load i32, i32* %4
store i32 %33, i32* %2
br label %34
34: ; preds = %29, %7
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @utilReadInt32(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 %17, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = load i8, i8* %7
store i8 %8, i8* %3
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %10, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %13, i8* %14
%15 = load i8, i8* %0
%16 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %15, i8* %16
br label %19
17: ; preds = %1
%18 = call i32 @memcpy(i8* %3, i8* %0, i32 4)
br label %19
19: ; preds = %17, %6
%20 = load i32, i32* %2
ret i32 %20
}