#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_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 *lang = prj_get_language_for(i);
    if (matches(lang, "c++") || matches(lang, "c")) {
      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   1060 <prj_find_package@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11dd <filterLinks+0x8d>
mov    -0x14(%rbp),%edi
call   1040 <prj_get_language_for@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
jne    11b2 <filterLinks+0x62>
mov    -0x20(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1030 <matches@plt>
cmp    $0x0,%rax
je     11d0 <filterLinks+0x80>
mov    -0x14(%rbp),%edi
call   1070 <prj_get_targetname_for@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <path_getname@plt>
mov    %rax,-0x8(%rbp)
jmp    11e5 <filterLinks+0x95>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <filterLinks+0x95>
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   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <prj_find_package@plt>
test   %eax,%eax
js     11aa <filterLinks+0x5a>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <prj_get_language_for@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1030 <matches@plt>
test   %rax,%rax
jne    1193 <filterLinks+0x43>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <matches@plt>
test   %rax,%rax
je     11a8 <filterLinks+0x58>
mov    %ebp,%edi
call   1070 <prj_get_targetname_for@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <path_getname@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"c++\00"
@.str.1 = [2 x i8] c"c\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 %14
4: ; preds = %1
%5 = tail call i8* @prj_get_language_for(i32 %2)
%6 = tail call i64 @matches(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i64 @matches(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8, %4
%12 = tail call i8* @prj_get_targetname_for(i32 %2)
%13 = tail call i8* @path_getname(i8* %12)
br label %14
14: ; preds = %1, %11, %8
%15 = phi i8* [ %13, %11 ], [ null, %8 ], [ %0, %1 ]
ret i8* %15
}