#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 */

/* Variables and functions */
int /*<<< orphan*/ GetSeed(long *);
int /*<<< orphan*/ PlantSeeds(int);
int /*<<< orphan*/ PutSeed(int);
double Random();
int /*<<< orphan*/ SelectStream(int);
int /*<<< orphan*/ printf(char *);
void TestRandom(void) {
  long i;
  long x;
  double u;
  char ok = 0;
  SelectStream(0);
  PutSeed(1);
  for (i = 0; i < 10000; i++)
    u = Random();
  GetSeed(&x);
  ok = (x == 113988298);
  SelectStream(1);
  PlantSeeds(1);
  GetSeed(&x);
  ok = ok && (x == 22925);
  if (ok) {
    printf("\n The implementation of rngs.c is correct.\n\n");
  } else {
    printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n");
  }
}


x86 assembly (clang, -O0):
<TestRandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x0,-0x19(%rbp)
xor    %edi,%edi
call   1040 <SelectStream@plt>
mov    $0x1,%edi
call   1080 <PutSeed@plt>
movq   $0x0,-0x8(%rbp)
cmpq   $0x2710,-0x8(%rbp)
jge    11b0 <TestRandom+0x50>
mov    $0x0,%al
call   1070 <Random@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <TestRandom+0x25>
lea    -0x10(%rbp),%rdi
call   1060 <GetSeed@plt>
cmpq   $0x6cb52ca,-0x10(%rbp)
06
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x19(%rbp)
mov    $0x1,%edi
call   1040 <SelectStream@plt>
mov    $0x1,%edi
call   1030 <PlantSeeds@plt>
lea    -0x10(%rbp),%rdi
call   1060 <GetSeed@plt>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
je     1209 <TestRandom+0xa9>
cmpq   $0x598d,-0x10(%rbp)
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x19(%rbp)
cmpb   $0x0,-0x19(%rbp)
je     122f <TestRandom+0xcf>
lea    0xddb(%rip),%rdi
call   1050 <printf@plt>
jmp    123b <TestRandom+0xdb>
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestRandom>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <SelectStream@plt>
mov    $0x1,%edi
call   1080 <PutSeed@plt>
mov    $0x2710,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <Random@plt>
add    $0xffffffffffffffff,%rbx
jne    1180 <TestRandom+0x20>
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <GetSeed@plt>
mov    $0x6cb52ca,%ebx
xor    (%rsp),%rbx
mov    $0x1,%edi
call   1050 <SelectStream@plt>
mov    $0x1,%edi
call   1030 <PlantSeeds@plt>
mov    %r14,%rdi
call   1060 <GetSeed@plt>
mov    $0x598d,%eax
xor    (%rsp),%rax
lea    0xe6d(%rip),%rcx
lea    0xe2c(%rip),%rdi
or     %rbx,%rax
cmove  %rcx,%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\0A The implementation of rngs.c is correct.\0A\0A\00"
@.str.1 = [59 x i8] c"\0A\07 ERROR -- the implementation of rngs.c is not correct.\0A\0A\00"
define void @TestRandom() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca double
%4 = alloca i8
store i8 0, i8* %4
%5 = call i32 @SelectStream(i32 0)
%6 = call i32 @PutSeed(i32 1)
store i64 0, i64* %1
br label %7
7: ; preds = %12, %0
%8 = load i64, i64* %1
%9 = icmp slt i64 %8, 10000
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call double (...) @Random()
store double %11, double* %3
br label %12
12: ; preds = %10
%13 = load i64, i64* %1
%14 = add nsw i64 %13, 1
store i64 %14, i64* %1
br label %7
15: ; preds = %7
%16 = call i32 @GetSeed(i64* %2)
%17 = load i64, i64* %2
%18 = icmp eq i64 %17, 113988298
%19 = zext i1 %18 to i32
%20 = trunc i32 %19 to i8
store i8 %20, i8* %4
%21 = call i32 @SelectStream(i32 1)
%22 = call i32 @PlantSeeds(i32 1)
%23 = call i32 @GetSeed(i64* %2)
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = load i64, i64* %2
%29 = icmp eq i64 %28, 22925
br label %30
30: ; preds = %27, %15
%31 = phi i1 [ false, %15 ], [ %29, %27 ]
%32 = zext i1 %31 to i32
%33 = trunc i32 %32 to i8
store i8 %33, i8* %4
%34 = load i8, i8* %4
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %40
38: ; preds = %30
%39 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
ret void
}

LLVM IR (-O2):
@str = [58 x i8] c"\0A\07 ERROR -- the implementation of rngs.c is not correct.\0A\00"
@str.2 = [44 x i8] c"\0A The implementation of rngs.c is correct.\0A\00"
define void @TestRandom() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @SelectStream(i32 0)
%4 = tail call i32 @PutSeed(i32 1)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %8, %5 ]
%7 = tail call double (...) @Random()
%8 = add nuw nsw i64 %6, 1
%9 = icmp eq i64 %8, 10000
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = call i32 @GetSeed(i64* %1)
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 113988298
%14 = call i32 @SelectStream(i32 1)
%15 = call i32 @PlantSeeds(i32 1)
%16 = call i32 @GetSeed(i64* %1)
%17 = load i64, i64* %1
%18 = icmp eq i64 %17, 22925
%19 = select i1 %13, i1 %18, i1 false
%20 = select i1 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0)
%21 = call i32 @puts(i8* dereferenceable(1) %20)
ret void
}