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

/* Variables and functions */
uint32_t byte_read_be_uint32(const char *samplePtr) {
  uint16_t one;
  uint16_t two;
  {
    uint8_t b1 = *samplePtr++;
    uint8_t b2 = *samplePtr++;
    one = (b1 << 8) | b2;
  };
  {
    uint8_t b1 = *samplePtr++;
    uint8_t b2 = *samplePtr++;
    two = (b1 << 8) | b2;
  };
  return (one << 16) | two;
}


x86 assembly (clang, -O0):
<byte_read_be_uint32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x10,%eax
or     -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_read_be_uint32>:
movzbl (%rdi),%ecx
movsbl 0x1(%rdi),%eax
movsbl 0x2(%rdi),%edx
movsbl 0x3(%rdi),%esi
shl    $0x8,%edx
or     %esi,%edx
shl    $0x18,%ecx
shl    $0x10,%eax
or     %ecx,%eax
or     %edx,%eax
ret

LLVM IR (-O0):
define i32 @byte_read_be_uint32(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
store i32 %12, i32* %5
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %2
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = shl i32 %17, 8
%19 = load i32, i32* %6
%20 = or i32 %18, %19
store i32 %20, i32* %3
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
store i32 %24, i32* %7
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %2
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = shl i32 %29, 8
%31 = load i32, i32* %8
%32 = or i32 %30, %31
store i32 %32, i32* %4
%33 = load i32, i32* %3
%34 = shl i32 %33, 16
%35 = load i32, i32* %4
%36 = or i32 %34, %35
ret i32 %36
}

LLVM IR (-O2):
define i32 @byte_read_be_uint32(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = zext i8 %3 to i32
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = getelementptr inbounds i8, i8* %0, i64 3
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
%11 = load i8, i8* %8
%12 = sext i8 %11 to i32
%13 = shl nsw i32 %10, 8
%14 = shl nuw i32 %4, 24
%15 = shl nsw i32 %7, 16
%16 = or i32 %15, %14
%17 = or i32 %16, %12
%18 = or i32 %17, %13
ret i32 %18
}