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

/* Variables and functions */
unsigned char text_read_ub(char *);
unsigned long text_read_ul(void *addr) {
  int i;
  unsigned long value;
  for (i = 0; i < sizeof(value); i++) {
    ((unsigned char *)&value)[i] = text_read_ub((char *)addr + i);
  }
  return value;
}


x86 assembly (clang, -O0):
<text_read_ul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x8,%rax
jae    1159 <text_read_ul+0x49>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
call   1030 <text_read_ub@plt>
mov    %al,%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x18(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <text_read_ul+0x13>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_read_ul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1030 <text_read_ub@plt>
mov    %al,0x7(%rsp)
lea    0x1(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %al,0x6(%rsp)
lea    0x2(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %eax,%r15d
lea    0x3(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %eax,%r13d
lea    0x4(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %eax,%ebx
lea    0x5(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %eax,%r12d
lea    0x6(%rbp),%rdi
call   1030 <text_read_ub@plt>
mov    %eax,%r14d
add    $0x7,%rbp
mov    %rbp,%rdi
call   1030 <text_read_ub@plt>
movzbl %al,%eax
shl    $0x38,%rax
movzbl %r14b,%ecx
shl    $0x30,%rcx
or     %rax,%rcx
movzbl %r12b,%eax
shl    $0x28,%rax
or     %rcx,%rax
movzbl %bl,%ecx
shl    $0x20,%rcx
or     %rax,%rcx
movzbl %r13b,%eax
shl    $0x18,%rax
or     %rcx,%rax
movzbl %r15b,%ecx
shl    $0x10,%rcx
or     %rax,%rcx
movzbl 0x6(%rsp),%edx
shl    $0x8,%rdx
or     %rcx,%rdx
movzbl 0x7(%rsp),%eax
or     %rdx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @text_read_ul(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 8
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = call zeroext i8 @text_read_ub(i8* %13)
%15 = bitcast i64* %4 to i8*
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
br label %19
19: ; preds = %9
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %5
%23 = load i64, i64* %4
ret i64 %23
}

LLVM IR (-O2):
define i64 @text_read_ul(i8* %0) {
%2 = tail call zeroext i8 @text_read_ub(i8* %0)
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = tail call zeroext i8 @text_read_ub(i8* %3)
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = tail call zeroext i8 @text_read_ub(i8* %5)
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = tail call zeroext i8 @text_read_ub(i8* %7)
%9 = getelementptr inbounds i8, i8* %0, i64 4
%10 = tail call zeroext i8 @text_read_ub(i8* %9)
%11 = getelementptr inbounds i8, i8* %0, i64 5
%12 = tail call zeroext i8 @text_read_ub(i8* %11)
%13 = getelementptr inbounds i8, i8* %0, i64 6
%14 = tail call zeroext i8 @text_read_ub(i8* %13)
%15 = getelementptr inbounds i8, i8* %0, i64 7
%16 = tail call zeroext i8 @text_read_ub(i8* %15)
%17 = zext i8 %16 to i64
%18 = shl nuw i64 %17, 56
%19 = zext i8 %14 to i64
%20 = shl nuw nsw i64 %19, 48
%21 = or i64 %18, %20
%22 = zext i8 %12 to i64
%23 = shl nuw nsw i64 %22, 40
%24 = or i64 %21, %23
%25 = zext i8 %10 to i64
%26 = shl nuw nsw i64 %25, 32
%27 = or i64 %24, %26
%28 = zext i8 %8 to i64
%29 = shl nuw nsw i64 %28, 24
%30 = or i64 %27, %29
%31 = zext i8 %6 to i64
%32 = shl nuw nsw i64 %31, 16
%33 = zext i8 %4 to i64
%34 = shl nuw nsw i64 %33, 8
%35 = or i64 %30, %32
%36 = zext i8 %2 to i64
%37 = or i64 %35, %34
%38 = or i64 %37, %36
ret i64 %38
}