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

/* Variables and functions */
int ntohl(int);
uint32_t get_uint32_t(const char *buffer) {
  do {
    if (!(buffer))
      return 0;
  } while (0);
  uint32_t value = ((uint32_t)buffer[3] << 24) + ((uint32_t)buffer[2] << 16) +
                   ((uint32_t)buffer[1] << 8) + ((uint32_t)buffer[0]);
  return ntohl((value));
}


x86 assembly (clang, -O0):
<get_uint32_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <get_uint32_t+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1174 <get_uint32_t+0x64>
jmp    1138 <get_uint32_t+0x28>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
shl    $0x18,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <ntohl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uint32_t>:
test   %rdi,%rdi
je     1138 <get_uint32_t+0x28>
movzbl 0x3(%rdi),%eax
shl    $0x18,%eax
movsbl 0x2(%rdi),%ecx
shl    $0x10,%ecx
add    %eax,%ecx
movsbl 0x1(%rdi),%eax
shl    $0x8,%eax
add    %ecx,%eax
movsbl (%rdi),%edi
add    %eax,%edi
jmp    1030 <ntohl@plt>
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i32 @get_uint32_t(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = getelementptr inbounds i8, i8* %0, i64 3
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = shl nuw i32 %6, 24
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = shl nsw i32 %10, 16
%12 = add nsw i32 %11, %7
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = shl nsw i32 %15, 8
%17 = add nsw i32 %12, %16
%18 = load i8, i8* %0
%19 = sext i8 %18 to i32
%20 = add nsw i32 %17, %19
%21 = tail call i32 @ntohl(i32 %20)
br label %22
22: ; preds = %1, %3
%23 = phi i32 [ %21, %3 ], [ 0, %1 ]
ret i32 %23
}