#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 */
int /*<<< orphan*/ arraystats(double *, int, double *, double *, double *);
int /*<<< orphan*/ cumulativedist(int *, int, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ interpolatetable(short *, int);
short *inverttable(int *, int, int, int);
int *makedist(double *, int, double, double);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printtable(short *, int);
double *readdoubles(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char **argv) {
  FILE *fp;
  double *x;
  double mu, sigma, rho;
  int limit;
  int *table;
  short *inverse;
  int total;
  if (argc > 1) {
    if (!(fp = fopen(argv[1], "r"))) {
      perror(argv[1]);
      exit(1);
    }
  } else {
    fp = stdin;
  }
  x = readdoubles(fp, &limit);
  if (limit <= 0) {
    fprintf(stderr, "Nothing much read!\n");
    exit(2);
  }
  arraystats(x, limit, &mu, &sigma, &rho);
  table = makedist(x, limit, mu, sigma);
  free((void *)x);
  cumulativedist(table, (((32767 / 8192) + 1) * 50000 * 2), &total);
  inverse =
      inverttable(table, 16384 / 4, (((32767 / 8192) + 1) * 50000 * 2), total);
  interpolatetable(inverse, 16384 / 4);
  printtable(inverse, 16384 / 4);
  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)
cmpl   $0x1,-0x8(%rbp)
jle    121e <main+0x5e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe11(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1219 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    122c <main+0x6c>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   10a0 <readdoubles@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     1266 <main+0xa6>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1070 <arraystats@plt>
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1060 <makedist@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
mov    $0x61a80,%esi
lea    -0x54(%rbp),%rdx
call   10b0 <cumulativedist@plt>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    $0x1000,%esi
mov    $0x61a80,%edx
call   1050 <inverttable@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <interpolatetable@plt>
mov    -0x50(%rbp),%rdi
mov    $0x1000,%esi
call   1090 <printtable@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     11fa <main+0x3a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe26(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rdi
test   %rax,%rax
jne    1204 <main+0x44>
mov    0x8(%rbx),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <readdoubles@plt>
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    12a6 <main+0xe6>
mov    %rax,%r14
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x20(%rsp),%r8
mov    %rax,%rdi
call   1070 <arraystats@plt>
mov    0x8(%rsp),%esi
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %r14,%rdi
call   1060 <makedist@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x61a80,%esi
call   10b0 <cumulativedist@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    $0x61a80,%edx
call   1050 <inverttable@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1000,%esi
call   1040 <interpolatetable@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1090 <printtable@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.1 = [20 x i8] c"Nothing much read!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i16*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @perror(i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %17
br label %32
30: ; preds = %2
%31 = load i32*, i32** @stdin
store i32* %31, i32** %6
br label %32
32: ; preds = %30, %29
%33 = load i32*, i32** %6
%34 = call double* @readdoubles(i32* %33, i32* %11)
store double* %34, double** %7
%35 = load i32, i32* %11
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 2)
unreachable
41: ; preds = %32
%42 = load double*, double** %7
%43 = load i32, i32* %11
%44 = call i32 @arraystats(double* %42, i32 %43, double* %8, double* %9, double* %10)
%45 = load double*, double** %7
%46 = load i32, i32* %11
%47 = load double, double* %8
%48 = load double, double* %9
%49 = call i32* @makedist(double* %45, i32 %46, double %47, double %48)
store i32* %49, i32** %12
%50 = load double*, double** %7
%51 = bitcast double* %50 to i8*
%52 = call i32 @free(i8* %51)
%53 = load i32*, i32** %12
%54 = call i32 @cumulativedist(i32* %53, i32 400000, i32* %14)
%55 = load i32*, i32** %12
%56 = load i32, i32* %14
%57 = call i16* @inverttable(i32* %55, i32 4096, i32 400000, i32 %56)
store i16* %57, i16** %13
%58 = load i16*, i16** %13
%59 = call i32 @interpolatetable(i16* %58, i32 4096)
%60 = load i16*, i16** %13
%61 = call i32 @printtable(i16* %60, i32 4096)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.1 = [20 x i8] c"Nothing much read!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = bitcast double* %3 to i8*
%9 = bitcast double* %4 to i8*
%10 = bitcast double* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i32 @perror(i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32*, i32** @stdin
br label %25
25: ; preds = %14, %23
%26 = phi i32* [ %17, %14 ], [ %24, %23 ]
%27 = call double* @readdoubles(i32* %26, i32* %6)
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %25
%35 = call i32 @arraystats(double* %27, i32 %28, double* %3, double* %4, double* %5)
%36 = load i32, i32* %6
%37 = load double, double* %3
%38 = load double, double* %4
%39 = call i32* @makedist(double* %27, i32 %36, double %37, double %38)
%40 = bitcast double* %27 to i8*
%41 = call i32 @free(i8* %40)
%42 = call i32 @cumulativedist(i32* %39, i32 400000, i32* %7)
%43 = load i32, i32* %7
%44 = call i16* @inverttable(i32* %39, i32 4096, i32 400000, i32 %43)
%45 = call i32 @interpolatetable(i16* %44, i32 4096)
%46 = call i32 @printtable(i16* %44, i32 4096)
ret i32 0
}