#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(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int *histogramGold(int *data, int items, int bins) {
  int *refHistogram;
  refHistogram = (int *)malloc(bins * sizeof(int));
  if (!refHistogram) {
    exit(-1);
  }
  int i;
  for (i = 0; i < bins; i++) {
    refHistogram[i] = 0;
  }
  for (i = 0; i < items; i++) {
    if (data[i] >= bins) {
      printf("Warning: Histogram data value out-of-bounds\n");
    }
    refHistogram[data[i]]++;
  }
  return refHistogram;
}


x86 assembly (clang, -O0):
<histogramGold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116a <histogramGold+0x3a>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <histogramGold+0x6a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <histogramGold+0x41>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f4 <histogramGold+0xc4>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jl     11cd <histogramGold+0x9d>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <histogramGold+0x71>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histogramGold>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r13
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11cb <histogramGold+0x8b>
mov    %rax,%r15
test   %r14d,%r14d
jle    117e <histogramGold+0x3e>
mov    %r14d,%edx
shl    $0x2,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %ebp,%ebp
jle    11b9 <histogramGold+0x79>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe73(%rip),%r12
jmp    11a0 <histogramGold+0x60>
nop
cltq
addl   $0x1,(%r15,%rax,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b9 <histogramGold+0x79>
mov    0x0(%r13,%rbx,4),%eax
cmp    %r14d,%eax
jl     1190 <histogramGold+0x50>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    0x0(%r13,%rbx,4),%eax
jmp    1190 <histogramGold+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"Warning: Histogram data value out-of-bounds\0A\00"
define i32* @histogramGold(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %3
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %3
store i32 0, i32* %8
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32*, i32** %7
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 0, i32* %28
br label %29
29: ; preds = %24
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %20
32: ; preds = %20
store i32 0, i32* %8
br label %33
33: ; preds = %58, %32
%34 = load i32, i32* %8
%35 = load i32, i32* %5
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %61
37: ; preds = %33
%38 = load i32*, i32** %4
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %6
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %45, %37
%48 = load i32*, i32** %7
%49 = load i32*, i32** %4
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %48, i64 %54
%56 = load i32, i32* %55
%57 = add nsw i32 %56, 1
store i32 %57, i32* %55
br label %58
58: ; preds = %47
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %33
61: ; preds = %33
%62 = load i32*, i32** %7
ret i32* %62
}

LLVM IR (-O2):
@str = [44 x i8] c"Warning: Histogram data value out-of-bounds\00"
define i32* @histogramGold(i32* nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32*
%7 = inttoptr i64 %5 to i8*
%8 = icmp eq i64 %5, 0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = zext i32 %2 to i64
%13 = shl nuw nsw i64 %12, 2
br label %16
14: ; preds = %3
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %11, %9
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %36
18: ; preds = %16
%19 = zext i32 %1 to i64
br label %20
20: ; preds = %18, %28
%21 = phi i64 [ 0, %18 ], [ %34, %28 ]
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = icmp slt i32 %23, %2
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* %22
br label %28
28: ; preds = %25, %20
%29 = phi i32 [ %27, %25 ], [ %23, %20 ]
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %6, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %31
%34 = add nuw nsw i64 %21, 1
%35 = icmp eq i64 %34, %19
br i1 %35, label %36, label %20
36: ; preds = %28, %16
ret i32* %6
}