#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 *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ rint(double);
int *makedist(double *x, int limit, double mu, double sigma) {
  int *table;
  int i, index, first = (((32767 / 8192) + 1) * 50000 * 2), last = 0;
  double input;
  table = calloc((((32767 / 8192) + 1) * 50000 * 2), sizeof(int));
  if (!table) {
    perror("table alloc");
    exit(3);
  }
  for (i = 0; i < limit; ++i) {
    input = (x[i] - mu) / sigma;
    index = (int)rint((input + ((32767 / 8192) + 1)) * 50000);
    if (index < 0)
      index = 0;
    if (index >= (((32767 / 8192) + 1) * 50000 * 2))
      index = (((32767 / 8192) + 1) * 50000 * 2) - 1;
    ++table[index];
    if (index > last)
      last = index + 1;
    if (index < first)
      first = index;
  }
  return table;
}


x86 assembly (clang, -O0):
<makedist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x61a80,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    $0x61a80,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119b <makedist+0x5b>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125b <makedist+0x11b>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe36(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xe21(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <rint@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11fc <makedist+0xbc>
movl   $0x0,-0x30(%rbp)
cmpl   $0x61a80,-0x30(%rbp)
jl     1210 <makedist+0xd0>
movl   $0x61a7f,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    1236 <makedist+0xf6>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1248 <makedist+0x108>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    124d <makedist+0x10d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a2 <makedist+0x62>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makedist>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x61a80,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11e5 <makedist+0xa5>
mov    %rax,%r15
test   %ebp,%ebp
jle    11d5 <makedist+0x95>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    $0x61a7f,%r12d
jmp    11a7 <makedist+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x61a7f,%eax
cmovae %r12d,%eax
addl   $0x1,(%r15,%rax,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11d5 <makedist+0x95>
movsd  (%r14,%rbx,8),%xmm0
subsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe40(%rip),%xmm0
mulsd  0xe40(%rip),%xmm0
call   1040 <rint@plt>
test   %eax,%eax
jns    1190 <makedist+0x50>
xor    %eax,%eax
jmp    1190 <makedist+0x50>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe24(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"table alloc\00"
define i32* @makedist(double* %0, i32 %1, double %2, double %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
store i32 400000, i32* %12
store i32 0, i32* %13
%15 = call i32* @calloc(i32 400000, i32 4)
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %4
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 3)
unreachable
21: ; preds = %4
store i32 0, i32* %10
br label %22
22: ; preds = %68, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %71
26: ; preds = %22
%27 = load double*, double** %5
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double, double* %7
%33 = fsub double %31, %32
%34 = load double, double* %8
%35 = fdiv double %33, %34
store double %35, double* %14
%36 = load double, double* %14
%37 = fadd double %36, 4.000000e+00
%38 = fmul double %37, 5.000000e+04
%39 = call i64 @rint(double %38)
%40 = trunc i64 %39 to i32
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %26
store i32 0, i32* %11
br label %44
44: ; preds = %43, %26
%45 = load i32, i32* %11
%46 = icmp sge i32 %45, 400000
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 399999, i32* %11
br label %48
48: ; preds = %47, %44
%49 = load i32*, i32** %9
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
%55 = load i32, i32* %11
%56 = load i32, i32* %13
%57 = icmp sgt i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
br label %61
61: ; preds = %58, %48
%62 = load i32, i32* %11
%63 = load i32, i32* %12
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = load i32, i32* %11
store i32 %66, i32* %12
br label %67
67: ; preds = %65, %61
br label %68
68: ; preds = %67
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %22
71: ; preds = %22
%72 = load i32*, i32** %9
ret i32* %72
}

LLVM IR (-O2):
@.str = [12 x i8] c"table alloc\00"
define noalias i32* @makedist(double* nocapture %0, i32 %1, double %2, double %3) {
%5 = tail call i32* @calloc(i32 400000, i32 4)
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %34
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %14
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 3)
unreachable
14: ; preds = %9, %14
%15 = phi i64 [ 0, %9 ], [ %32, %14 ]
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fsub double %17, %2
%19 = fdiv double %18, %3
%20 = fadd double %19, 4.000000e+00
%21 = fmul double %20, 5.000000e+04
%22 = tail call i64 @rint(double %21)
%23 = trunc i64 %22 to i32
%24 = icmp sgt i32 %23, 0
%25 = select i1 %24, i32 %23, i32 0
%26 = icmp ult i32 %25, 399999
%27 = select i1 %26, i32 %25, i32 399999
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %5, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %10
br i1 %33, label %34, label %14
34: ; preds = %14, %7
ret i32* %5
}