#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 = 7200, t = 0;
  double r;
  FILE *graf;
  graf = fopen("graf.dat", "w");
  srand(time(NULL));
  while (nleft != 7200 / 2) {
    r = rand() * 1.0 / RAND_MAX;
    if (r <= nleft * 1.0 / 7200) {
      nleft--;
    } else {
      nleft++;
    }
    t++;
    fprintf(graf, "%d\t %d\t %d\n", t, nleft, 7200 - nleft);
  }
  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    0xe9e(%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   $0xe10,-0x8(%rbp)
je     1235 <main+0xe5>
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)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    $0x1c20,%r8d
sub    -0x8(%rbp),%r8d
lea    0xdf0(%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   %r12
push   %rbx
lea    0xeb1(%rip),%rdi
lea    0xeb3(%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,%ebx
mov    $0x1,%ebp
mov    0x2e5b(%rip),%r12
lea    0xe87(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
unpcklpd %xmm1,%xmm0
movapd 0xe46(%rip),%xmm1
movlpd (%r12),%xmm1
divpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
setb   %al
lea    (%rbx,%rax,2),%ecx
mov    $0x1c21,%r8d
sub    %ecx,%r8d
lea    (%rbx,%rax,2),%ebx
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1040 <fprintf@plt>
add    $0x1,%ebp
cmp    $0xe10,%ebx
jne    11a0 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"graf.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 i32*
store i32 0, i32* %1
store i32 7200, i32* %2
store i32 0, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 = %29, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 3600
br i1 %11, label %12, label %38
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** %5
%33 = load i32, i32* %3
%34 = load i32, i32* %2
%35 = load i32, i32* %2
%36 = sub nsw i32 7200, %35
%37 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34, i32 %36)
br label %9
38: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"graf.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 ([9 x i8], [9 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 [ 7200, %0 ], [ %18, %4 ]
%6 = phi i32 [ 0, %0 ], [ %19, %4 ]
%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 = sub nsw i32 7200, %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 %18, 3600
br i1 %22, label %23, label %4
23: ; preds = %4
ret i32 0
}