#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*/ err(int, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned int seed_of_time(void) {
  static unsigned int counter = 1;
  struct timeval tv;
  if (0 != gettimeofday(&tv, NULL)) {
    err(1, "gettimeofday");
  }
  return (unsigned int)(~(tv.tv_sec ^ tv.tv_usec) * counter++);
}


x86 assembly (clang, -O0):
<seed_of_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1154 <seed_of_time+0x34>
mov    $0x1,%edi
lea    0xeb1(%rip),%rsi
call   1040 <err@plt>
mov    -0x8(%rbp),%eax
xor    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
mov    0x2ecd(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2ec2(%rip)
imul   %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seed_of_time>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
je     1141 <seed_of_time+0x21>
lea    0xec9(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    (%rsp),%eax
xor    0x4(%rsp),%eax
not    %eax
mov    0x2ee0(%rip),%ecx
lea    0x1(%rcx),%edx
mov    %edx,0x2ed7(%rip)
imul   %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@seed_of_time.counter = internal global i32 1
@.str = [13 x i8] c"gettimeofday\00"
define i32 @seed_of_time() {
%1 = alloca %struct.timeval
%2 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%3 = icmp ne i64 0, %2
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i32, i32* %9
%11 = xor i32 %8, %10
%12 = xor i32 %11, -1
%13 = load i32, i32* @seed_of_time.counter
%14 = add i32 %13, 1
store i32 %14, i32* @seed_of_time.counter
%15 = mul i32 %12, %13
ret i32 %15
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@seed_of_time.counter = internal unnamed_addr global i32 1
@.str = [13 x i8] c"gettimeofday\00"
define i32 @seed_of_time() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = xor i32 %9, %11
%13 = xor i32 %12, -1
%14 = load i32, i32* @seed_of_time.counter
%15 = add i32 %14, 1
store i32 %15, i32* @seed_of_time.counter
%16 = mul i32 %14, %13
ret i32 %16
}