#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 /*<<< orphan*/ printf(char *, int);
double rand();
int sqrt(double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int nleft = 7200, t = 0;
  double r, error = 0;
  FILE *graf;
  graf = fopen("graf4.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) {
      error += (nleft - 7200 / 2) * (nleft - 7200 / 2);
      fprintf(graf, "%d\t %d\n", t, nleft - 7200 / 2);
    }
  }
  printf("%f\n", sqrt(error / (85000)) / 3600);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1c20,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
cmpl   $0x186a0,-0xc(%rbp)
jge    1288 <main+0x118>
mov    $0x0,%al
call   1090 <rand@plt>
movsd  0xe38(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e05(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe12(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xdfe(%rip),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1226 <main+0xb6>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    122f <main+0xbf>
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    1283 <main+0x113>
mov    -0x8(%rbp),%eax
sub    $0xe10,%eax
mov    -0x8(%rbp),%ecx
sub    $0xe10,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
sub    $0xe10,%ecx
lea    0xda6(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11bc <main+0x4c>
movsd  -0x20(%rbp),%xmm0
movsd  0xd6b(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1080 <sqrt@plt>
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd7d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1c20,%r12d
mov    $0x1,%ebx
mov    0x2e2e(%rip),%r13
lea    0xe63(%rip),%r15
jmp    11db <main+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    $0x186a1,%ebx
je     1258 <main+0xe8>
lea    -0x1(%rbx),%ebp
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
unpcklpd %xmm1,%xmm0
movapd 0xe07(%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     11d0 <main+0x60>
lea    -0xe10(%r12),%ecx
ff
mov    %ecx,%eax
imul   %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
jmp    11d0 <main+0x60>
movsd  (%rsp),%xmm0
divsd  0xdab(%rip),%xmm0
call   1080 <sqrt@plt>
movslq %eax,%rsi
imul   $0xffffffff91a2b3c5,%rsi,%rax
shr    $0x20,%rax
add    %eax,%esi
mov    %esi,%eax
shr    $0x1f,%eax
sar    $0xb,%esi
add    %eax,%esi
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
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"graf4.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"
@.str.3 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca i32*
store i32 0, i32* %1
store i32 7200, i32* %2
store i32 0, i32* %3
store double 0.000000e+00, double* %5
%7 = 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* %7, i32** %6
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
br label %10
10: ; preds = %49, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 100000
br i1 %12, label %13, label %50
13: ; preds = %10
%14 = call double (...) @rand()
%15 = fmul double %14, 1.000000e+00
%16 = load double, double* @RAND_MAX
%17 = fdiv double %15, %16
store double %17, double* %4
%18 = load double, double* %4
%19 = load i32, i32* %2
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 1.000000e+00
%22 = fdiv double %21, 7.200000e+03
%23 = fcmp ole double %18, %22
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = load i32, i32* %2
%26 = add nsw i32 %25, -1
store i32 %26, i32* %2
br label %30
27: ; preds = %13
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = icmp sgt i32 %33, 15000
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 3600
%38 = load i32, i32* %2
%39 = sub nsw i32 %38, 3600
%40 = mul nsw i32 %37, %39
%41 = sitofp i32 %40 to double
%42 = load double, double* %5
%43 = fadd double %42, %41
store double %43, double* %5
%44 = load i32*, i32** %6
%45 = load i32, i32* %3
%46 = load i32, i32* %2
%47 = sub nsw i32 %46, 3600
%48 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %47)
br label %49
49: ; preds = %35, %30
br label %10
50: ; preds = %10
%51 = load double, double* %5
%52 = fdiv double %51, 8.500000e+04
%53 = call i32 @sqrt(double %52)
%54 = sdiv i32 %53, 3600
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %54)
ret i32 0
}

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