#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*/ assert(int);
int *ivec_new_0(int);
int *ivec_new_histogram(int k, int *v, long n) {
  long i;
  int *h = ivec_new_0(k);
  for (i = 0; i < n; i++) {
    assert(v[i] >= 0 && v[i] < k);
    h[v[i]]++;
  }
  return h;
}


x86 assembly (clang, -O0):
<ivec_new_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <ivec_new_0@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11b7 <ivec_new_histogram+0x97>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x29(%rbp)
jl     1180 <ivec_new_histogram+0x60>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1147 <ivec_new_histogram+0x27>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivec_new_histogram>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
call   1040 <ivec_new_0@plt>
mov    %rax,%r12
test   %r14,%r14
jle    116a <ivec_new_histogram+0x4a>
xor    %ebp,%ebp
mov    (%rbx,%rbp,4),%eax
test   %eax,%eax
setns  %cl
cmp    %r15d,%eax
setl   %al
and    %cl,%al
movzbl %al,%edi
call   1030 <assert@plt>
movslq (%rbx,%rbp,4),%rax
addl   $0x1,(%r12,%rax,4)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1140 <ivec_new_histogram+0x20>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @ivec_new_histogram(i32 %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%9 = load i32, i32* %4
%10 = call i32* @ivec_new_0(i32 %9)
store i32* %10, i32** %8
store i64 0, i64* %7
br label %11
11: ; preds = %41, %3
%12 = load i64, i64* %7
%13 = load i64, i64* %6
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i64, i64* %7
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i32, i32* %18
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32*, i32** %5
%23 = load i64, i64* %7
%24 = getelementptr inbounds i32, i32* %22, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br label %28
28: ; preds = %21, %15
%29 = phi i1 [ false, %15 ], [ %27, %21 ]
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32*, i32** %8
%33 = load i32*, i32** %5
%34 = load i64, i64* %7
%35 = getelementptr inbounds i32, i32* %33, i64 %34
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %32, i64 %37
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
store i32 %40, i32* %38
br label %41
41: ; preds = %28
%42 = load i64, i64* %7
%43 = add nsw i64 %42, 1
store i64 %43, i64* %7
br label %11
44: ; preds = %11
%45 = load i32*, i32** %8
ret i32* %45
}

LLVM IR (-O2):
define i32* @ivec_new_histogram(i32 %0, i32* nocapture %1, i64 %2) {
%4 = tail call i32* @ivec_new_0(i32 %0)
%5 = icmp sgt i64 %2, 0
br i1 %5, label %6, label %22
6: ; preds = %3, %6
%7 = phi i64 [ %20, %6 ], [ 0, %3 ]
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = icmp sgt i32 %9, -1
%11 = icmp slt i32 %9, %0
%12 = and i1 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %4, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = add nuw nsw i64 %7, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %22, label %6
22: ; preds = %6, %3
ret i32* %4
}