#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*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int main() {
  int i, v, count[2];
  srand(0);
  count[0] = count[1] = 0;
  for (i = 0; i < 1000; i++) {
    v = (rand() + i) & 1;
    count[v]++;
  }
  if (count[0] == 0 || count[1] == 0) {
    printf("bad random generator\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1040 <srand@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1195 <main+0x65>
mov    $0x0,%al
call   1050 <rand@plt>
add    -0x8(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    -0x14(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x2b>
cmpl   $0x0,-0x14(%rbp)
je     11a9 <main+0x79>
cmpl   $0x0,-0x10(%rbp)
jne    11c1 <main+0x91>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <main+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1040 <srand@plt>
movq   $0x0,0x8(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
add    %ebx,%eax
and    $0x1,%eax
addl   $0x1,0x8(%rsp,%rax,4)
add    $0x1,%ebx
cmp    $0x3e8,%ebx
jne    1150 <main+0x20>
cmpl   $0x0,0x8(%rsp)
je     117c <main+0x4c>
xor    %eax,%eax
cmpl   $0x0,0xc(%rsp)
jne    118d <main+0x5d>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"bad random generator\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
store i32 0, i32* %1
%5 = call i32 @srand(i32 0)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 0, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 0, i32* %7
store i32 0, i32* %2
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = load i32, i32* %2
%14 = add nsw i32 %12, %13
%15 = and i32 %14, 1
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %11
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %8
24: ; preds = %8
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28, %24
%33 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %35
34: ; preds = %28
store i32 0, i32* %1
br label %35
35: ; preds = %34, %32
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@str = [21 x i8] c"bad random generator\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = tail call i32 @srand(i32 0)
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
store i32 0, i32* %4
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 0, i32* %5
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %15, %6 ]
%8 = tail call i32 (...) @rand()
%9 = add nsw i32 %8, %7
%10 = and i32 %9, 1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %12
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %17, %23
%26 = phi i32 [ 1, %23 ], [ 0, %17 ]
ret i32 %26
}