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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ shiftarray(int *);
int /*<<< orphan*/ srand(int);
int hit(int *future) {
  struct timespec a;
  a.tv_sec = 0;
  a.tv_nsec = 1000;
  nanosleep(&a, NULL);
  struct timeval t1;
  gettimeofday(&t1, NULL);
  srand(t1.tv_usec * t1.tv_sec);
  int k;
  if (*future >= 0) {
    k = *future;
    shiftarray(future);
  } else
    k = rand() % 13;
  if (k > 8)
    return 10;
  return k + 1;
}


x86 assembly (clang, -O0):
<hit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x3e8,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%edi
imul   -0x24(%rbp),%edi
call   1050 <srand@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11b5 <hit+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <shiftarray@plt>
jmp    11c7 <hit+0x77>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jle    11dd <hit+0x8d>
movl   $0xa,-0x4(%rbp)
jmp    11e6 <hit+0x96>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hit>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
movl   $0x3e8,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x4(%rsp),%edi
imul   (%rsp),%edi
call   1050 <srand@plt>
mov    (%r14),%ebx
test   %ebx,%ebx
js     119f <hit+0x4f>
mov    %r14,%rdi
call   1060 <shiftarray@plt>
jmp    11c5 <hit+0x75>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbx
imul   $0x4ec4ec4f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%eax
sub    %eax,%ebx
lea    0x1(%rbx),%ecx
cmp    $0x9,%ebx
mov    $0xa,%eax
cmovl  %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i32 }
define i32 @hit(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.timespec
%5 = alloca %struct.timeval
%6 = alloca i32
store i32* %0, i32** %3
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 1000, i32* %8
%9 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%14 = load i32, i32* %13
%15 = mul nsw i32 %12, %14
%16 = call i32 @srand(i32 %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = load i32*, i32** %3
%22 = load i32, i32* %21
store i32 %22, i32* %6
%23 = load i32*, i32** %3
%24 = call i32 @shiftarray(i32* %23)
br label %28
25: ; preds = %1
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 13
store i32 %27, i32* %6
br label %28
28: ; preds = %25, %20
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 8
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 10, i32* %2
br label %35
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %35
35: ; preds = %32, %31
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i32 }
define i32 @hit(i32* %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timeval
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 1000, i32* %6
%7 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%8 = bitcast %struct.timeval* %3 to i8*
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, %11
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %0
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @shiftarray(i32* %0)
br label %23
20: ; preds = %1
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 13
br label %23
23: ; preds = %20, %18
%24 = phi i32 [ %16, %18 ], [ %22, %20 ]
%25 = icmp sgt i32 %24, 8
%26 = add nsw i32 %24, 1
%27 = select i1 %25, i32 10, i32 %26
ret i32 %27
}