#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 uint64_t;

/* Variables and functions */
int rnd64();
void rnd(void *dst, size_t len) {
  unsigned char *buf;
  size_t u;
  uint64_t x;
  buf = dst;
  x = 0;
  for (u = 0; u < len; u++) {
    if ((u & 7) == 0) {
      x = rnd64();
    }
    buf[u] = (unsigned char)x;
    x >>= 8;
  }
}


x86 assembly (clang, -O0):
<rnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118b <rnd+0x7b>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1161 <rnd+0x51>
mov    $0x0,%al
call   1030 <rnd64@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1137 <rnd+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnd>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     114e <rnd+0x3e>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
xor    %ebx,%ebx
jmp    1140 <rnd+0x30>
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
sar    $0x8,%eax
add    $0x1,%rbx
cmp    %rbx,%r15
je     114e <rnd+0x3e>
test   $0x7,%bl
jne    1130 <rnd+0x20>
xor    %eax,%eax
call   1030 <rnd64@plt>
jmp    1130 <rnd+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @rnd(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2, %11
%5 = phi i32 [ %15, %11 ], [ 0, %2 ]
%6 = phi i64 [ %16, %11 ], [ 0, %2 ]
%7 = and i64 %6, 7
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 (...) @rnd64()
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %10, %9 ], [ %5, %4 ]
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %13, i8* %14
%15 = ashr i32 %12, 8
%16 = add nuw i64 %6, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %18, label %4
18: ; preds = %11, %2
ret void
}