#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 */
scalar_t__ ivec_sorted_count_occurrences(int const *, int, int const);
int ivec_sorted_count_occurrences_multiple(const int *v, int n, const int *vals,
                                           int nval) {
  int i;
  int accu = 0;
  for (i = 0; i < nval; i++)
    accu += ivec_sorted_count_occurrences(v, n, vals[i]);
  return accu;
}


x86 assembly (clang, -O0):
<ivec_sorted_count_occurrences_multiple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1172 <ivec_sorted_count_occurrences_multiple+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1030 <ivec_sorted_count_occurrences@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1134 <ivec_sorted_count_occurrences_multiple+0x24>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivec_sorted_count_occurrences_multiple>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    114c <ivec_sorted_count_occurrences_multiple+0x3c>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
mov    %ecx,%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
nop
mov    (%r14,%rbx,4),%edx
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <ivec_sorted_count_occurrences@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1130 <ivec_sorted_count_occurrences_multiple+0x20>
jmp    114e <ivec_sorted_count_occurrences_multiple+0x3e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ivec_sorted_count_occurrences_multiple(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
store i32 0, i32* %10
store i32 0, i32* %9
br label %11
11: ; preds = %28, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = load i32*, i32** %7
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = call i64 @ivec_sorted_count_occurrences(i32* %16, i32 %17, i32 %22)
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = add nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %10
br label %28
28: ; preds = %15
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %11
31: ; preds = %11
%32 = load i32, i32* %10
ret i32 %32
}

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