#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 /*<<< orphan*/ uint64_t;
struct timezone {
  int dummy;
};
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ random();
int /*<<< orphan*/ srandom(scalar_t__);
uint64_t anerd_salt(uint64_t salt) {
  struct timeval tv;
  struct timezone tz;
  static int init = 0;
  if (!init) {
    gettimeofday(&tv, &tz);
    srandom(1000000 * tv.tv_sec + tv.tv_usec);
    init++;
  }
  salt ^= random();
  return salt;
}


x86 assembly (clang, -O0):
<anerd_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2efa(%rip)
jne    1177 <anerd_salt+0x47>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x18(%rbp),%eax
movslq %eax,%rdi
add    -0x10(%rbp),%rdi
call   1030 <srandom@plt>
mov    0x2ece(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ec5(%rip)
mov    $0x0,%al
call   1050 <random@plt>
xor    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anerd_salt>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
cmpl   $0x0,0x2efe(%rip)
jne    116c <anerd_salt+0x3c>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rdi
add    0x18(%rsp),%rdi
call   1030 <srandom@plt>
addl   $0x1,0x2ed0(%rip)
xor    %eax,%eax
call   1050 <random@plt>
xor    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.timezone = type { i32 }
@anerd_salt.init = internal global i32 0
define i32 @anerd_salt(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
store i32 %0, i32* %2
%5 = load i32, i32* @anerd_salt.init
%6 = icmp ne i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%10 = load i32, i32* %9
%11 = mul nsw i32 1000000, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%14 = load i64, i64* %13
%15 = add nsw i64 %12, %14
%16 = call i32 @srandom(i64 %15)
%17 = load i32, i32* @anerd_salt.init
%18 = add nsw i32 %17, 1
store i32 %18, i32* @anerd_salt.init
br label %19
19: ; preds = %7, %1
%20 = call i32 (...) @random()
%21 = load i32, i32* %2
%22 = xor i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.timezone = type { i32 }
@anerd_salt.init = internal unnamed_addr global i32 0
define i32 @anerd_salt(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = load i32, i32* @anerd_salt.init
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000000
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%15 = load i64, i64* %14
%16 = add nsw i64 %15, %13
%17 = tail call i32 @srandom(i64 %16)
%18 = load i32, i32* @anerd_salt.init
%19 = add nsw i32 %18, 1
store i32 %19, i32* @anerd_salt.init
br label %20
20: ; preds = %8, %1
%21 = tail call i32 (...) @random()
%22 = xor i32 %21, %0
ret i32 %22
}