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

/* Variables and functions */
long sgetl(const char *buffer) {
  const uint8_t *p = (uint8_t *)buffer;
  uint32_t r;
  r = *p++;
  r |= (((uint16_t)*p++) << 8);
  r |= (((uint32_t)*p++) << 16);
  r |= (((uint32_t)*p) << 24);
  return (long)r;
}


x86 assembly (clang, -O0):
<sgetl>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
shl    $0x8,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
shl    $0x10,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
shl    $0x18,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sgetl>:
mov    0x8(%rdi),%eax
mov    0x10(%rdi),%ecx
shl    $0x8,%eax
or     (%rdi),%eax
shl    $0x10,%ecx
mov    0x18(%rdi),%edx
shl    $0x18,%edx
or     %ecx,%edx
or     %eax,%edx
movslq %edx,%rax
ret

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

LLVM IR (-O2):
define i64 @sgetl(i8* nocapture %0) {
%2 = bitcast i8* %0 to i64*
%3 = getelementptr inbounds i8, i8* %0, i64 8
%4 = bitcast i8* %3 to i64*
%5 = load i64, i64* %2
%6 = trunc i64 %5 to i32
%7 = getelementptr inbounds i8, i8* %0, i64 16
%8 = bitcast i8* %7 to i64*
%9 = load i64, i64* %4
%10 = trunc i64 %9 to i32
%11 = shl i32 %10, 8
%12 = or i32 %11, %6
%13 = getelementptr inbounds i8, i8* %0, i64 24
%14 = bitcast i8* %13 to i64*
%15 = load i64, i64* %8
%16 = trunc i64 %15 to i32
%17 = shl i32 %16, 16
%18 = or i32 %12, %17
%19 = load i64, i64* %14
%20 = trunc i64 %19 to i32
%21 = shl i32 %20, 24
%22 = or i32 %18, %21
%23 = sext i32 %22 to i64
ret i64 %23
}