#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(unsigned int);
void fill_with_random(unsigned char *buf, unsigned int size) {
  int i;
  struct timeval tv;
  unsigned int seed;
  gettimeofday(&tv, NULL);
  seed = (tv.tv_sec + (tv.tv_sec << 11)) ^ (tv.tv_usec + (tv.tv_usec << 17));
  srand(seed);
  for (i = 0; i < size; i++)
    buf[i] = rand() % 0xff;
}


x86 assembly (clang, -O0):
<fill_with_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0xb,%ecx
add    %ecx,%eax
mov    -0x14(%rbp),%ecx
mov    -0x14(%rbp),%edx
shl    $0x11,%edx
add    %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11aa <fill_with_random+0x7a>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <fill_with_random+0x46>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_with_random>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
mov    %eax,%edx
shl    $0xb,%edx
add    %eax,%edx
mov    %ecx,%edi
shl    $0x11,%edi
add    %ecx,%edi
xor    %edx,%edi
call   1040 <srand@plt>
test   %ebp,%ebp
je     119f <fill_with_random+0x6f>
mov    %ebp,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <fill_with_random+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @fill_with_random(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%12 = load i32, i32* %11
%13 = shl i32 %12, 11
%14 = add nsw i32 %10, %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = shl i32 %18, 17
%20 = add nsw i32 %16, %19
%21 = xor i32 %14, %20
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i32 @srand(i32 %22)
store i32 0, i32* %5
br label %24
24: ; preds = %36, %2
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp ult i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 255
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %28
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %24
39: ; preds = %24
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @fill_with_random(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = mul i32 %7, 2049
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = mul i32 %10, 131073
%12 = xor i32 %11, %8
%13 = tail call i32 @srand(i32 %12)
%14 = icmp eq i32 %1, 0
br i1 %14, label %25, label %15
15: ; preds = %2
%16 = zext i32 %1 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %23, %17 ]
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %21, i8* %22
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %16
br i1 %24, label %25, label %17
25: ; preds = %17, %2
ret void
}