#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);
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int nleft = 7200, t = 0;
  double r;
  FILE *graf;
  graf = fopen("graf3.dat", "w");
  srand(time(NULL));
  while (t < 100000) {
    r = rand() * 1.0 / RAND_MAX;
    if (r <= nleft * 1.0 / 7200) {
      nleft--;
    } else {
      nleft++;
    }
    t++;
    if (t > 15000) {
      fprintf(graf, "%d\t %d\n", t, nleft - 7200 / 2);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1c20,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmpl   $0x186a0,-0xc(%rbp)
jge    123e <main+0xee>
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe58(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e2d(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe32(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xe1e(%rip),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     11fe <main+0xae>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1207 <main+0xb7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3a98,-0xc(%rbp)
jle    1239 <main+0xe9>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
sub    $0xe10,%ecx
lea    0xde8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1194 <main+0x44>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x1c20,%r12d
mov    $0x1,%ebx
mov    0x2e57(%rip),%r13
lea    0xe84(%rip),%r15
jmp    11ab <main+0x5b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0x186a1,%ebx
je     120b <main+0xbb>
lea    -0x1(%rbx),%ebp
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
unpcklpd %xmm1,%xmm0
movapd 0xe37(%rip),%xmm1
movlpd 0x0(%r13),%xmm1
divpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
setb   %al
lea    (%r12,%rax,2),%r12d
add    $0xffffffff,%r12d
cmp    $0x3a98,%ebp
jb     11a0 <main+0x50>
lea    -0xe10(%r12),%ecx
ff
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
jmp    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"graf3.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [8 x i8] c"%d\09 %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32*
store i32 0, i32* %1
store i32 7200, i32* %2
store i32 0, i32* %3
%6 = 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* %6, i32** %5
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
br label %9
9: ; preds = %40, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 100000
br i1 %11, label %12, label %41
12: ; preds = %9
%13 = call double (...) @rand()
%14 = fmul double %13, 1.000000e+00
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
store double %16, double* %4
%17 = load double, double* %4
%18 = load i32, i32* %2
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 1.000000e+00
%21 = fdiv double %20, 7.200000e+03
%22 = fcmp ole double %17, %21
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
store i32 %25, i32* %2
br label %29
26: ; preds = %12
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 15000
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i32*, i32** %5
%36 = load i32, i32* %3
%37 = load i32, i32* %2
%38 = sub nsw i32 %37, 3600
%39 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %38)
br label %40
40: ; preds = %34, %29
br label %9
41: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"graf3.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [8 x i8] c"%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, %24
%5 = phi i32 [ 7200, %0 ], [ %18, %24 ]
%6 = phi i32 [ 0, %0 ], [ %19, %24 ]
%7 = tail call double (...) @rand()
%8 = load double, double* @RAND_MAX
%9 = sitofp i32 %5 to double
%10 = insertelement <2 x double> poison, double %7, i64 0
%11 = insertelement <2 x double> %10, double %9, i64 1
%12 = insertelement <2 x double> <double poison, double 7.200000e+03>, double %8, i64 0
%13 = fdiv <2 x double> %11, %12
%14 = extractelement <2 x double> %13, i64 0
%15 = extractelement <2 x double> %13, i64 1
%16 = fcmp ugt double %14, %15
%17 = select i1 %16, i32 1, i32 -1
%18 = add nsw i32 %17, %5
%19 = add nuw nsw i32 %6, 1
%20 = icmp ugt i32 %6, 14999
br i1 %20, label %21, label %24
21: ; preds = %4
%22 = add nsw i32 %18, -3600
%23 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %22)
br label %24
24: ; preds = %21, %4
%25 = icmp eq i32 %19, 100000
br i1 %25, label %26, label %4
26: ; preds = %24
ret i32 0
}