#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 */

/* Variables and functions */
unsigned int zreadword(char **entry) {
  size_t i;
  unsigned int zint;
  unsigned char *cursor;
  cursor = (unsigned char *)*entry;
  zint = (unsigned int)*cursor;
  cursor++;
  for (i = 1; i < (8 * sizeof(unsigned int)) / 8; i++) {
    zint <<= 8;
    zint += (unsigned int)*cursor;
    cursor++;
  }
  *entry = (char *)cursor;
  return zint;
}


x86 assembly (clang, -O0):
<zreadword>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x10(%rbp)
cmpq   $0x4,-0x10(%rbp)
jae    116f <zreadword+0x6f>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1131 <zreadword+0x31>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<zreadword>:
mov    (%rdi),%rcx
mov    (%rcx),%eax
bswap  %eax
add    $0x4,%rcx
mov    %rcx,(%rdi)
ret

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

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