#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 Random(int *, int *);
int /*<<< orphan*/ printf(char *, int, int, int, int);
void main(void) {
  int i, above, below, maxdif, newv;
  int median;
  int m_w = 177;
  int m_z = 311;
  above = below = maxdif = 0;
  median = 0xffffffff;
  for (i = 1; i <= 100; i++) {
    if (Random(&m_z, &m_w) <= median)
      below++;
    else
      above++;
    if ((newv = (((above - below) < 0) ? -(above - below) : (above - below))) >
        maxdif)
      maxdif = newv;
    if ((i % (100 / 5)) == 0) {
      printf("%08x\n%08x\n%08x\n%08x\n\n", i, above, below, maxdif);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xb1,-0x1c(%rbp)
movl   $0x137,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x1,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jg     120f <main+0xef>
lea    -0x20(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <Random@plt>
cmp    -0x18(%rbp),%eax
jg     1187 <main+0x67>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1190 <main+0x70>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x0,%eax
jge    11b1 <main+0x91>
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <main+0x9a>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
jle    11cf <main+0xaf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fc <main+0xdc>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
jmp    1201 <main+0xe1>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1159 <main+0x39>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0xb1,0x14(%rsp)
movl   $0x137,0x10(%rsp)
xor    %ebp,%ebp
mov    $0x1,%r13d
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    115a <main+0x3a>
nopl   (%rax)
add    $0x1,%r13d
cmp    $0x65,%r13d
je     11d9 <main+0xb9>
mov    %ebx,0x8(%rsp)
mov    %r12d,0xc(%rsp)
mov    %ebp,%r12d
movzbl %r13b,%r15d
imul   $0xcd,%r15d,%eax
shr    $0xa,%eax
and    $0xfffffffc,%eax
lea    (%rax,%rax,4),%r14d
neg    %r14d
lea    0x10(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1040 <Random@plt>
mov    %eax,%ebp
mov    %eax,%ebx
shr    $0x1f,%ebx
add    0x8(%rsp),%ebx
not    %ebp
shr    $0x1f,%ebp
add    %r12d,%ebp
mov    %ebp,%eax
sub    %ebx,%eax
mov    %eax,%r12d
neg    %r12d
cmovs  %eax,%r12d
mov    0xc(%rsp),%eax
cmp    %eax,%r12d
cmovle %eax,%r12d
add    %r14b,%r15b
jne    1150 <main+0x30>
lea    0xe3b(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r12d,%r8d
call   1030 <printf@plt>
jmp    1150 <main+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%08x\0A%08x\0A%08x\0A%08x\0A\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 177, i32* %7
store i32 311, i32* %8
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
store i32 -1, i32* %6
store i32 1, i32* %1
br label %9
9: ; preds = %53, %0
%10 = load i32, i32* %1
%11 = icmp sle i32 %10, 100
br i1 %11, label %12, label %56
12: ; preds = %9
%13 = call i32 @Random(i32* %8, i32* %7)
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %22
19: ; preds = %12
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = sub nsw i32 %23, %24
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = sub nsw i32 %28, %29
%31 = sub nsw i32 0, %30
br label %36
32: ; preds = %22
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = sub nsw i32 %33, %34
br label %36
36: ; preds = %32, %27
%37 = phi i32 [ %31, %27 ], [ %35, %32 ]
store i32 %37, i32* %5
%38 = load i32, i32* %4
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %5
store i32 %41, i32* %4
br label %42
42: ; preds = %40, %36
%43 = load i32, i32* %1
%44 = srem i32 %43, 20
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32, i32* %1
%48 = load i32, i32* %2
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %48, i32 %49, i32 %50)
br label %52
52: ; preds = %46, %42
br label %53
53: ; preds = %52
%54 = load i32, i32* %1
%55 = add nsw i32 %54, 1
store i32 %55, i32* %1
br label %9
56: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"%08x\0A%08x\0A%08x\0A%08x\0A\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 177, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 311, i32* %2
br label %5
5: ; preds = %0, %25
%6 = phi i32 [ 1, %0 ], [ %26, %25 ]
%7 = phi i32 [ 0, %0 ], [ %15, %25 ]
%8 = phi i32 [ 0, %0 ], [ %19, %25 ]
%9 = phi i32 [ 0, %0 ], [ %12, %25 ]
%10 = call i32 @Random(i32* %2, i32* %1)
%11 = lshr i32 %10, 31
%12 = add nuw nsw i32 %11, %9
%13 = xor i32 %10, -1
%14 = lshr i32 %13, 31
%15 = add nuw nsw i32 %14, %7
%16 = sub nsw i32 %15, %12
%17 = call i32 @llvm.abs.i32(i32 %16, i1 true)
%18 = icmp sgt i32 %17, %8
%19 = select i1 %18, i32 %17, i32 %8
%20 = trunc i32 %6 to i8
%21 = urem i8 %20, 20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %15, i32 %12, i32 %19)
br label %25
25: ; preds = %5, %23
%26 = add nuw nsw i32 %6, 1
%27 = icmp eq i32 %26, 101
br i1 %27, label %28, label %5
28: ; preds = %25
ret void
}