#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 timespec {
  unsigned int tv_sec;
  unsigned int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ abort();
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ random_mult();
int /*<<< orphan*/ srandom(unsigned int);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  struct timespec t;
  unsigned int seed;
  if (argc > 1) {
    seed = strtoul(argv[1], NULL, 10);
  } else {
    if (clock_gettime(CLOCK_REALTIME, &t)) {
      perror("clock_gettime");
      abort();
    }
    seed = t.tv_sec + t.tv_nsec;
  }
  printf("Seed: %u\n", seed);
  srandom(seed);
  random_mult();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ae <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
jmp    11e6 <main+0x76>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1050 <clock_gettime@plt>
cmp    $0x0,%rax
je     11dd <main+0x6d>
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <srandom@plt>
mov    $0x0,%al
call   1090 <random_mult@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     118e <main+0x1e>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,%ebx
jmp    11ae <main+0x3e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
test   %rax,%rax
jne    11d2 <main+0x62>
mov    0xc(%rsp),%ebx
add    0x8(%rsp),%ebx
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    %ebx,%edi
call   1040 <srandom@plt>
xor    %eax,%eax
call   1090 <random_mult@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@.str.1 = [10 x i8] c"Seed: %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strtoul(i8* %13, i32* null, i32 10)
store i32 %14, i32* %7
br label %28
15: ; preds = %2
%16 = load i32, i32* @CLOCK_REALTIME
%17 = call i64 @clock_gettime(i32 %16, %struct.timespec* %6)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %15
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add i32 %24, %26
store i32 %27, i32* %7
br label %28
28: ; preds = %22, %10
%29 = load i32, i32* %7
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = call i32 @srandom(i32 %31)
%33 = call i32 (...) @random_mult()
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@.str.1 = [10 x i8] c"Seed: %u\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtoul(i8* nocapture %8, i32* null, i32 10)
br label %23
10: ; preds = %2
%11 = load i32, i32* @CLOCK_REALTIME
%12 = call i64 @clock_gettime(i32 %11, %struct.timespec* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %10
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%21 = load i32, i32* %20
%22 = add i32 %21, %19
br label %23
23: ; preds = %17, %6
%24 = phi i32 [ %9, %6 ], [ %22, %17 ]
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 @srandom(i32 %24)
%27 = call i32 (...) @random_mult()
ret i32 0
}