#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*/ memcpy(unsigned long long *, unsigned long long *, size_t);
void *random64();
void random_memory(void *buf, size_t len) {
  unsigned long long *ptr = buf;
  size_t words = len >> 3;
  while (words--)
    *ptr++ = random64();
  if (len & 7) {
    unsigned long long last = random64();
    memcpy(ptr, &last, len & 7);
  }
}


x86 assembly (clang, -O0):
<random_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     117e <random_memory+0x5e>
mov    $0x0,%al
call   1040 <random64@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
jmp    1144 <random_memory+0x24>
mov    -0x10(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     11b0 <random_memory+0x90>
mov    $0x0,%al
call   1040 <random64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
and    $0x7,%rdx
lea    -0x28(%rbp),%rsi
call   1030 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_memory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x8,%rsi
jb     1159 <random_memory+0x39>
mov    %r14,%rbx
shr    $0x3,%rbx
mov    %r15,%r12
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <random64@plt>
lea    0x8(%r12),%r15
mov    %rax,(%r12)
mov    %r15,%r12
add    $0xffffffffffffffff,%rbx
jne    1140 <random_memory+0x20>
and    $0x7,%r14
je     1178 <random_memory+0x58>
xor    %eax,%eax
call   1040 <random64@plt>
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1030 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @random_memory(i8* %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i8* %0 to i64*
%5 = icmp ult i64 %1, 8
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = lshr i64 %1, 3
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %11, %8 ], [ %7, %6 ]
%10 = phi i64* [ %14, %8 ], [ %4, %6 ]
%11 = add nsw i64 %9, -1
%12 = tail call i8* (...) @random64()
%13 = ptrtoint i8* %12 to i64
%14 = getelementptr inbounds i64, i64* %10, i64 1
store i64 %13, i64* %10
%15 = icmp eq i64 %11, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = phi i64* [ %4, %2 ], [ %14, %8 ]
%18 = and i64 %1, 7
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = bitcast i64* %3 to i8*
%22 = tail call i8* (...) @random64()
%23 = ptrtoint i8* %22 to i64
store i64 %23, i64* %3
%24 = call i32 @memcpy(i64* %17, i64* %3, i64 %18)
br label %25
25: ; preds = %20, %16
ret void
}