#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*/ fatalx(char *);
int /*<<< orphan*/ ivzero(int *, int);
void countcat(int *tags, int n, int *ncat, int nclass) {
  int i, k;
  ivzero(ncat, nclass);
  for (i = 0; i < n; i++) {
    k = tags[i];
    if ((k < 0) || (k >= nclass))
      fatalx("(countcat) bounds error\n");
    ++ncat[k];
  }
}


x86 assembly (clang, -O0):
<countcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <ivzero@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <countcat+0x84>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1179 <countcat+0x59>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1185 <countcat+0x65>
lea    0xe80(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1149 <countcat+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countcat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%r12
mov    %rdx,%rdi
mov    %ecx,%esi
call   1030 <ivzero@plt>
test   %r15d,%r15d
jle    117b <countcat+0x5b>
mov    %r15d,%ebp
xor    %ebx,%ebx
jmp    116b <countcat+0x4b>
nopl   (%rax)
lea    0xea9(%rip),%rdi
call   1040 <fatalx@plt>
addl   $0x1,0x0(%r13,%r15,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     117b <countcat+0x5b>
movslq (%r12,%rbx,4),%r15
test   %r15,%r15
js     1150 <countcat+0x30>
cmp    %r14d,%r15d
jl     115c <countcat+0x3c>
jmp    1150 <countcat+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"(countcat) bounds error\0A\00"
define void @countcat(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%11 = load i32*, i32** %7
%12 = load i32, i32* %8
%13 = call i32 @ivzero(i32* %11, i32 %12)
store i32 0, i32* %9
br label %14
14: ; preds = %39, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %42
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp slt i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i32, i32* %10
%28 = load i32, i32* %8
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26, %18
%31 = call i32 @fatalx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32*, i32** %7
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
br label %39
39: ; preds = %32
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %14
42: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"(countcat) bounds error\0A\00"
define void @countcat(i32* nocapture %0, i32 %1, i32* %2, i32 %3) {
%5 = tail call i32 @ivzero(i32* %2, i32 %3)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %18
%10 = phi i64 [ 0, %7 ], [ %23, %18 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, -1
%14 = icmp slt i32 %12, %3
%15 = and i1 %13, %14
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = tail call i32 @fatalx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %9, %16
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i32, i32* %2, i64 %19
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
%23 = add nuw nsw i64 %10, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %9
25: ; preds = %18, %4
ret void
}