#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned int readuint(FILE *f, int bigendian) {
  unsigned char c1, c2, c3, c4;
  fread(&c1, 1, 1, f);
  fread(&c2, 1, 1, f);
  fread(&c3, 1, 1, f);
  fread(&c4, 1, 1, f);
  if (bigendian) {
    return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
  } else {
    return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1;
  }
}


x86 assembly (clang, -O0):
<readuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x16(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x17(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmpl   $0x0,-0x14(%rbp)
je     11a0 <readuint+0x90>
movzbl -0x15(%rbp),%eax
shl    $0x18,%eax
movzbl -0x16(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x17(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <readuint+0xb2>
movzbl -0x18(%rbp),%eax
shl    $0x18,%eax
movzbl -0x17(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x16(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x15(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readuint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0x7(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
lea    0x6(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
lea    0x5(%rsp),%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %r12d,%r12d
je     11a2 <readuint+0x92>
movzbl 0x7(%rsp),%eax
shl    $0x18,%eax
movzbl 0x6(%rsp),%ecx
shl    $0x10,%ecx
or     %eax,%ecx
jmp    11ba <readuint+0xaa>
movzbl 0x4(%rsp),%eax
shl    $0x18,%eax
movzbl 0x5(%rsp),%ecx
shl    $0x10,%ecx
or     %eax,%ecx
mov    %r15,%r13
mov    %r14,%rbx
movzbl 0x0(%r13),%edx
shl    $0x8,%edx
movzbl (%rbx),%eax
or     %ecx,%eax
or     %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readuint(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = load i32*, i32** %4
%11 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %10)
%12 = load i32*, i32** %4
%13 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %12)
%14 = load i32*, i32** %4
%15 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %14)
%16 = load i32*, i32** %4
%17 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %16)
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %2
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 24
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 16
%27 = add nsw i32 %23, %26
%28 = load i8, i8* %8
%29 = zext i8 %28 to i32
%30 = shl i32 %29, 8
%31 = add nsw i32 %27, %30
%32 = load i8, i8* %9
%33 = zext i8 %32 to i32
%34 = add nsw i32 %31, %33
store i32 %34, i32* %3
br label %50
35: ; preds = %2
%36 = load i8, i8* %9
%37 = zext i8 %36 to i32
%38 = shl i32 %37, 24
%39 = load i8, i8* %8
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 16
%42 = add nsw i32 %38, %41
%43 = load i8, i8* %7
%44 = zext i8 %43 to i32
%45 = shl i32 %44, 8
%46 = add nsw i32 %42, %45
%47 = load i8, i8* %6
%48 = zext i8 %47 to i32
%49 = add nsw i32 %46, %48
store i32 %49, i32* %3
br label %50
50: ; preds = %35, %20
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @readuint(i32* nocapture %0, i32 %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%8 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%9 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %0)
%10 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %0)
%11 = icmp eq i32 %1, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i8, i8* %3
%14 = zext i8 %13 to i32
%15 = shl nuw i32 %14, 24
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 16
%19 = or i32 %18, %15
br label %28
20: ; preds = %2
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = shl nuw i32 %22, 24
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = shl nuw nsw i32 %25, 16
%27 = or i32 %26, %23
br label %28
28: ; preds = %20, %12
%29 = phi i8* [ %4, %20 ], [ %5, %12 ]
%30 = phi i32 [ %27, %20 ], [ %19, %12 ]
%31 = phi i8* [ %3, %20 ], [ %6, %12 ]
%32 = load i8, i8* %29
%33 = zext i8 %32 to i32
%34 = shl nuw nsw i32 %33, 8
%35 = or i32 %30, %34
%36 = load i8, i8* %31
%37 = zext i8 %36 to i32
%38 = or i32 %35, %37
ret i32 %38
}