#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 {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int rand();
int random();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ srandom(unsigned int);
int main() {
  struct timeval tv;
  int ret = gettimeofday(&tv, NULL);
  if (ret == -1) {
    perror("gtm failed");
    return -1;
  }
  srand((unsigned int)tv.tv_usec);
  printf("%d\n", rand());
  printf("%d\n", rand());
  printf("%d\n", rand());
  printf("%d\n", rand());
  printf("%d\n", rand());
  srandom((unsigned int)tv.tv_usec);
  printf("%d\n", random());
  printf("%d\n", random());
  printf("%d\n", random());
  printf("%d\n", random());
  printf("%d\n", random());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b1 <main+0x41>
lea    0xe60(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%esi
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%esi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%esi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%esi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1030 <srandom@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xda1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%esi
lea    0xd77(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     125f <main+0xef>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
lea    0xe62(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1030 <srandom@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd9a(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1253 <main+0xe3>

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [11 x i8] c"gtm failed\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %38
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
%14 = call i32 (...) @rand()
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @rand()
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @rand()
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @rand()
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @rand()
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%25 = load i64, i64* %24
%26 = trunc i64 %25 to i32
%27 = call i32 @srandom(i32 %26)
%28 = call i32 (...) @random()
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 (...) @random()
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @random()
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 (...) @random()
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 (...) @random()
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i32 0, i32* %1
br label %38
38: ; preds = %9, %7
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [11 x i8] c"gtm failed\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %33
7: ; preds = %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @srand(i32 %10)
%12 = tail call i32 (...) @rand()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @rand()
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @rand()
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = tail call i32 (...) @rand()
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = tail call i32 (...) @rand()
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = tail call i32 @srandom(i32 %10)
%23 = tail call i32 (...) @random()
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = tail call i32 (...) @random()
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = tail call i32 (...) @random()
%28 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = tail call i32 (...) @random()
%30 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = tail call i32 (...) @random()
%32 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %7, %5
%34 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %34
}