#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);
int /*<<< orphan*/ Random();
int /*<<< orphan*/ SelectStream(int);
int /*<<< orphan*/ printf(char *);
void TestRandom(void) {
  long i;
  long x;
  char ok = 0;
  SelectStream(0);
  PutSeed(1);
  for (i = 0; i < 10000; i++)
    Random();
  GetSeed(&x);
  ok = (x == 399268537);
  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,-0x11(%rbp)
xor    %edi,%edi
call   1040 <SelectStream@plt>
mov    $0x1,%edi
call   1080 <PutSeed@plt>
movq   $0x0,-0x8(%rbp)
cmpq   $0x2710,-0x8(%rbp)
jge    11ab <TestRandom+0x4b>
mov    $0x0,%al
call   1070 <Random@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <TestRandom+0x25>
lea    -0x10(%rbp),%rdi
call   1060 <GetSeed@plt>
cmpq   $0x17cc5ab9,-0x10(%rbp)
17
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x11(%rbp)
mov    $0x1,%edi
call   1040 <SelectStream@plt>
mov    $0x1,%edi
call   1030 <PlantSeeds@plt>
lea    -0x10(%rbp),%rdi
call   1060 <GetSeed@plt>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
je     1204 <TestRandom+0xa4>
cmpq   $0x598d,-0x10(%rbp)
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x11(%rbp)
cmpb   $0x0,-0x11(%rbp)
je     122a <TestRandom+0xca>
lea    0xde0(%rip),%rdi
call   1050 <printf@plt>
jmp    1236 <TestRandom+0xd6>
lea    0xdfc(%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    $0x17cc5ab9,%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 i8
store i8 0, i8* %3
%4 = call i32 @SelectStream(i32 0)
%5 = call i32 @PutSeed(i32 1)
store i64 0, i64* %1
br label %6
6: ; preds = %11, %0
%7 = load i64, i64* %1
%8 = icmp slt i64 %7, 10000
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 (...) @Random()
br label %11
11: ; preds = %9
%12 = load i64, i64* %1
%13 = add nsw i64 %12, 1
store i64 %13, i64* %1
br label %6
14: ; preds = %6
%15 = call i32 @GetSeed(i64* %2)
%16 = load i64, i64* %2
%17 = icmp eq i64 %16, 399268537
%18 = zext i1 %17 to i32
%19 = trunc i32 %18 to i8
store i8 %19, i8* %3
%20 = call i32 @SelectStream(i32 1)
%21 = call i32 @PlantSeeds(i32 1)
%22 = call i32 @GetSeed(i64* %2)
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %14
%27 = load i64, i64* %2
%28 = icmp eq i64 %27, 22925
br label %29
29: ; preds = %26, %14
%30 = phi i1 [ false, %14 ], [ %28, %26 ]
%31 = zext i1 %30 to i32
%32 = trunc i32 %31 to i8
store i8 %32, i8* %3
%33 = load i8, i8* %3
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %39
37: ; preds = %29
%38 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
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 i32 (...) @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, 399268537
%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
}