#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 *histogramGoldFloat(float *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 ((int)data[i] >= bins) {
      printf("Warning: Histogram data value out-of-bounds\n");
    }
    refHistogram[(int)data[i]]++;
  }
  return refHistogram;
}


x86 assembly (clang, -O0):
<histogramGoldFloat>:
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 <histogramGoldFloat+0x3a>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <histogramGoldFloat+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 <histogramGoldFloat+0x41>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fa <histogramGoldFloat+0xca>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cvttss2si (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jl     11cf <histogramGoldFloat+0x9f>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
cvttss2si (%rcx,%rdx,4),%ecx
movslq %ecx,%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 <histogramGoldFloat+0x71>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histogramGoldFloat>:
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     11cf <histogramGoldFloat+0x8f>
mov    %rax,%r15
test   %r14d,%r14d
jle    117e <histogramGoldFloat+0x3e>
mov    %r14d,%edx
shl    $0x2,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %ebp,%ebp
jle    11bd <histogramGoldFloat+0x7d>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe73(%rip),%r12
jmp    11a0 <histogramGoldFloat+0x60>
nop
cltq
addl   $0x1,(%r15,%rax,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11bd <histogramGoldFloat+0x7d>
cvttss2si 0x0(%r13,%rbx,4),%eax
cmp    %r14d,%eax
jl     1190 <histogramGoldFloat+0x50>
mov    %r12,%rdi
call   1030 <puts@plt>
cvttss2si 0x0(%r13,%rbx,4),%eax
jmp    1190 <histogramGoldFloat+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* @histogramGoldFloat(float* %0, i32 %1, i32 %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store float* %0, float** %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 = %60, %32
%34 = load i32, i32* %8
%35 = load i32, i32* %5
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %63
37: ; preds = %33
%38 = load float*, float** %4
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = load float, float* %41
%43 = fptosi float %42 to i32
%44 = load i32, i32* %6
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %37
%49 = load i32*, i32** %7
%50 = load float*, float** %4
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds float, float* %50, i64 %52
%54 = load float, float* %53
%55 = fptosi float %54 to i32
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %49, i64 %56
%58 = load i32, i32* %57
%59 = add nsw i32 %58, 1
store i32 %59, i32* %57
br label %60
60: ; preds = %48
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %33
63: ; preds = %33
%64 = load i32*, i32** %7
ret i32* %64
}

LLVM IR (-O2):
@str = [44 x i8] c"Warning: Histogram data value out-of-bounds\00"
define i32* @histogramGoldFloat(float* 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 %38
18: ; preds = %16
%19 = zext i32 %1 to i64
br label %20
20: ; preds = %18, %30
%21 = phi i64 [ 0, %18 ], [ %36, %30 ]
%22 = getelementptr inbounds float, float* %0, i64 %21
%23 = load float, float* %22
%24 = fptosi float %23 to i32
%25 = icmp slt i32 %24, %2
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%28 = load float, float* %22
%29 = fptosi float %28 to i32
br label %30
30: ; preds = %26, %20
%31 = phi i32 [ %29, %26 ], [ %24, %20 ]
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %6, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
%36 = add nuw nsw i64 %21, 1
%37 = icmp eq i64 %36, %19
br i1 %37, label %38, label %20
38: ; preds = %30, %16
ret i32* %6
}