#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ make_intervals(double, double, int, double **);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void deliver_frequencies(int size, double *data_array, int breaks,
                         int **delivery_frequencies,
                         double **delivery_intervals) {
  double *intervals;
  double themin = data_array[0];
  double themax = data_array[size - 1];
  int *buckets;
  int j;
  int place_in_bucket = 0;
  int the_bound = 1;
  int k;
  make_intervals(themin, themax, breaks, &intervals);
  *delivery_intervals = intervals;
  buckets = (int *)malloc(breaks * sizeof(int));
  if (buckets == NULL) {
    fputs("Error allocating memory", stderr);
    exit(EXIT_FAILURE);
  }
  for (j = 0; j < breaks; j++) {
    buckets[j] = 0;
  }
  for (k = 0; k < size; k++) {
    double num = data_array[k];
    if (num < intervals[the_bound]) {
      buckets[place_in_bucket]++;
    } else {
      the_bound++;
      place_in_bucket++;
      buckets[place_in_bucket]++;
    }
  }
  intervals[breaks]--;
  *delivery_frequencies = buckets;
}


x86 assembly (clang, -O0):
<deliver_frequencies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <make_intervals@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11ee <deliver_frequencies+0xae>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121e <deliver_frequencies+0xde>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11f5 <deliver_frequencies+0xb5>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12ab <deliver_frequencies+0x16b>
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1275 <deliver_frequencies+0x135>
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1298 <deliver_frequencies+0x158>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    129d <deliver_frequencies+0x15d>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1225 <deliver_frequencies+0xe5>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  0xd45(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deliver_frequencies>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebp
movsd  (%rsi),%xmm0
movslq %edi,%rax
movsd  -0x8(%rsi,%rax,8),%xmm1
lea    0x8(%rsp),%rsi
mov    %edx,%edi
call   1030 <make_intervals@plt>
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
lea    0x0(,%r15,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1219 <deliver_frequencies+0xc9>
mov    %rax,%rbx
test   %r15d,%r15d
jle    11b6 <deliver_frequencies+0x66>
mov    %r15d,%edx
shl    $0x2,%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x8(%rsp),%rax
test   %ebp,%ebp
jle    11f4 <deliver_frequencies+0xa4>
mov    %ebp,%ecx
xor    %edx,%edx
mov    $0x1,%esi
xor    %edi,%edi
nopw   0x0(%rax,%rax,1)
mov    %esi,%ebp
movsd  (%rax,%rbp,8),%xmm0
xor    %ebp,%ebp
ucomisd (%r12,%rdx,8),%xmm0
setbe  %bpl
add    %ebp,%edi
addl   $0x1,(%rbx,%rdi,4)
add    %ebp,%esi
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    11d0 <deliver_frequencies+0x80>
movslq %r15d,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  0xdfc(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    %rbx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xddf(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Error allocating memory\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define void @deliver_frequencies(i32 %0, double* %1, i32 %2, i32** %3, double** %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32**
%10 = alloca double**
%11 = alloca double*
%12 = alloca double
%13 = alloca double
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32** %3, i32*** %9
store double** %4, double*** %10
%20 = load double*, double** %7
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
store double %22, double* %12
%23 = load double*, double** %7
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %23, i64 %26
%28 = load double, double* %27
store double %28, double* %13
store i32 0, i32* %16
store i32 1, i32* %17
%29 = load double, double* %12
%30 = load double, double* %13
%31 = load i32, i32* %8
%32 = call i32 @make_intervals(double %29, double %30, i32 %31, double** %11)
%33 = load double*, double** %11
%34 = load double**, double*** %10
store double* %33, double** %34
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i32*
store i32* %40, i32** %14
%41 = load i32*, i32** %14
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %5
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %5
store i32 0, i32* %15
br label %49
49: ; preds = %58, %48
%50 = load i32, i32* %15
%51 = load i32, i32* %8
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i32*, i32** %14
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 0, i32* %57
br label %58
58: ; preds = %53
%59 = load i32, i32* %15
%60 = add nsw i32 %59, 1
store i32 %60, i32* %15
br label %49
61: ; preds = %49
store i32 0, i32* %18
br label %62
62: ; preds = %98, %61
%63 = load i32, i32* %18
%64 = load i32, i32* %6
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %101
66: ; preds = %62
%67 = load double*, double** %7
%68 = load i32, i32* %18
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
store double %71, double* %19
%72 = load double, double* %19
%73 = load double*, double** %11
%74 = load i32, i32* %17
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = fcmp olt double %72, %77
br i1 %78, label %79, label %86
79: ; preds = %66
%80 = load i32*, i32** %14
%81 = load i32, i32* %16
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
%84 = load i32, i32* %83
%85 = add nsw i32 %84, 1
store i32 %85, i32* %83
br label %97
86: ; preds = %66
%87 = load i32, i32* %17
%88 = add nsw i32 %87, 1
store i32 %88, i32* %17
%89 = load i32, i32* %16
%90 = add nsw i32 %89, 1
store i32 %90, i32* %16
%91 = load i32*, i32** %14
%92 = load i32, i32* %16
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
%96 = add nsw i32 %95, 1
store i32 %96, i32* %94
br label %97
97: ; preds = %86, %79
br label %98
98: ; preds = %97
%99 = load i32, i32* %18
%100 = add nsw i32 %99, 1
store i32 %100, i32* %18
br label %62
101: ; preds = %62
%102 = load double*, double** %11
%103 = load i32, i32* %8
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = fadd double %106, -1.000000e+00
store double %107, double* %105
%108 = load i32*, i32** %14
%109 = load i32**, i32*** %9
store i32* %108, i32** %109
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Error allocating memory\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define void @deliver_frequencies(i32 %0, double* nocapture %1, i32 %2, i32** nocapture writeonly %3, double** nocapture writeonly %4) {
%6 = alloca double*
%7 = bitcast double** %6 to i8*
%8 = load double, double* %1
%9 = add nsw i32 %0, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = call i32 @make_intervals(double %8, double %12, i32 %2, double** %6)
%14 = load double*, double** %6
store double* %14, double** %4
%15 = shl i32 %2, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
%18 = inttoptr i64 %16 to i8*
%19 = icmp eq i64 %16, 0
br i1 %19, label %25, label %20
20: ; preds = %5
%21 = icmp sgt i32 %2, 0
br i1 %21, label %22, label %30
22: ; preds = %20
%23 = zext i32 %2 to i64
%24 = shl nuw nsw i64 %23, 2
br label %30
25: ; preds = %5
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22, %20
%31 = icmp sgt i32 %0, 0
%32 = load double*, double** %6
br i1 %31, label %33, label %57
33: ; preds = %30
%34 = zext i32 %0 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %55, %35 ]
%37 = phi i32 [ 1, %33 ], [ %50, %35 ]
%38 = phi i32 [ 0, %33 ], [ %47, %35 ]
%39 = getelementptr inbounds double, double* %1, i64 %36
%40 = load double, double* %39
%41 = zext i32 %37 to i64
%42 = getelementptr inbounds double, double* %32, i64 %41
%43 = load double, double* %42
%44 = fcmp olt double %40, %43
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
%47 = add nuw nsw i32 %38, %46
%48 = xor i1 %44, true
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %37, %49
%51 = zext i32 %47 to i64
%52 = getelementptr inbounds i32, i32* %17, i64 %51
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
%55 = add nuw nsw i64 %36, 1
%56 = icmp eq i64 %55, %34
br i1 %56, label %57, label %35
57: ; preds = %35, %30
%58 = sext i32 %2 to i64
%59 = getelementptr inbounds double, double* %32, i64 %58
%60 = load double, double* %59
%61 = fadd double %60, -1.000000e+00
store double %61, double* %59
store i32* %17, i32** %3
ret void
}