#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 INT_MAX;
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(unsigned int);
unsigned int randomi(int *value) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) == 0) {
    unsigned int usec = (unsigned int)(tv.tv_usec);
    srand(usec);
    *value = rand() % INT_MAX;
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<randomi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jne    1185 <randomi+0x55>
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    0x2e78(%rip),%rcx
cltd
idivl  (%rcx)
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    118c <randomi+0x5c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomi>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    116f <randomi+0x3f>
mov    0x8(%rsp),%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1050 <rand@plt>
mov    0x2e80(%rip),%rcx
cltd
idivl  (%rcx)
mov    %edx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@INT_MAX = global i32 0
define i32 @randomi(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.timeval
%5 = alloca i32
store i32* %0, i32** %3
%6 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i32 @srand(i32 %12)
%14 = call i32 (...) @rand()
%15 = load i32, i32* @INT_MAX
%16 = srem i32 %14, %15
%17 = load i32*, i32** %3
store i32 %16, i32* %17
store i32 0, i32* %2
br label %19
18: ; preds = %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@INT_MAX = global i32 0
define i32 @randomi(i32* nocapture writeonly %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 @srand(i32 %9)
%11 = tail call i32 (...) @rand()
%12 = load i32, i32* @INT_MAX
%13 = srem i32 %11, %12
store i32 %13, i32* %0
br label %14
14: ; preds = %1, %6
%15 = phi i32 [ 0, %6 ], [ 1, %1 ]
ret i32 %15
}