#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
double RAND_MAX;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int nleft = 800, t = 0;
  double r, error_bar, error = 0, sigma;
  FILE *graf;
  graf = fopen("graf5.dat", "w");
  srand(time(NULL));
  while (t < 100000) {
    r = rand() * 1.0 / RAND_MAX;
    if (r <= 0.5 & nleft > 0) {
      nleft--;
    } else if (r >= .5 & (800 - nleft) > 0) {
      nleft++;
    }
    t++;
    fprintf(graf, "%d\t %d\t %d\n", t, nleft, 800 - nleft);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x320,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmpl   $0x186a0,-0xc(%rbp)
jge    127b <main+0x12b>
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe50(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e25(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe2c(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x8(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1207 <main+0xb7>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    124d <main+0xfd>
movsd  -0x18(%rbp),%xmm0
movsd  0xdec(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    $0x320,%ecx
sub    -0x8(%rbp),%ecx
cmp    $0x0,%ecx
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1248 <main+0xf8>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124d <main+0xfd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    $0x320,%r8d
sub    -0x8(%rbp),%r8d
lea    0xdab(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119c <main+0x4c>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x320,%ebp
mov    $0x1,%ebx
mov    0x2e58(%rip),%r12
mov    $0xffffffff,%r13d
lea    0xe77(%rip),%r15
nopl   (%rax)
xor    %eax,%eax
call   1070 <rand@plt>
divsd  (%r12),%xmm0
movsd  0xe4b(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
cmp    $0x320,%ebp
setl   %cl
and    %al,%cl
ucomisd %xmm0,%xmm1
movzbl %cl,%eax
mov    %eax,%ecx
cmovae %r13d,%ecx
test   %ebp,%ebp
cmovle %eax,%ecx
add    %ecx,%ebp
mov    $0x320,%r8d
sub    %ebp,%r8d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
add    $0x1,%ebx
cmp    $0x186a1,%ebx
jne    11a0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"graf5.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [12 x i8] c"%d\09 %d\09 %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32*
store i32 0, i32* %1
store i32 800, i32* %2
store i32 0, i32* %3
store double 0.000000e+00, double* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
br label %12
12: ; preds = %45, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 100000
br i1 %14, label %15, label %54
15: ; preds = %12
%16 = call double (...) @rand()
%17 = fmul double %16, 1.000000e+00
%18 = load double, double* @RAND_MAX
%19 = fdiv double %17, %18
store double %19, double* %4
%20 = load double, double* %4
%21 = fcmp ole double %20, 5.000000e-01
%22 = zext i1 %21 to i32
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 0
%25 = zext i1 %24 to i32
%26 = and i32 %22, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
br label %45
31: ; preds = %15
%32 = load double, double* %4
%33 = fcmp oge double %32, 5.000000e-01
%34 = zext i1 %33 to i32
%35 = load i32, i32* %2
%36 = sub nsw i32 800, %35
%37 = icmp sgt i32 %36, 0
%38 = zext i1 %37 to i32
%39 = and i32 %34, %38
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %31
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %44
44: ; preds = %41, %31
br label %45
45: ; preds = %44, %28
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
%48 = load i32*, i32** %8
%49 = load i32, i32* %3
%50 = load i32, i32* %2
%51 = load i32, i32* %2
%52 = sub nsw i32 800, %51
%53 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %50, i32 %52)
br label %12
54: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"graf5.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [12 x i8] c"%d\09 %d\09 %d\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 800, %0 ], [ %18, %4 ]
%6 = phi i32 [ 0, %0 ], [ %19, %4 ]
%7 = tail call double (...) @rand()
%8 = load double, double* @RAND_MAX
%9 = fdiv double %7, %8
%10 = fcmp ole double %9, 5.000000e-01
%11 = icmp sgt i32 %5, 0
%12 = and i1 %11, %10
%13 = fcmp oge double %9, 5.000000e-01
%14 = icmp slt i32 %5, 800
%15 = and i1 %14, %13
%16 = zext i1 %15 to i32
%17 = select i1 %12, i32 -1, i32 %16
%18 = add nsw i32 %5, %17
%19 = add nuw nsw i32 %6, 1
%20 = sub nsw i32 800, %18
%21 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %18, i32 %20)
%22 = icmp eq i32 %19, 100000
br i1 %22, label %23, label %4
23: ; preds = %4
ret i32 0
}