#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 rand();
int /*<<< orphan*/ srand(unsigned int);
int myrand(void) {
  struct timeval tv;
  unsigned int seed;
  gettimeofday(&tv, NULL);
  seed = (tv.tv_sec % 10000) * 523 + tv.tv_usec * 13 + (getpid() % 1000) * 983;
  srand(seed);
  return rand();
}


x86 assembly (clang, -O0):
<myrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
imul   $0x20b,%edx,%eax
imul   $0xd,-0x4(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%eax
imul   $0x3d7,%edx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myrand>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
imul   $0x20b,%eax,%eax
mov    0xc(%rsp),%ecx
lea    (%rcx,%rcx,2),%edx
lea    (%rcx,%rdx,4),%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0x3d7,%eax,%edi
add    %ebx,%edi
call   1050 <srand@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1060 <rand@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @myrand() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%5 = load i32, i32* %4
%6 = srem i32 %5, 10000
%7 = mul nsw i32 %6, 523
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 13
%11 = add nsw i32 %7, %10
%12 = call i32 (...) @getpid()
%13 = srem i32 %12, 1000
%14 = mul nsw i32 %13, 983
%15 = add nsw i32 %11, %14
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @srand(i32 %16)
%18 = call i32 (...) @rand()
ret i32 %18
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @myrand() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = srem i32 %5, 10000
%7 = mul nsw i32 %6, 523
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 13
%11 = add nsw i32 %7, %10
%12 = tail call i32 (...) @getpid()
%13 = srem i32 %12, 1000
%14 = mul nsw i32 %13, 983
%15 = add nsw i32 %11, %14
%16 = tail call i32 @srand(i32 %15)
%17 = tail call i32 (...) @rand()
ret i32 %17
}