#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; i += 8)
    *q++ = xrand();
  uint8_t *r = (uint8_t *)q;
  for (; 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
cmp    -0xc(%rbp),%eax
jge    1162 <memrand+0x52>
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    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <memrand+0x1e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <memrand+0x94>
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    116a <memrand+0x5a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memrand>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %ebp,%ebp
test   %esi,%esi
jle    1135 <memrand+0x25>
xor    %eax,%eax
call   1030 <xrand@plt>
mov    %eax,(%rbx)
add    $0x4,%rbx
add    $0x8,%ebp
cmp    %r14d,%ebp
jl     1120 <memrand+0x10>
cmp    %r14d,%ebp
jge    1156 <memrand+0x46>
sub    %ebp,%r14d
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   1030 <xrand@plt>
movzbl %al,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    1140 <memrand+0x30>
pop    %rbx
pop    %r14
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 = %18, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = call i32 (...) @xrand()
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %5
store i32 %15, i32* %16
br label %18
18: ; preds = %14
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 8
store i32 %20, i32* %6
br label %10
21: ; preds = %10
%22 = load i32*, i32** %5
store i32* %22, i32** %7
br label %23
23: ; preds = %32, %21
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = call i32 (...) @xrand()
%29 = and i32 %28, 255
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %7
store i32 %29, i32* %30
br label %32
32: ; preds = %27
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %23
35: ; preds = %23
ret void
}

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