#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;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ is_big_endian();
const uint8_t *read_fixed32(uint32_t *v, const uint8_t *buffer,
                            const uint8_t *buffer_end) {
  if (buffer + 4 > buffer_end)
    return NULL;
  if (!is_big_endian()) {
    *v = *(uint32_t *)buffer;
  } else {
    *v = ((uint32_t)buffer[0]) | (((uint32_t)buffer[1]) << 8) |
         (((uint32_t)buffer[2]) << 16) | (((uint32_t)buffer[3]) << 24);
  }
  return buffer + 4;
}


x86 assembly (clang, -O0):
<read_fixed32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
cmp    -0x20(%rbp),%rax
jbe    1143 <read_fixed32+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <read_fixed32+0x96>
mov    $0x0,%al
call   1030 <is_big_endian@plt>
cmp    $0x0,%eax
jne    1164 <read_fixed32+0x54>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    119a <read_fixed32+0x8a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
shl    $0x18,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fixed32>:
push   %r15
push   %r14
push   %rbx
lea    0x20(%rsi),%r15
cmp    %rdx,%r15
jbe    1123 <read_fixed32+0x13>
xor    %r15d,%r15d
jmp    1153 <read_fixed32+0x43>
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <is_big_endian@plt>
test   %eax,%eax
je     114e <read_fixed32+0x3e>
mov    0x8(%rbx),%ecx
mov    0x10(%rbx),%edx
shl    $0x8,%ecx
or     (%rbx),%ecx
shl    $0x10,%edx
mov    0x18(%rbx),%eax
shl    $0x18,%eax
or     %edx,%eax
or     %ecx,%eax
jmp    1150 <read_fixed32+0x40>
mov    (%rbx),%eax
mov    %eax,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64* @read_fixed32(i32* %0, i64* %1, i64* %2) {
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i64*
store i32* %0, i32** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%8 = load i64*, i64** %6
%9 = getelementptr inbounds i64, i64* %8, i64 4
%10 = load i64*, i64** %7
%11 = icmp ugt i64* %9, %10
br i1 %11, label %12, label %13
12: ; preds = %3
store i64* null, i64** %4
br label %48
13: ; preds = %3
%14 = call i32 (...) @is_big_endian()
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = load i64*, i64** %6
%18 = bitcast i64* %17 to i32*
%19 = load i32, i32* %18
%20 = load i32*, i32** %5
store i32 %19, i32* %20
br label %45
21: ; preds = %13
%22 = load i64*, i64** %6
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = load i64*, i64** %6
%27 = getelementptr inbounds i64, i64* %26, i64 1
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = shl i32 %29, 8
%31 = or i32 %25, %30
%32 = load i64*, i64** %6
%33 = getelementptr inbounds i64, i64* %32, i64 2
%34 = load i64, i64* %33
%35 = trunc i64 %34 to i32
%36 = shl i32 %35, 16
%37 = or i32 %31, %36
%38 = load i64*, i64** %6
%39 = getelementptr inbounds i64, i64* %38, i64 3
%40 = load i64, i64* %39
%41 = trunc i64 %40 to i32
%42 = shl i32 %41, 24
%43 = or i32 %37, %42
%44 = load i32*, i32** %5
store i32 %43, i32* %44
br label %45
45: ; preds = %21, %16
%46 = load i64*, i64** %6
%47 = getelementptr inbounds i64, i64* %46, i64 4
store i64* %47, i64** %4
br label %48
48: ; preds = %45, %12
%49 = load i64*, i64** %4
ret i64* %49
}

LLVM IR (-O2):
define i64* @read_fixed32(i32* nocapture writeonly %0, i64* %1, i64* readnone %2) {
%4 = getelementptr inbounds i64, i64* %1, i64 4
%5 = icmp ugt i64* %4, %2
br i1 %5, label %32, label %6
6: ; preds = %3
%7 = tail call i32 (...) @is_big_endian()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = bitcast i64* %1 to i32*
%11 = load i32, i32* %10
br label %30
12: ; preds = %6
%13 = load i64, i64* %1
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds i64, i64* %1, i64 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = shl i32 %17, 8
%19 = or i32 %18, %14
%20 = getelementptr inbounds i64, i64* %1, i64 2
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = shl i32 %22, 16
%24 = or i32 %19, %23
%25 = getelementptr inbounds i64, i64* %1, i64 3
%26 = load i64, i64* %25
%27 = trunc i64 %26 to i32
%28 = shl i32 %27, 24
%29 = or i32 %24, %28
br label %30
30: ; preds = %12, %9
%31 = phi i32 [ %11, %9 ], [ %29, %12 ]
store i32 %31, i32* %0
br label %32
32: ; preds = %3, %30
%33 = phi i64* [ %4, %30 ], [ null, %3 ]
ret i64* %33
}