#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__ matches(char const *, char *);
char const *path_getname(char const *);
int prj_find_package(char const *);
char *prj_get_kind_for(int);
char *prj_get_language_for(int);
char *prj_get_targetname_for(int);
const char *filterLinks(const char *name) {
  int i = prj_find_package(name);
  if (i >= 0) {
    const char *kind = prj_get_kind_for(i);
    const char *lang = prj_get_language_for(i);
    if ((matches(lang, "c++") || matches(lang, "c")) &&
        (matches(kind, "dll") || matches(kind, "lib"))) {
      const char *target = prj_get_targetname_for(i);
      return path_getname(target);
    } else {
      return NULL;
    }
  } else {
    return name;
  }
}


x86 assembly (clang, -O0):
<filterLinks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <prj_find_package@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     122d <filterLinks+0xcd>
mov    -0x14(%rbp),%edi
call   1060 <prj_get_kind_for@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <prj_get_language_for@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
jne    11ce <filterLinks+0x6e>
mov    -0x28(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
je     1220 <filterLinks+0xc0>
mov    -0x20(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
jne    1202 <filterLinks+0xa2>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
je     1220 <filterLinks+0xc0>
mov    -0x14(%rbp),%edi
call   1080 <prj_get_targetname_for@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <path_getname@plt>
mov    %rax,-0x8(%rbp)
jmp    1235 <filterLinks+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    1235 <filterLinks+0xd5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filterLinks>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1070 <prj_find_package@plt>
test   %eax,%eax
js     11eb <filterLinks+0x8b>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <prj_get_kind_for@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1040 <prj_get_language_for@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rsi
mov    %rax,%rdi
call   1030 <matches@plt>
test   %rax,%rax
jne    11ae <filterLinks+0x4e>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1030 <matches@plt>
test   %rax,%rax
je     11e9 <filterLinks+0x89>
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
call   1030 <matches@plt>
test   %rax,%rax
jne    11d6 <filterLinks+0x76>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   1030 <matches@plt>
test   %rax,%rax
je     11e9 <filterLinks+0x89>
mov    %ebp,%edi
call   1080 <prj_get_targetname_for@plt>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <path_getname@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"c++\00"
@.str.1 = [2 x i8] c"c\00"
@.str.2 = [4 x i8] c"dll\00"
@.str.3 = [4 x i8] c"lib\00"
define i8* @filterLinks(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @prj_find_package(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i8* @prj_get_kind_for(i32 %13)
store i8* %14, i8** %5
%15 = load i32, i32* %4
%16 = call i8* @prj_get_language_for(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i64 @matches(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %12
%21 = load i8*, i8** %6
%22 = call i64 @matches(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %20, %12
%25 = load i8*, i8** %5
%26 = call i64 @matches(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = call i64 @matches(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28, %24
%33 = load i32, i32* %4
%34 = call i8* @prj_get_targetname_for(i32 %33)
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = call i8* @path_getname(i8* %35)
store i8* %36, i8** %2
br label %40
37: ; preds = %28, %20
store i8* null, i8** %2
br label %40
38: ; preds = %1
%39 = load i8*, i8** %3
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %37, %32
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [4 x i8] c"c++\00"
@.str.1 = [2 x i8] c"c\00"
@.str.2 = [4 x i8] c"dll\00"
@.str.3 = [4 x i8] c"lib\00"
define i8* @filterLinks(i8* %0) {
%2 = tail call i32 @prj_find_package(i8* %0)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = tail call i8* @prj_get_kind_for(i32 %2)
%6 = tail call i8* @prj_get_language_for(i32 %2)
%7 = tail call i64 @matches(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i64 @matches(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9, %4
%13 = tail call i64 @matches(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i64 @matches(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %12
%19 = tail call i8* @prj_get_targetname_for(i32 %2)
%20 = tail call i8* @path_getname(i8* %19)
br label %21
21: ; preds = %1, %18, %15, %9
%22 = phi i8* [ %20, %18 ], [ null, %15 ], [ null, %9 ], [ %0, %1 ]
ret i8* %22
}