#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);
size_t count_of_value(int *array, size_t begin, size_t end, int value,
                      size_t pos[3]) {
  size_t count = 0;
  size_t i = begin;
  for (; i < end; ++i) {
    if (value == array[i]) {
      pos[count++] = i;
      assert(count <= 3);
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<count_of_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a0 <count_of_value+0x90>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    -0x38(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    118a <count_of_value+0x7a>
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x3,-0x30(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    118f <count_of_value+0x7f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    113b <count_of_value+0x2b>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_of_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rdx,%rsi
jae    1169 <count_of_value+0x59>
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r13
xor    %ebp,%ebp
jmp    1149 <count_of_value+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     116b <count_of_value+0x5b>
cmp    %r15d,0x0(%r13,%rbx,4)
jne    1140 <count_of_value+0x30>
mov    %rbx,(%r14,%rbp,8)
add    $0x1,%rbp
xor    %edi,%edi
cmp    $0x4,%rbp
setb   %dil
call   1030 <assert@plt>
jmp    1140 <count_of_value+0x30>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @count_of_value(i32* %0, i64 %1, i64 %2, i32 %3, i64* %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64*
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i64* %4, i64** %10
store i64 0, i64* %11
%13 = load i64, i64* %7
store i64 %13, i64* %12
br label %14
14: ; preds = %36, %5
%15 = load i64, i64* %12
%16 = load i64, i64* %8
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i32, i32* %9
%20 = load i32*, i32** %6
%21 = load i64, i64* %12
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = icmp eq i32 %19, %23
br i1 %24, label %25, label %35
25: ; preds = %18
%26 = load i64, i64* %12
%27 = load i64*, i64** %10
%28 = load i64, i64* %11
%29 = add i64 %28, 1
store i64 %29, i64* %11
%30 = getelementptr inbounds i64, i64* %27, i64 %28
store i64 %26, i64* %30
%31 = load i64, i64* %11
%32 = icmp ule i64 %31, 3
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %35
35: ; preds = %25, %18
br label %36
36: ; preds = %35
%37 = load i64, i64* %12
%38 = add i64 %37, 1
store i64 %38, i64* %12
br label %14
39: ; preds = %14
%40 = load i64, i64* %11
ret i64 %40
}

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