#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 scalar_t__ uint8_t;
struct timespec {
  int dummy;
};
typedef int /*<<< orphan*/ now;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ srand(unsigned int);
void time_random_seed(void) {
  struct timespec now;
  uint8_t *c = (uint8_t *)&now;
  size_t i;
  unsigned int s = 0;
  clock_gettime(CLOCK_REALTIME, &now);
  for (i = 0; i < sizeof(now); i++) {
    s *= 127u;
    s += c[i];
  }
  srand(s);
}


x86 assembly (clang, -O0):
<time_random_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x4,-0x18(%rbp)
jae    1189 <time_random_seed+0x69>
imul   $0x7f,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x1c(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <time_random_seed+0x31>
mov    -0x1c(%rbp),%edi
call   1040 <srand@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_random_seed>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
imul   $0x1f8100,(%rsp),%edi
call   1040 <srand@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define void @time_random_seed() {
%1 = alloca %struct.timespec
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i32
%5 = bitcast %struct.timespec* %1 to i64*
store i64* %5, i64** %2
store i32 0, i32* %4
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %1)
store i64 0, i64* %3
br label %8
8: ; preds = %22, %0
%9 = load i64, i64* %3
%10 = icmp ult i64 %9, 4
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %4
%13 = mul i32 %12, 127
store i32 %13, i32* %4
%14 = load i64*, i64** %2
%15 = load i64, i64* %3
%16 = getelementptr inbounds i64, i64* %14, i64 %15
%17 = load i64, i64* %16
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %4
br label %22
22: ; preds = %11
%23 = load i64, i64* %3
%24 = add i64 %23, 1
store i64 %24, i64* %3
br label %8
25: ; preds = %8
%26 = load i32, i32* %4
%27 = call i32 @srand(i32 %26)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define void @time_random_seed() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = bitcast %struct.timespec* %1 to i64*
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %1)
%6 = load i64, i64* %3
%7 = trunc i64 %6 to i32
%8 = mul i32 %7, 2064640
%9 = call i32 @srand(i32 %8)
ret void
}