#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 timezone {
  scalar_t__ tz_dsttime;
  scalar_t__ tz_minuteswest;
};
struct timeval {
  long tv_usec;
};

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ srand(long);
scalar_t__ time(int /*<<< orphan*/ *);
__attribute__((visibility("hidden"))) void SYS_InitRandom(void) {
  struct timeval tv;
  struct timezone tz;
  long myseed = 0;
  tz.tz_minuteswest = 0;
  tz.tz_dsttime = 0;
  if (gettimeofday(&tv, &tz) == 0) {
    myseed = tv.tv_usec;
  } else {
    myseed = (long)time(NULL);
  }
  srand(myseed);
}


x86 assembly (clang, -O0):
<SYS_InitRandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jne    1174 <SYS_InitRandom+0x44>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1181 <SYS_InitRandom+0x51>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <srand@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SYS_InitRandom>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gettimeofday@plt>
test   %rax,%rax
je     1163 <SYS_InitRandom+0x33>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,%rdi
add    $0x28,%rsp
jmp    1040 <srand@plt>
mov    0x8(%rsp),%rdi
add    $0x28,%rsp
jmp    1040 <srand@plt>

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.timezone = type { i64, i64 }
define hidden void @SYS_InitRandom() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = alloca i64
store i64 0, i64* %3
%4 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i32 0, i32 0
store i64 0, i64* %5
%6 = call i64 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%10 = load i64, i64* %9
store i64 %10, i64* %3
br label %13
11: ; preds = %0
%12 = call i64 @time(i32* null)
store i64 %12, i64* %3
br label %13
13: ; preds = %11, %8
%14 = load i64, i64* %3
%15 = call i32 @srand(i64 %14)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.timezone = type { i64, i64 }
define hidden void @SYS_InitRandom() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = bitcast %struct.timezone* %2 to i8*
%6 = call i64 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i64, i64* %9
br label %13
11: ; preds = %0
%12 = tail call i64 @time(i32* null)
br label %13
13: ; preds = %11, %8
%14 = phi i64 [ %10, %8 ], [ %12, %11 ]
%15 = tail call i32 @srand(i64 %14)
ret void
}