#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*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int xrand();
void memrand(void *p, int size) {
  uint64_t *q = (uint64_t *)p;
  int i;
  for (i = 0; i < size / 8; i++)
    *q++ = xrand();
  uint8_t *r = (uint8_t *)q;
  for (i *= 8; i < size; i++)
    *r++ = xrand() & 0xff;
}


x86 assembly (clang, -O0):
<memrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1174 <memrand+0x64>
mov    $0x0,%al
call   1030 <xrand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <memrand+0x1e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <memrand+0xaf>
mov    $0x0,%al
call   1030 <xrand@plt>
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x28(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <memrand+0x75>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memrand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x7(%r14),%r15d
test   %esi,%esi
cmovns %esi,%r15d
cmp    $0x8,%esi
jl     115d <memrand+0x4d>
sar    $0x3,%r15d
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <xrand@plt>
mov    %eax,(%rbx)
add    $0x4,%rbx
add    $0xffffffff,%ebp
jne    1140 <memrand+0x30>
shl    $0x3,%r15d
cmp    %r14d,%r15d
jl     1165 <memrand+0x55>
jmp    1186 <memrand+0x76>
xor    %r15d,%r15d
cmp    %r14d,%r15d
jge    1186 <memrand+0x76>
sub    %r15d,%r14d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <xrand@plt>
movzbl %al,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    1170 <memrand+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @memrand(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %5
store i32 0, i32* %6
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = sdiv i32 %12, 8
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = call i32 (...) @xrand()
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %5
store i32 %16, i32* %17
br label %19
19: ; preds = %15
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %10
22: ; preds = %10
%23 = load i32*, i32** %5
store i32* %23, i32** %7
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 8
store i32 %25, i32* %6
br label %26
26: ; preds = %35, %22
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = call i32 (...) @xrand()
%32 = and i32 %31, 255
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i32 1
store i32* %34, i32** %7
store i32 %32, i32* %33
br label %35
35: ; preds = %30
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %26
38: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @memrand(i8* nocapture writeonly %0, i32 %1) {
%3 = bitcast i8* %0 to i32*
%4 = sdiv i32 %1, 8
%5 = icmp sgt i32 %1, 7
br i1 %5, label %6, label %15
6: ; preds = %2, %6
%7 = phi i32 [ %11, %6 ], [ 0, %2 ]
%8 = phi i32* [ %10, %6 ], [ %3, %2 ]
%9 = tail call i32 (...) @xrand()
%10 = getelementptr inbounds i32, i32* %8, i64 1
store i32 %9, i32* %8
%11 = add nuw nsw i32 %7, 1
%12 = icmp eq i32 %11, %4
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = shl nsw i32 %4, 3
br label %15
15: ; preds = %13, %2
%16 = phi i32* [ %3, %2 ], [ %10, %13 ]
%17 = phi i32 [ 0, %2 ], [ %14, %13 ]
%18 = icmp slt i32 %17, %1
br i1 %18, label %19, label %27
19: ; preds = %15, %19
%20 = phi i32* [ %24, %19 ], [ %16, %15 ]
%21 = phi i32 [ %25, %19 ], [ %17, %15 ]
%22 = tail call i32 (...) @xrand()
%23 = and i32 %22, 255
%24 = getelementptr inbounds i32, i32* %20, i64 1
store i32 %23, i32* %20
%25 = add i32 %21, 1
%26 = icmp eq i32 %25, %1
br i1 %26, label %27, label %19
27: ; preds = %19, %15
ret void
}