#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 bnldev(float, int, long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main(void) {
  char txt[50 + 1];
  int i, j, k, klim, dist[20 + 1];
  long idum = (-133);
  float pp, xm, dd;
  for (;;) {
    for (j = 0; j <= 20; j++)
      dist[j] = 0;
    do {
      printf("Mean of binomial distribution (0.0 to %d.0)", 20);
      printf(" - Negative to end:\n");
      scanf("%f", &xm);
    } while (xm > 20);
    if (xm < 0.0)
      break;
    pp = xm / 100;
    for (i = 1; i <= 1000; i++) {
      j = bnldev(pp, 100, &idum);
      if (j >= 0 && j <= 20)
        ++dist[j];
    }
    printf("Binomial-distributed deviate, mean %5.2f of %6d points\n", xm,
           1000);
    printf("%4s %8s %10s\n", "x", "p(x)", "graph:");
    for (j = 0; j < 20; j++) {
      for (k = 0; k <= 50; k++)
        txt[k] = ' ';
      dd = (float)dist[j] / 1000;
      klim = (int)(200 * dd + 1);
      if (klim > 50)
        klim = 50;
      for (k = 1; k <= klim; k++)
        txt[k] = '*';
      txt[50] = '\0';
      printf("%4d %9.4f   %s\n", j, dd, txt);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffffffff7b,-0xb8(%rbp)
7b ff ff ff
movl   $0x0,-0x48(%rbp)
cmpl   $0x14,-0x48(%rbp)
jg     117b <main+0x4b>
movslq -0x48(%rbp),%rax
movl   $0x0,-0xb0(%rbp,%rax,4)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1154 <main+0x24>
jmp    1180 <main+0x50>
lea    0xe8d(%rip),%rdi
mov    $0x14,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0xc0(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0xc0(%rbp),%xmm0
ff
movss  0xe3c(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     1180 <main+0x50>
movss  -0xc0(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11eb <main+0xbb>
jmp    13a9 <main+0x279>
movss  -0xc0(%rbp),%xmm0
ff
movss  0xe09(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xbc(%rbp)
ff
movl   $0x1,-0x44(%rbp)
cmpl   $0x3e8,-0x44(%rbp)
jg     1273 <main+0x143>
movss  -0xbc(%rbp),%xmm0
ff
mov    $0x64,%edi
lea    -0xb8(%rbp),%rsi
call   1050 <bnldev@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     1260 <main+0x130>
cmpl   $0x14,-0x48(%rbp)
jg     1260 <main+0x130>
movslq -0x48(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xb0(%rbp,%rax,4)
jmp    1265 <main+0x135>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    120e <main+0xde>
movss  -0xc0(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xdd2(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xdf7(%rip),%rdi
lea    0xdfe(%rip),%rsi
lea    0xdf9(%rip),%rdx
lea    0xdf7(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x14,-0x48(%rbp)
jge    13a4 <main+0x274>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x32,-0x4c(%rbp)
jg     12ee <main+0x1be>
movslq -0x4c(%rbp),%rax
movb   $0x20,-0x40(%rbp,%rax,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    12cd <main+0x19d>
movslq -0x48(%rbp),%rax
cvtsi2ssl -0xb0(%rbp,%rax,4),%xmm0
ff ff
movss  0xd0d(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc4(%rbp)
ff
movss  -0xc4(%rbp),%xmm0
ff
movss  0xce9(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xce1(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x32,-0x50(%rbp)
jle    1347 <main+0x217>
movl   $0x32,-0x50(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jg     1371 <main+0x241>
movslq -0x4c(%rbp),%rax
movb   $0x2a,-0x40(%rbp,%rax,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    134e <main+0x21e>
movb   $0x0,-0xe(%rbp)
mov    -0x48(%rbp),%esi
movss  -0xc4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    -0x40(%rbp),%rdx
lea    0xd1d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12bc <main+0x18c>
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movq   $0xffffffffffffff7b,0x8(%rsp)
ff ff
lea    0x4(%rsp),%r13
lea    0xf3d(%rip),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movl   $0x0,0xa0(%rsp)
lea    0xe7c(%rip),%r12
lea    0xf08(%rip),%rbx
lea    0xe9a(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
movss  0xe06(%rip),%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
ja     11d0 <main+0x80>
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
ja     134d <main+0x1fd>
divss  0xdeb(%rip),%xmm1
mov    $0x3e8,%ebp
lea    0x8(%rsp),%rbx
movss  %xmm1,(%rsp)
jmp    123a <main+0xea>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
movss  (%rsp),%xmm1
je     1260 <main+0x110>
movaps %xmm1,%xmm0
mov    $0x64,%edi
mov    %rbx,%rsi
call   1070 <bnldev@plt>
cmp    $0x14,%eax
ja     1230 <main+0xe0>
mov    %eax,%eax
addl   $0x1,0x50(%rsp,%rax,4)
jmp    1230 <main+0xe0>
nopl   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdee(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
lea    0xe1a(%rip),%rsi
lea    0xe15(%rip),%rdx
lea    0xe13(%rip),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r12d,%r12d
lea    0x11(%rsp),%rbp
jmp    12da <main+0x18a>
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x42(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%r12
cmp    $0x14,%r12
je     1180 <main+0x30>
movaps 0xd3f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ssl 0x50(%rsp,%r12,4),%xmm1
movaps %xmm0,0x10(%rsp)
movl   $0x20202020,0x3f(%rsp)
20
divss  0xcfe(%rip),%xmm1
movaps %xmm1,%xmm0
mulss  0xcf7(%rip),%xmm0
addss  0xcf3(%rip),%xmm0
cvttss2si %xmm0,%eax
cmp    $0x32,%eax
jl     132b <main+0x1db>
mov    $0x32,%eax
test   %eax,%eax
jle    12b0 <main+0x160>
mov    %eax,%edx
mov    %rbp,%rdi
mov    $0x2a,%esi
movss  %xmm1,(%rsp)
call   1050 <memset@plt>
movss  (%rsp),%xmm1
jmp    12b0 <main+0x160>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Mean of binomial distribution (0.0 to %d.0)\00"
@.str.1 = [21 x i8] c" - Negative to end:\0A\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [56 x i8] c"Binomial-distributed deviate, mean %5.2f of %6d points\0A\00"
@.str.4 = [14 x i8] c"%4s %8s %10s\0A\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [5 x i8] c"p(x)\00"
@.str.7 = [7 x i8] c"graph:\00"
@.str.8 = [16 x i8] c"%4d %9.4f %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [51 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [21 x i32]
%8 = alloca i64
%9 = alloca float
%10 = alloca float
%11 = alloca float
store i32 0, i32* %1
store i64 -133, i64* %8
br label %12
12: ; preds = %114, %0
store i32 0, i32* %4
br label %13
13: ; preds = %20, %12
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 20
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %18
store i32 0, i32* %19
br label %20
20: ; preds = %16
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %13
23: ; preds = %13
br label %24
24: ; preds = %28, %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 20)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %10)
br label %28
28: ; preds = %24
%29 = load float, float* %10
%30 = fcmp ogt float %29, 2.000000e+01
br i1 %30, label %24, label %31
31: ; preds = %28
%32 = load float, float* %10
%33 = fpext float %32 to double
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %36
35: ; preds = %31
br label %115
36: ; preds = %31
%37 = load float, float* %10
%38 = fdiv float %37, 1.000000e+02
store float %38, float* %9
store i32 1, i32* %3
br label %39
39: ; preds = %57, %36
%40 = load i32, i32* %3
%41 = icmp sle i32 %40, 1000
br i1 %41, label %42, label %60
42: ; preds = %39
%43 = load float, float* %9
%44 = call i32 @bnldev(float %43, i32 100, i64* %8)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = icmp sge i32 %45, 0
br i1 %46, label %47, label %56
47: ; preds = %42
%48 = load i32, i32* %4
%49 = icmp sle i32 %48, 20
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
store i32 %55, i32* %53
br label %56
56: ; preds = %50, %47, %42
br label %57
57: ; preds = %56
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
br label %39
60: ; preds = %39
%61 = load float, float* %10
%62 = fpext float %61 to double
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), double %62, i32 1000)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %65
65: ; preds = %111, %60
%66 = load i32, i32* %4
%67 = icmp slt i32 %66, 20
br i1 %67, label %68, label %114
68: ; preds = %65
store i32 0, i32* %5
br label %69
69: ; preds = %76, %68
%70 = load i32, i32* %5
%71 = icmp sle i32 %70, 50
br i1 %71, label %72, label %79
72: ; preds = %69
%73 = load i32, i32* %5
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 %74
store i8 32, i8* %75
br label %76
76: ; preds = %72
%77 = load i32, i32* %5
%78 = add nsw i32 %77, 1
store i32 %78, i32* %5
br label %69
79: ; preds = %69
%80 = load i32, i32* %4
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [21 x i32], [21 x i32]* %7, i64 0, i64 %81
%83 = load i32, i32* %82
%84 = sitofp i32 %83 to float
%85 = fdiv float %84, 1.000000e+03
store float %85, float* %11
%86 = load float, float* %11
%87 = call float @llvm.fmuladd.f32(float 2.000000e+02, float %86, float 1.000000e+00)
%88 = fptosi float %87 to i32
store i32 %88, i32* %6
%89 = load i32, i32* %6
%90 = icmp sgt i32 %89, 50
br i1 %90, label %91, label %92
91: ; preds = %79
store i32 50, i32* %6
br label %92
92: ; preds = %91, %79
store i32 1, i32* %5
br label %93
93: ; preds = %101, %92
%94 = load i32, i32* %5
%95 = load i32, i32* %6
%96 = icmp sle i32 %94, %95
br i1 %96, label %97, label %104
97: ; preds = %93
%98 = load i32, i32* %5
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 %99
store i8 42, i8* %100
br label %101
101: ; preds = %97
%102 = load i32, i32* %5
%103 = add nsw i32 %102, 1
store i32 %103, i32* %5
br label %93
104: ; preds = %93
%105 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 50
store i8 0, i8* %105
%106 = load i32, i32* %4
%107 = load float, float* %11
%108 = fpext float %107 to double
%109 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 0
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %106, double %108, i8* %109)
br label %111
111: ; preds = %104
%112 = load i32, i32* %4
%113 = add nsw i32 %112, 1
store i32 %113, i32* %4
br label %65
114: ; preds = %65
br label %12
115: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"Mean of binomial distribution (0.0 to %d.0)\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [56 x i8] c"Binomial-distributed deviate, mean %5.2f of %6d points\0A\00"
@.str.4 = [14 x i8] c"%4s %8s %10s\0A\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [5 x i8] c"p(x)\00"
@.str.7 = [7 x i8] c"graph:\00"
@.str.8 = [16 x i8] c"%4d %9.4f %s\0A\00"
@str = [20 x i8] c" - Negative to end:\00"
define i32 @main() {
%1 = alloca [51 x i8]
%2 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 0
%3 = alloca [21 x i32]
%4 = bitcast [21 x i32]* %3 to i8*
%5 = alloca i64
%6 = alloca float
%7 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
store i64 -133, i64* %5
%9 = bitcast float* %6 to i8*
%10 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 50
%11 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 1
br label %12
12: ; preds = %53, %0
br label %13
13: ; preds = %12, %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 20)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %6)
%17 = load float, float* %6
%18 = fcmp ogt float %17, 2.000000e+01
br i1 %18, label %13, label %19
19: ; preds = %13
%20 = fcmp olt float %17, 0.000000e+00
br i1 %20, label %59, label %21
21: ; preds = %19
%22 = fdiv float %17, 1.000000e+02
br label %23
23: ; preds = %21, %32
%24 = phi i32 [ 1, %21 ], [ %33, %32 ]
%25 = call i32 @bnldev(float %22, i32 100, i64* %5)
%26 = icmp ult i32 %25, 21
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = zext i32 %25 to i64
%29 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %23, %27
%33 = add nuw nsw i32 %24, 1
%34 = icmp eq i32 %33, 1001
br i1 %34, label %35, label %23
35: ; preds = %32
%36 = load float, float* %6
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), double %37, i32 1000)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %35, %53
%41 = phi i64 [ 0, %35 ], [ %57, %53 ]
%42 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = sitofp i32 %43 to float
%45 = fdiv float %44, 1.000000e+03
%46 = call float @llvm.fmuladd.f32(float %45, float 2.000000e+02, float 1.000000e+00)
%47 = fptosi float %46 to i32
%48 = icmp slt i32 %47, 50
%49 = select i1 %48, i32 %47, i32 50
%50 = icmp slt i32 %49, 1
br i1 %50, label %53, label %51
51: ; preds = %40
%52 = zext i32 %49 to i64
br label %53
53: ; preds = %51, %40
store i8 0, i8* %10
%54 = fpext float %45 to double
%55 = trunc i64 %41 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %55, double %54, i8* %7)
%57 = add nuw nsw i64 %41, 1
%58 = icmp eq i64 %57, 20
br i1 %58, label %12, label %40
59: ; preds = %19
ret i32 0
}