#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 get_ac3_header(uint8_t *buf) {
  int i = 0;
  uint32_t tmp = 0;
  tmp = (tmp << 8) + (buf[i++] & 0xff);
  tmp = (tmp << 8) + (buf[i++] & 0xff);
  tmp = (tmp << 8) + (buf[i++] & 0xff);
  return tmp;
}


x86 assembly (clang, -O0):
<get_ac3_header>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ac3_header>:
mov    (%rdi),%eax
shl    $0x8,%eax
movzwl %ax,%eax
movzbl 0x4(%rdi),%ecx
or     %eax,%ecx
shl    $0x8,%ecx
movzbl 0x8(%rdi),%eax
or     %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @get_ac3_header(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = shl i32 %2, 8
%4 = and i32 %3, 65280
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = and i32 %6, 255
%8 = or i32 %4, %7
%9 = shl nuw nsw i32 %8, 8
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = load i32, i32* %10
%12 = and i32 %11, 255
%13 = or i32 %9, %12
ret i32 %13
}