#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 */
char *basename(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcmp(char const *, char const *);
char *strdup(char const *);
int filter_by_command(const char *search, const char *arg0) {
  if (!strcmp(search, arg0))
    return 1;
  char *arg0dup = strdup(arg0);
  if (!arg0dup) {
    perror("strdup");
    return 0;
  }
  char *base = basename(arg0dup);
  if (!strcmp(search, base)) {
    free(arg0dup);
    return 1;
  }
  free(arg0dup);
  return 0;
}


x86 assembly (clang, -O0):
<filter_by_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1182 <filter_by_command+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11fa <filter_by_command+0xaa>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <filter_by_command+0x62>
lea    0xe5f(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fa <filter_by_command+0xaa>
mov    -0x20(%rbp),%rdi
call   1050 <basename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ea <filter_by_command+0x9a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <filter_by_command+0xaa>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_by_command>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strcmp@plt>
test   %eax,%eax
je     1198 <filter_by_command+0x48>
mov    %rbx,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
je     11a4 <filter_by_command+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <basename@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    119d <filter_by_command+0x4d>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe55(%rip),%rdi
call   1060 <perror@plt>
xor    %ebp,%ebp
jmp    119d <filter_by_command+0x4d>

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

LLVM IR (-O2):
@.str = [7 x i8] c"strdup\00"
define i32 @filter_by_command(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %5
%11 = tail call i8* @basename(i8* %6)
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %11)
%13 = icmp eq i32 %12, 0
%14 = tail call i32 @free(i8* %6)
%15 = zext i1 %13 to i32
br label %16
16: ; preds = %10, %8, %2
%17 = phi i32 [ 1, %2 ], [ 0, %8 ], [ %15, %10 ]
ret i32 %17
}