#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 */
double M_PI;
double RAND_MAX;
int /*<<< orphan*/ printf(char *, double, double, size_t);
scalar_t__ rand();
double sin(double);
int main(int argc, const char **argv) {
  size_t n_max = 100000;
  size_t n_min = 0;
  size_t n_steps = 10000;
  size_t i;
  size_t seed = 1;
  size_t n = 50000;
  double sum = 0;
  for (i = 0; i < n_steps; i++) {
    double r = 0.5 + 0.1 * 0.5 * sin(2.0 * M_PI * i / (double)n_steps);
    double x = (double)rand() / RAND_MAX;
    if (x < r) {
      if (n < n_max - 1) {
        n++;
      }
    } else {
      if (n > n_min) {
        n--;
      }
    }
    printf("%f %f %d\n", x, r, n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x186a0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x2710,-0x28(%rbp)
movq   $0x1,-0x38(%rbp)
movq   $0xc350,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12a4 <main+0x174>
mov    0x2e55(%rip),%rax
movsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
movq   -0x30(%rbp),%xmm1
movaps 0xe69(%rip),%xmm3
punpckldq %xmm3,%xmm1
movapd 0xe6d(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm4
unpckhpd %xmm1,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm0
movq   -0x28(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  0xe11(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dc9(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    125a <main+0x12a>
mov    -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1255 <main+0x125>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1279 <main+0x149>
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1274 <main+0x144>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
jmp    1279 <main+0x149>
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x40(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    117e <main+0x4e>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xc350,%r13d
mov    0x2e9e(%rip),%r15
mov    0x2e8f(%rip),%r12
lea    0xee0(%rip),%r14
xor    %ebx,%ebx
jmp    1189 <main+0x59>
nopl   0x0(%rax)
sub    $0x1,%r13
mov    $0x0,%eax
cmovb  %rax,%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
je     120f <main+0xdf>
movsd  (%r15),%xmm1
addsd  %xmm1,%xmm1
movq   %rbx,%xmm2
punpckldq 0xe61(%rip),%xmm2
subpd  0xe69(%rip),%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe61(%rip),%xmm0
call   1040 <sin@plt>
mulsd  0xe5c(%rip),%xmm0
addsd  0xe5c(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
ucomisd %xmm0,%xmm1
jbe    1160 <main+0x30>
cmp    $0x1869f,%r13
adc    $0x0,%r13
jmp    116d <main+0x3d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
@.str = [10 x i8] c"%f %f %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 100000, i64* %6
store i64 0, i64* %7
store i64 10000, i64* %8
store i64 1, i64* %10
store i64 50000, i64* %11
store double 0.000000e+00, double* %12
store i64 0, i64* %9
br label %15
15: ; preds = %59, %2
%16 = load i64, i64* %9
%17 = load i64, i64* %8
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %62
19: ; preds = %15
%20 = load double, double* @M_PI
%21 = fmul double 2.000000e+00, %20
%22 = load i64, i64* %9
%23 = uitofp i64 %22 to double
%24 = fmul double %21, %23
%25 = load i64, i64* %8
%26 = uitofp i64 %25 to double
%27 = fdiv double %24, %26
%28 = call double @sin(double %27)
%29 = call double @llvm.fmuladd.f64(double 5.000000e-02, double %28, double 5.000000e-01)
store double %29, double* %13
%30 = call i64 (...) @rand()
%31 = sitofp i64 %30 to double
%32 = load double, double* @RAND_MAX
%33 = fdiv double %31, %32
store double %33, double* %14
%34 = load double, double* %14
%35 = load double, double* %13
%36 = fcmp olt double %34, %35
br i1 %36, label %37, label %46
37: ; preds = %19
%38 = load i64, i64* %11
%39 = load i64, i64* %6
%40 = sub i64 %39, 1
%41 = icmp ult i64 %38, %40
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i64, i64* %11
%44 = add i64 %43, 1
store i64 %44, i64* %11
br label %45
45: ; preds = %42, %37
br label %54
46: ; preds = %19
%47 = load i64, i64* %11
%48 = load i64, i64* %7
%49 = icmp ugt i64 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i64, i64* %11
%52 = add i64 %51, -1
store i64 %52, i64* %11
br label %53
53: ; preds = %50, %46
br label %54
54: ; preds = %53, %45
%55 = load double, double* %14
%56 = load double, double* %13
%57 = load i64, i64* %11
%58 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %55, double %56, i64 %57)
br label %59
59: ; preds = %54
%60 = load i64, i64* %9
%61 = add i64 %60, 1
store i64 %61, i64* %9
br label %15
62: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@RAND_MAX = global double 0.000000e+00
@.str = [10 x i8] c"%f %f %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %26
%4 = phi i64 [ 0, %2 ], [ %29, %26 ]
%5 = phi i64 [ 50000, %2 ], [ %27, %26 ]
%6 = load double, double* @M_PI
%7 = fmul double %6, 2.000000e+00
%8 = uitofp i64 %4 to double
%9 = fmul double %7, %8
%10 = fdiv double %9, 1.000000e+04
%11 = tail call double @sin(double %10)
%12 = tail call double @llvm.fmuladd.f64(double %11, double 5.000000e-02, double 5.000000e-01)
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = fcmp olt double %16, %12
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = icmp ult i64 %5, 99999
%20 = zext i1 %19 to i64
%21 = add i64 %5, %20
br label %26
22: ; preds = %3
%23 = icmp eq i64 %5, 0
%24 = add i64 %5, -1
%25 = select i1 %23, i64 0, i64 %24
br label %26
26: ; preds = %22, %18
%27 = phi i64 [ %21, %18 ], [ %25, %22 ]
%28 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %16, double %12, i64 %27)
%29 = add nuw nsw i64 %4, 1
%30 = icmp eq i64 %29, 10000
br i1 %30, label %31, label %3
31: ; preds = %26
ret i32 0
}