#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 */
int /*<<< orphan*/ printf(char *, unsigned long long);
int /*<<< orphan*/ start();
unsigned long long stop();
void test_read(unsigned long *p, size_t size) {
  size_t i;
  volatile unsigned long *wp, tmp;
  unsigned long long timeval;
  start();
  for (i = 0, wp = p; i < (size / sizeof(*wp)); i++)
    tmp = *wp++;
  tmp = tmp;
  timeval = stop();
  printf("Read : %10llu usec\n", timeval);
}


x86 assembly (clang, -O0):
<test_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <start@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x3,%rcx
cmp    %rcx,%rax
jae    1193 <test_read+0x63>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <test_read+0x27>
mov    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <stop@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <start@plt>
cmp    $0x8,%r14
jb     11c1 <test_read+0x91>
shr    $0x3,%r14
lea    -0x1(%r14),%rcx
mov    %r14d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jb     11a9 <test_read+0x79>
and    $0xfffffffffffffff8,%r14
nop
mov    (%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x10(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x18(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x20(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x28(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x30(%rbx),%rcx
mov    %rcx,(%rsp)
mov    0x38(%rbx),%rcx
add    $0x40,%rbx
mov    %rcx,(%rsp)
add    $0xfffffffffffffff8,%r14
jne    1160 <test_read+0x30>
test   %rax,%rax
je     11c1 <test_read+0x91>
xor    %ecx,%ecx
mov    (%rbx,%rcx,8),%rdx
mov    %rdx,(%rsp)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11b0 <test_read+0x80>
mov    (%rsp),%rax
mov    %rax,(%rsp)
xor    %eax,%eax
call   1040 <stop@plt>
lea    0xe29(%rip),%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Read : %10llu usec\0A\00"
define void @test_read(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
%9 = call i32 (...) @start()
store i64 0, i64* %5
%10 = load i64*, i64** %3
store i64* %10, i64** %6
br label %11
11: ; preds = %20, %2
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = udiv i64 %13, 8
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i64*, i64** %6
%18 = getelementptr inbounds i64, i64* %17, i32 1
store i64* %18, i64** %6
%19 = load volatile i64, i64* %17
store volatile i64 %19, i64* %7
br label %20
20: ; preds = %16
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %5
br label %11
23: ; preds = %11
%24 = load volatile i64, i64* %7
store volatile i64 %24, i64* %7
%25 = call i64 (...) @stop()
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %26)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Read : %10llu usec\0A\00"
define void @test_read(i64* %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32 (...) @start()
%6 = icmp ult i64 %1, 8
br i1 %6, label %45, label %7
7: ; preds = %2
%8 = lshr i64 %1, 3
%9 = add nsw i64 %8, -1
%10 = and i64 %8, 7
%11 = icmp ult i64 %9, 7
br i1 %11, label %35, label %12
12: ; preds = %7
%13 = and i64 %8, 2305843009213693944
br label %14
14: ; preds = %14, %12
%15 = phi i64* [ %0, %12 ], [ %31, %14 ]
%16 = phi i64 [ 0, %12 ], [ %33, %14 ]
%17 = getelementptr inbounds i64, i64* %15, i64 1
%18 = load volatile i64, i64* %15
store volatile i64 %18, i64* %3
%19 = getelementptr inbounds i64, i64* %15, i64 2
%20 = load volatile i64, i64* %17
store volatile i64 %20, i64* %3
%21 = getelementptr inbounds i64, i64* %15, i64 3
%22 = load volatile i64, i64* %19
store volatile i64 %22, i64* %3
%23 = getelementptr inbounds i64, i64* %15, i64 4
%24 = load volatile i64, i64* %21
store volatile i64 %24, i64* %3
%25 = getelementptr inbounds i64, i64* %15, i64 5
%26 = load volatile i64, i64* %23
store volatile i64 %26, i64* %3
%27 = getelementptr inbounds i64, i64* %15, i64 6
%28 = load volatile i64, i64* %25
store volatile i64 %28, i64* %3
%29 = getelementptr inbounds i64, i64* %15, i64 7
%30 = load volatile i64, i64* %27
store volatile i64 %30, i64* %3
%31 = getelementptr inbounds i64, i64* %15, i64 8
%32 = load volatile i64, i64* %29
store volatile i64 %32, i64* %3
%33 = add i64 %16, 8
%34 = icmp eq i64 %33, %13
br i1 %34, label %35, label %14
35: ; preds = %14, %7
%36 = phi i64* [ %0, %7 ], [ %31, %14 ]
%37 = icmp eq i64 %10, 0
br i1 %37, label %45, label %38
38: ; preds = %35, %38
%39 = phi i64* [ %41, %38 ], [ %36, %35 ]
%40 = phi i64 [ %43, %38 ], [ 0, %35 ]
%41 = getelementptr inbounds i64, i64* %39, i64 1
%42 = load volatile i64, i64* %39
store volatile i64 %42, i64* %3
%43 = add i64 %40, 1
%44 = icmp eq i64 %43, %10
br i1 %44, label %45, label %38
45: ; preds = %35, %38, %2
%46 = load volatile i64, i64* %3
store volatile i64 %46, i64* %3
%47 = tail call i64 (...) @stop()
%48 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %47)
ret void
}