#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 */
int irbit1(unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i, iflg, ipts = 0, j, n;
  unsigned long iseed = 12345;
  float twoinv, delay[15 + 1];
  for (i = 1; i <= 15; i++)
    delay[i] = 0.0;
  printf("distribution of runs of n zeros\n");
  printf("%6s %22s %18s\n", "n", "probability", "expected");
  for (i = 1; i <= 10000; i++) {
    if (irbit1(&iseed) == 1) {
      ++ipts;
      iflg = 0;
      for (j = 1; j <= 15; j++) {
        if ((irbit1(&iseed) == 1) && (iflg == 0)) {
          iflg = 1;
          ++delay[j];
        }
      }
    }
  }
  twoinv = 0.5;
  for (n = 1; n <= 15; n++) {
    printf("%6d %19.4f %20.4f\n", (n - 1), delay[n] / ipts, twoinv);
    twoinv /= 2.0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x3039,-0x20(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xf,-0x8(%rbp)
jg     116a <main+0x4a>
movslq -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x70(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <main+0x25>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    0xeba(%rip),%rsi
lea    0xeb5(%rip),%rdx
lea    0xeba(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jg     1248 <main+0x128>
lea    -0x20(%rbp),%rdi
call   1040 <irbit1@plt>
cmp    $0x1,%eax
jne    1235 <main+0x115>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xf,-0x14(%rbp)
jg     1230 <main+0x110>
lea    -0x20(%rbp),%rdi
call   1040 <irbit1@plt>
cmp    $0x1,%eax
jne    121d <main+0xfd>
cmpl   $0x0,-0xc(%rbp)
jne    121d <main+0xfd>
movl   $0x1,-0xc(%rbp)
movslq -0x14(%rbp),%rax
movss  0xdf3(%rip),%xmm0
addss  -0x70(%rbp,%rax,4),%xmm0
movss  %xmm0,-0x70(%rbp,%rax,4)
jmp    1222 <main+0x102>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0xb8>
jmp    1235 <main+0x115>
jmp    123a <main+0x11a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a2 <main+0x82>
movss  0xdb0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0xf,-0x18(%rbp)
jg     12c6 <main+0x1a6>
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
movslq -0x18(%rbp),%rax
movss  -0x70(%rbp,%rax,4),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x24(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdc4(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd5d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    125c <main+0x13c>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
movq   $0x3039,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rsp)
movups %xmm0,0x34(%rsp)
movups %xmm0,0x24(%rsp)
movups %xmm0,0x14(%rsp)
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rdi
lea    0xea1(%rip),%rsi
lea    0xe9c(%rip),%rdx
lea    0xea1(%rip),%rcx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
lea    0x8(%rsp),%r12
jmp    11b1 <main+0x81>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
add    $0x1,%r15d
cmp    $0x2711,%r15d
je     1206 <main+0xd6>
mov    %r12,%rdi
call   1050 <irbit1@plt>
cmp    $0x1,%eax
jne    11a4 <main+0x74>
xor    %ebx,%ebx
mov    $0x1,%ebp
jmp    11da <main+0xaa>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x10,%rbp
je     11a0 <main+0x70>
mov    %r12,%rdi
call   1050 <irbit1@plt>
cmp    $0x1,%eax
jne    11d0 <main+0xa0>
test   %ebx,%ebx
jne    11d0 <main+0xa0>
movss  0x10(%rsp,%rbp,4),%xmm0
addss  0xe07(%rip),%xmm0
movss  %xmm0,0x10(%rsp,%rbp,4)
mov    $0x1,%ebx
jmp    11d0 <main+0xa0>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
movss  %xmm0,0x4(%rsp)
movss  0xde8(%rip),%xmm0
xor    %ebx,%ebx
lea    0xe09(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movss  %xmm0,(%rsp)
movss  0x14(%rsp,%rbx,4),%xmm0
divss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1040 <printf@plt>
movss  (%rsp),%xmm0
mulss  0xd9d(%rip),%xmm0
add    $0x1,%rbx
cmp    $0xf,%rbx
jne    1230 <main+0x100>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"distribution of runs of n zeros\0A\00"
@.str.1 = [15 x i8] c"%6s %22s %18s\0A\00"
@.str.2 = [2 x i8] c"n\00"
@.str.3 = [12 x i8] c"probability\00"
@.str.4 = [9 x i8] c"expected\00"
@.str.5 = [19 x i8] c"%6d %19.4f %20.4f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca float
%9 = alloca [16 x float]
store i32 0, i32* %1
store i32 0, i32* %4
store i64 12345, i64* %7
store i32 1, i32* %2
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 15
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [16 x float], [16 x float]* %9, i64 0, i64 %15
store float 0.000000e+00, float* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %10
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %23
23: ; preds = %53, %20
%24 = load i32, i32* %2
%25 = icmp sle i32 %24, 10000
br i1 %25, label %26, label %56
26: ; preds = %23
%27 = call i32 @irbit1(i64* %7)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %52
29: ; preds = %26
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
store i32 0, i32* %3
store i32 1, i32* %5
br label %32
32: ; preds = %48, %29
%33 = load i32, i32* %5
%34 = icmp sle i32 %33, 15
br i1 %34, label %35, label %51
35: ; preds = %32
%36 = call i32 @irbit1(i64* %7)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
store i32 1, i32* %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [16 x float], [16 x float]* %9, i64 0, i64 %43
%45 = load float, float* %44
%46 = fadd float %45, 1.000000e+00
store float %46, float* %44
br label %47
47: ; preds = %41, %38, %35
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %32
51: ; preds = %32
br label %52
52: ; preds = %51, %26
br label %53
53: ; preds = %52
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %23
56: ; preds = %23
store float 5.000000e-01, float* %8
store i32 1, i32* %6
br label %57
57: ; preds = %78, %56
%58 = load i32, i32* %6
%59 = icmp sle i32 %58, 15
br i1 %59, label %60, label %81
60: ; preds = %57
%61 = load i32, i32* %6
%62 = sub nsw i32 %61, 1
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [16 x float], [16 x float]* %9, i64 0, i64 %64
%66 = load float, float* %65
%67 = load i32, i32* %4
%68 = sitofp i32 %67 to float
%69 = fdiv float %66, %68
%70 = fpext float %69 to double
%71 = load float, float* %8
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %62, double %70, double %72)
%74 = load float, float* %8
%75 = fpext float %74 to double
%76 = fdiv double %75, 2.000000e+00
%77 = fptrunc double %76 to float
store float %77, float* %8
br label %78
78: ; preds = %60
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %57
81: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"%6s %22s %18s\0A\00"
@.str.2 = [2 x i8] c"n\00"
@.str.3 = [12 x i8] c"probability\00"
@.str.4 = [9 x i8] c"expected\00"
@.str.5 = [19 x i8] c"%6d %19.4f %20.4f\0A\00"
@str = [32 x i8] c"distribution of runs of n zeros\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [16 x float]
%3 = bitcast i64* %1 to i8*
store i64 12345, i64* %1
%4 = bitcast [16 x float]* %2 to i8*
%5 = getelementptr inbounds [16 x float], [16 x float]* %2, i64 0, i64 1
%6 = bitcast float* %5 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %11
9: ; preds = %33
%10 = sitofp i32 %34 to float
br label %37
11: ; preds = %0, %33
%12 = phi i32 [ 0, %0 ], [ %34, %33 ]
%13 = phi i32 [ 1, %0 ], [ %35, %33 ]
%14 = call i32 @irbit1(i64* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %33
16: ; preds = %11, %27
%17 = phi i64 [ %29, %27 ], [ 1, %11 ]
%18 = phi i32 [ %28, %27 ], [ 0, %11 ]
%19 = call i32 @irbit1(i64* %1)
%20 = icmp eq i32 %19, 1
%21 = icmp eq i32 %18, 0
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = getelementptr inbounds [16 x float], [16 x float]* %2, i64 0, i64 %17
%25 = load float, float* %24
%26 = fadd float %25, 1.000000e+00
store float %26, float* %24
br label %27
27: ; preds = %16, %23
%28 = phi i32 [ 1, %23 ], [ %18, %16 ]
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, 16
br i1 %30, label %31, label %16
31: ; preds = %27
%32 = add nsw i32 %12, 1
br label %33
33: ; preds = %31, %11
%34 = phi i32 [ %12, %11 ], [ %32, %31 ]
%35 = add nuw nsw i32 %13, 1
%36 = icmp eq i32 %35, 10001
br i1 %36, label %9, label %11
37: ; preds = %9, %37
%38 = phi i64 [ 1, %9 ], [ %49, %37 ]
%39 = phi float [ 5.000000e-01, %9 ], [ %48, %37 ]
%40 = getelementptr inbounds [16 x float], [16 x float]* %2, i64 0, i64 %38
%41 = load float, float* %40
%42 = fdiv float %41, %10
%43 = fpext float %42 to double
%44 = fpext float %39 to double
%45 = trunc i64 %38 to i32
%46 = add i32 %45, -1
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %46, double %43, double %44)
%48 = fmul float %39, 5.000000e-01
%49 = add nuw nsw i64 %38, 1
%50 = icmp eq i64 %49, 16
br i1 %50, label %51, label %37
51: ; preds = %37
ret i32 0
}