#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 unsigned short ushort;
struct timezone {
  int dummy;
};
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int nrand48(unsigned short *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  unsigned short xsub[3];
  struct timeval randtime;
  gettimeofday(&randtime, (struct timezone *)0);
  xsub[0] = (ushort)(randtime.tv_usec);
  xsub[1] = (ushort)(randtime.tv_usec >> 16);
  xsub[2] = (ushort)(0);
  int i;
  for (i = 0; i < 100; i++) {
    printf("%ld\n", nrand48(xsub) & 7);
  }
  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    -0x10(%rbp),%eax
mov    %ax,-0xa(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
mov    %ax,-0x8(%rbp)
movw   $0x0,-0x6(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    119c <main+0x6c>
lea    -0xa(%rbp),%rdi
call   1030 <nrand48@plt>
mov    %eax,%esi
and    $0x7,%esi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <main+0x3a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    %ax,0x2(%rsp)
shr    $0x10,%eax
mov    %ax,0x4(%rsp)
movw   $0x0,0x6(%rsp)
mov    $0x64,%ebp
lea    0x2(%rsp),%r14
lea    0xe93(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1030 <nrand48@plt>
and    $0x7,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i16]
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%7 = load i32, i32* %6
%8 = trunc i32 %7 to i16
%9 = getelementptr inbounds [3 x i16], [3 x i16]* %2, i64 0, i64 0
store i16 %8, i16* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = ashr i32 %11, 16
%13 = trunc i32 %12 to i16
%14 = getelementptr inbounds [3 x i16], [3 x i16]* %2, i64 0, i64 1
store i16 %13, i16* %14
%15 = getelementptr inbounds [3 x i16], [3 x i16]* %2, i64 0, i64 2
store i16 0, i16* %15
store i32 0, i32* %4
br label %16
16: ; preds = %24, %0
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 100
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = getelementptr inbounds [3 x i16], [3 x i16]* %2, i64 0, i64 0
%21 = call i32 @nrand48(i16* %20)
%22 = and i32 %21, 7
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %16
27: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca [3 x i16]
%2 = alloca %struct.timeval
%3 = bitcast [3 x i16]* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%7 = load i32, i32* %6
%8 = trunc i32 %7 to i16
%9 = getelementptr inbounds [3 x i16], [3 x i16]* %1, i64 0, i64 0
store i16 %8, i16* %9
%10 = lshr i32 %7, 16
%11 = trunc i32 %10 to i16
%12 = getelementptr inbounds [3 x i16], [3 x i16]* %1, i64 0, i64 1
store i16 %11, i16* %12
%13 = getelementptr inbounds [3 x i16], [3 x i16]* %1, i64 0, i64 2
store i16 0, i16* %13
br label %14
14: ; preds = %0, %14
%15 = phi i32 [ 0, %0 ], [ %19, %14 ]
%16 = call i32 @nrand48(i16* %9)
%17 = and i32 %16, 7
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i32 %15, 1
%20 = icmp eq i32 %19, 100
br i1 %20, label %21, label %14
21: ; preds = %14
ret i32 0
}