#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;

/* Variables and functions */
uint32_t mathbuf_get(uint8_t buf[], uint8_t size) {
  uint32_t temp;
  temp = buf[size - 4] & 0xff;
  temp <<= 8;
  temp |= buf[size - 3] & 0xff;
  temp <<= 8;
  temp |= buf[size - 2] & 0xff;
  temp <<= 8;
  temp |= buf[size - 1] & 0xff;
  return temp;
}


x86 assembly (clang, -O0):
<mathbuf_get>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mathbuf_get>:
movslq %esi,%rax
mov    -0x10(%rdi,%rax,4),%ecx
mov    -0xc(%rdi,%rax,4),%edx
mov    -0x8(%rdi,%rax,4),%esi
shl    $0x18,%ecx
movzbl %dl,%edx
shl    $0x10,%edx
or     %ecx,%edx
shl    $0x8,%esi
movzwl %si,%ecx
or     %edx,%ecx
movzbl -0x4(%rdi,%rax,4),%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @mathbuf_get(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %6, i64 %9
%11 = load i32, i32* %10
%12 = and i32 %11, 255
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = shl i32 %13, 8
store i32 %14, i32* %5
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %15, i64 %18
%20 = load i32, i32* %19
%21 = and i32 %20, 255
%22 = load i32, i32* %5
%23 = or i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = shl i32 %24, 8
store i32 %25, i32* %5
%26 = load i32*, i32** %3
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
%31 = load i32, i32* %30
%32 = and i32 %31, 255
%33 = load i32, i32* %5
%34 = or i32 %33, %32
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = shl i32 %35, 8
store i32 %36, i32* %5
%37 = load i32*, i32** %3
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = load i32, i32* %41
%43 = and i32 %42, 255
%44 = load i32, i32* %5
%45 = or i32 %44, %43
store i32 %45, i32* %5
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @mathbuf_get(i32* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, -4
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i32, i32* %0, i64 %4
%6 = load i32, i32* %5
%7 = add nsw i32 %1, -3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = add nsw i32 %1, -2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = shl i32 %6, 24
%16 = shl i32 %10, 16
%17 = and i32 %16, 16711680
%18 = or i32 %17, %15
%19 = shl i32 %14, 8
%20 = and i32 %19, 65280
%21 = or i32 %18, %20
%22 = add nsw i32 %1, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %0, i64 %23
%25 = load i32, i32* %24
%26 = and i32 %25, 255
%27 = or i32 %21, %26
ret i32 %27
}