#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*/ printf(char *, int const);
void filter(const int *myarray, int (*comp)(const int, const int),
            const int val) {
  for (int a = 0; a < 5; a++) {
    if (comp(myarray[a], val))
      printf("%d \n", myarray[a]);
  }
}


x86 assembly (clang, -O0):
<filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    117b <filter+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
mov    (%rcx,%rdx,4),%edi
mov    -0x14(%rbp),%esi
call   *%rax
cmp    $0x0,%eax
je     1168 <filter+0x58>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
jmp    116d <filter+0x5d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <filter+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    %edx,%esi
call   *%r14
test   %eax,%eax
je     1135 <filter+0x25>
mov    (%rbx),%esi
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
mov    0x4(%rbx),%edi
mov    %ebp,%esi
call   *%r14
test   %eax,%eax
je     1150 <filter+0x40>
mov    0x4(%rbx),%esi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rbx),%edi
mov    %ebp,%esi
call   *%r14
test   %eax,%eax
je     116b <filter+0x5b>
mov    0x8(%rbx),%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    0xc(%rbx),%edi
mov    %ebp,%esi
call   *%r14
test   %eax,%eax
je     1186 <filter+0x76>
mov    0xc(%rbx),%esi
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rbx),%edi
mov    %ebp,%esi
call   *%r14
test   %eax,%eax
je     11a5 <filter+0x95>
mov    0x10(%rbx),%esi
lea    0xe64(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%d \0A\00"
define void @filter(i32* nocapture %0, i32 (i32, i32)* nocapture %1, i32 %2) {
%4 = load i32, i32* %0
%5 = tail call i32 %1(i32 %4, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i32, i32* %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %3, %7
%11 = getelementptr inbounds i32, i32* %0, i64 1
%12 = load i32, i32* %11
%13 = tail call i32 %1(i32 %12, i32 %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i32, i32* %11
%17 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %10
%19 = getelementptr inbounds i32, i32* %0, i64 2
%20 = load i32, i32* %19
%21 = tail call i32 %1(i32 %20, i32 %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* %19
%25 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %18
%27 = getelementptr inbounds i32, i32* %0, i64 3
%28 = load i32, i32* %27
%29 = tail call i32 %1(i32 %28, i32 %2)
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i32, i32* %27
%33 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %26
%35 = getelementptr inbounds i32, i32* %0, i64 4
%36 = load i32, i32* %35
%37 = tail call i32 %1(i32 %36, i32 %2)
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = load i32, i32* %35
%41 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %34
ret void
}