#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 getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int getuid();
int /*<<< orphan*/ rand();
int /*<<< orphan*/ srand(int);
void crank_random(void) {
  int i;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
  gettimeofday(&tv, NULL);
  for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
    rand();
}


x86 assembly (clang, -O0):
<crank_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
shl    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%edi
xor    -0x10(%rbp),%edi
xor    -0xc(%rbp),%edi
call   1060 <srand@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
xor    -0xc(%rbp),%eax
and    $0x1f,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11c1 <crank_random+0x71>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <crank_random+0x52>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crank_random>:
push   %rbp
push   %rbx
push   %rax
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
shl    $0x10,%ebp
xor    %eax,%eax
call   1040 <getuid@plt>
xor    %eax,%ebp
xor    (%rsp),%ebp
xor    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1060 <srand@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x4(%rsp),%ebx
xor    (%rsp),%ebx
and    $0x1f,%ebx
je     11af <crank_random+0x5f>
add    $0x1,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11a0 <crank_random+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @crank_random() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%4 = call i32 (...) @getpid()
%5 = shl i32 %4, 16
%6 = call i32 (...) @getuid()
%7 = xor i32 %5, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = xor i32 %7, %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%12 = load i32, i32* %11
%13 = xor i32 %10, %12
%14 = call i32 @srand(i32 %13)
%15 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%19 = load i32, i32* %18
%20 = xor i32 %17, %19
%21 = and i32 %20, 31
store i32 %21, i32* %1
br label %22
22: ; preds = %27, %0
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = call i32 (...) @rand()
br label %27
27: ; preds = %25
%28 = load i32, i32* %1
%29 = add nsw i32 %28, -1
store i32 %29, i32* %1
br label %22
30: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @crank_random() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = tail call i32 (...) @getpid()
%5 = shl i32 %4, 16
%6 = tail call i32 (...) @getuid()
%7 = xor i32 %5, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = xor i32 %7, %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = xor i32 %10, %12
%14 = tail call i32 @srand(i32 %13)
%15 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%16 = load i32, i32* %8
%17 = load i32, i32* %11
%18 = xor i32 %17, %16
%19 = and i32 %18, 31
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %0, %21
%22 = phi i32 [ %24, %21 ], [ %19, %0 ]
%23 = tail call i32 (...) @rand()
%24 = add nsw i32 %22, -1
%25 = icmp ugt i32 %22, 1
br i1 %25, label %21, label %26
26: ; preds = %21, %0
ret void
}