#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 */
scalar_t__ gamdev(int, long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  char words[50 + 1];
  long idum = (-13);
  int i, ia, j, k, klim, dist[20 + 1];
  float dd;
  for (;;) {
    for (j = 0; j <= 20; j++)
      dist[j] = 0;
    do {
      printf("Select order of Gamma distribution (n=1..%d), -1 to end\n", 20);
      scanf("%d", &ia);
    } while (ia > 20);
    if (ia < 0)
      break;
    for (i = 1; i <= 10000; i++) {
      j = (int)gamdev(ia, &idum);
      if ((j >= 0) && (j <= 20))
        ++dist[j];
    }
    printf("\ngamma-distribution deviate, order %2d of %6d points\n", ia,
           10000);
    printf("%6s %7s %9s \n", "x", "p(x)", "graph:");
    for (j = 0; j < 20; j++) {
      dd = (float)dist[j] / 10000;
      for (k = 1; k <= 50; k++)
        words[k] = ' ';
      klim = (int)(200 * dd);
      if (klim > 50)
        klim = 50;
      for (k = 1; k <= klim; k++)
        words[k] = '*';
      printf("%6d %8.4f  ", j, dd);
      for (k = 1; k <= klim; k++)
        printf("%c", words[k]);
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xfffffffffffffff3,-0x48(%rbp)
ff
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jg     1178 <main+0x48>
movslq -0x54(%rbp),%rax
movl   $0x0,-0xb0(%rbp,%rax,4)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1151 <main+0x21>
jmp    117d <main+0x4d>
lea    0xe84(%rip),%rdi
mov    $0x14,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x14,-0x50(%rbp)
jg     117d <main+0x4d>
cmpl   $0x0,-0x50(%rbp)
jge    11b9 <main+0x89>
jmp    1373 <main+0x243>
movl   $0x1,-0x4c(%rbp)
cmpl   $0x2710,-0x4c(%rbp)
jg     1218 <main+0xe8>
mov    -0x50(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1040 <gamdev@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jl     1205 <main+0xd5>
cmpl   $0x14,-0x54(%rbp)
jg     1205 <main+0xd5>
movslq -0x54(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xb0(%rbp,%rax,4)
jmp    120a <main+0xda>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11c0 <main+0x90>
mov    -0x50(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x2710,%edx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe45(%rip),%rdi
lea    0xe4c(%rip),%rsi
lea    0xe47(%rip),%rdx
lea    0xe45(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jge    136e <main+0x23e>
movslq -0x54(%rbp),%rax
cvtsi2ssl -0xb0(%rbp,%rax,4),%xmm0
ff ff
movss  0xd89(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xb4(%rbp)
ff
movl   $0x1,-0x58(%rbp)
cmpl   $0x32,-0x58(%rbp)
jg     12ab <main+0x17b>
movslq -0x58(%rbp),%rax
movb   $0x20,-0x40(%rbp,%rax,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    128a <main+0x15a>
movss  0xd51(%rip),%xmm0
mulss  -0xb4(%rbp),%xmm0
ff
cvttss2si %xmm0,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x32,-0x5c(%rbp)
jle    12d3 <main+0x1a3>
movl   $0x32,-0x5c(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     12fd <main+0x1cd>
movslq -0x58(%rbp),%rax
movb   $0x2a,-0x40(%rbp,%rax,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12da <main+0x1aa>
mov    -0x54(%rbp),%esi
movss  -0xb4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd83(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     1352 <main+0x222>
movslq -0x58(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1321 <main+0x1f1>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1258 <main+0x128>
jmp    114a <main+0x1a>
xor    %eax,%eax
add    $0xc0,%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   $0xfffffffffffffff3,0x8(%rsp)
ff ff
lea    0x71(%rsp),%r14
lea    0x8(%rsp),%rbx
lea    0xf2b(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r13
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe6a(%rip),%r15
lea    0xe9c(%rip),%rbx
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%esi
cmp    $0x14,%esi
jg     11c0 <main+0x70>
test   %esi,%esi
js     1338 <main+0x1e8>
mov    $0x2710,%ebp
mov    %r13,%rbx
jmp    1208 <main+0xb8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%esi
add    $0xffffffff,%ebp
je     1220 <main+0xd0>
mov    %esi,%edi
mov    %rbx,%rsi
call   1060 <gamdev@plt>
cmp    $0x14,%eax
ja     1200 <main+0xb0>
cltq
addl   $0x1,0x10(%rsp,%rax,4)
jmp    1200 <main+0xb0>
lea    0xe2d(%rip),%rdi
mov    $0x2710,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xe57(%rip),%rsi
lea    0xe52(%rip),%rdx
lea    0xe50(%rip),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r13d,%r13d
jmp    128c <main+0x13c>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mov    %r12,%rdi
mov    %r13d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
cmp    $0x14,%r13
je     1180 <main+0x30>
xorps  %xmm1,%xmm1
cvtsi2ssl 0x10(%rsp,%r13,4),%xmm1
movaps 0xd63(%rip),%xmm0
movups %xmm0,0x20(%r14)
movups %xmm0,0x10(%r14)
movups %xmm0,(%r14)
movw   $0x2020,0x30(%r14)
divss  0xd56(%rip),%xmm1
movaps %xmm1,%xmm0
mulss  0xd4f(%rip),%xmm0
cvttss2si %xmm0,%r15d
cmp    $0x32,%r15d
mov    $0x32,%eax
cmovge %eax,%r15d
test   %r15d,%r15d
jle    1260 <main+0x110>
mov    %r15d,%edx
mov    %r14,%rdi
mov    $0x2a,%esi
movss  %xmm1,0x4(%rsp)
call   1050 <memset@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r12,%rdi
mov    %r13d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x70(%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1320 <main+0x1d0>
jmp    1274 <main+0x124>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [57 x i8] c"Select order of Gamma distribution (n=1..%d), -1 to end\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"\0Agamma-distribution deviate, order %2d of %6d points\0A\00"
@.str.3 = [14 x i8] c"%6s %7s %9s \0A\00"
@.str.4 = [2 x i8] c"x\00"
@.str.5 = [5 x i8] c"p(x)\00"
@.str.6 = [7 x i8] c"graph:\00"
@.str.7 = [12 x i8] c"%6d %8.4f \00"
define i32 @main() {
%1 = alloca [51 x i8]
%2 = alloca i64
%3 = alloca i32
%4 = alloca [21 x i32]
%5 = bitcast [21 x i32]* %4 to i8*
%6 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 0
%7 = bitcast i64* %2 to i8*
store i64 -13, i64* %2
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 1
br label %10
10: ; preds = %67, %0
br label %11
11: ; preds = %10, %11
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 20)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 20
br i1 %15, label %11, label %16
16: ; preds = %11
%17 = icmp slt i32 %14, 0
br i1 %17, label %71, label %18
18: ; preds = %16, %30
%19 = phi i32 [ %33, %30 ], [ %14, %16 ]
%20 = phi i32 [ %31, %30 ], [ 1, %16 ]
%21 = call i64 @gamdev(i32 %19, i64* %2)
%22 = trunc i64 %21 to i32
%23 = icmp ult i32 %22, 21
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = shl i64 %21, 32
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds [21 x i32], [21 x i32]* %4, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %27
br label %30
30: ; preds = %18, %24
%31 = add nuw nsw i32 %20, 1
%32 = icmp eq i32 %31, 10001
%33 = load i32, i32* %3
br i1 %32, label %34, label %18
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 10000)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %37
37: ; preds = %34, %67
%38 = phi i64 [ 0, %34 ], [ %69, %67 ]
%39 = getelementptr inbounds [21 x i32], [21 x i32]* %4, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = sitofp i32 %40 to float
%42 = fdiv float %41, 1.000000e+04
%43 = fmul float %42, 2.000000e+02
%44 = fptosi float %43 to i32
%45 = icmp slt i32 %44, 50
%46 = select i1 %45, i32 %44, i32 50
%47 = icmp slt i32 %46, 1
br i1 %47, label %48, label %52
48: ; preds = %37
%49 = fpext float %42 to double
%50 = trunc i64 %38 to i32
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %50, double %49)
br label %67
52: ; preds = %37
%53 = zext i32 %46 to i64
%54 = fpext float %42 to double
%55 = trunc i64 %38 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %55, double %54)
%57 = add nuw nsw i32 %46, 1
%58 = zext i32 %57 to i64
br label %59
59: ; preds = %52, %59
%60 = phi i64 [ 1, %52 ], [ %65, %59 ]
%61 = getelementptr inbounds [51 x i8], [51 x i8]* %1, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = call i32 @putchar(i32 %63)
%65 = add nuw nsw i64 %60, 1
%66 = icmp eq i64 %65, %58
br i1 %66, label %67, label %59
67: ; preds = %59, %48
%68 = call i32 @putchar(i32 10)
%69 = add nuw nsw i64 %38, 1
%70 = icmp eq i64 %69, 20
br i1 %70, label %10, label %37
71: ; preds = %16
ret i32 0
}