#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 */
struct confctl_var {
  int dummy;
};

/* Variables and functions */
struct confctl_var *confctl_var_first_child(struct confctl_var *);
int /*<<< orphan*/ confctl_var_name(struct confctl_var *);
struct confctl_var *confctl_var_next(struct confctl_var *);
int /*<<< orphan*/ *confctl_var_value(struct confctl_var *);
int /*<<< orphan*/ cv_mark(struct confctl_var *, int);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
bool cv_filter(struct confctl_var *cv, struct confctl_var *filter) {
  struct confctl_var *child, *filterchild;
  bool found;
  if (confctl_var_value(filter) != NULL)
    errx(1, "filter must not specify a value");
  if (strcmp(confctl_var_name(filter), confctl_var_name(cv)) != 0)
    return (false);
  for (child = confctl_var_first_child(cv); child != NULL;
       child = confctl_var_next(child)) {
    if (confctl_var_first_child(filter) == NULL) {
      found = true;
    } else {
      found = false;
      for (filterchild = confctl_var_first_child(filter); filterchild != NULL;
           filterchild = confctl_var_next(filterchild)) {
        if (cv_filter(child, filterchild))
          found = true;
      }
    }
    if (found)
      cv_mark(child, false);
    else
      cv_mark(child, true);
  }
  return (true);
}


x86 assembly (clang, -O0):
<cv_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <confctl_var_value@plt>
cmp    $0x0,%rax
je     11b4 <cv_filter+0x34>
mov    $0x1,%edi
lea    0xe51(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rdi
call   1060 <confctl_var_name@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <confctl_var_name@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <cv_filter+0x69>
movl   $0x0,-0x4(%rbp)
jmp    12be <cv_filter+0x13e>
mov    -0x10(%rbp),%rdi
call   1030 <confctl_var_first_child@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12b7 <cv_filter+0x137>
mov    -0x18(%rbp),%rdi
call   1030 <confctl_var_first_child@plt>
cmp    $0x0,%rax
jne    1220 <cv_filter+0xa0>
movl   $0x1,-0x2c(%rbp)
jmp    1278 <cv_filter+0xf8>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <confctl_var_first_child@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1273 <cv_filter+0xf3>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <cv_filter@plt>
cmp    $0x0,%eax
je     125c <cv_filter+0xdc>
movl   $0x1,-0x2c(%rbp)
jmp    1261 <cv_filter+0xe1>
mov    -0x28(%rbp),%rdi
call   1070 <confctl_var_next@plt>
mov    %rax,-0x28(%rbp)
jmp    1234 <cv_filter+0xb4>
jmp    1278 <cv_filter+0xf8>
cmpl   $0x0,-0x2c(%rbp)
je     1292 <cv_filter+0x112>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <cv_mark@plt>
jmp    12a0 <cv_filter+0x120>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1080 <cv_mark@plt>
jmp    12a5 <cv_filter+0x125>
mov    -0x20(%rbp),%rdi
call   1070 <confctl_var_next@plt>
mov    %rax,-0x20(%rbp)
jmp    11f6 <cv_filter+0x76>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cv_filter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   10a0 <confctl_var_value@plt>
test   %rax,%rax
je     11ac <cv_filter+0x2c>
lea    0xe5e(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    %r14,%rdi
call   1060 <confctl_var_name@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <confctl_var_name@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1279 <cv_filter+0xf9>
mov    %rbx,%rdi
call   1030 <confctl_var_first_child@plt>
test   %rax,%rax
je     1274 <cv_filter+0xf4>
mov    %rax,%r15
mov    $0x1,%r12d
jmp    121d <cv_filter+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%esi
mov    %r15,%rdi
call   1080 <cv_mark@plt>
mov    %r15,%rdi
call   1070 <confctl_var_next@plt>
mov    %rax,%r15
test   %rax,%rax
je     1274 <cv_filter+0xf4>
mov    %r14,%rdi
call   1030 <confctl_var_first_child@plt>
test   %rax,%rax
je     1270 <cv_filter+0xf0>
mov    %r14,%rdi
call   1030 <confctl_var_first_child@plt>
test   %rax,%rax
je     1200 <cv_filter+0x80>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <cv_filter@plt>
test   %eax,%eax
cmovne %r12d,%ebp
mov    %rbx,%rdi
call   1070 <confctl_var_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1240 <cv_filter+0xc0>
xor    %esi,%esi
test   %ebp,%ebp
jne    1205 <cv_filter+0x85>
jmp    1200 <cv_filter+0x80>
nopl   0x0(%rax)
xor    %esi,%esi
jmp    1205 <cv_filter+0x85>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.confctl_var = type { i32 }
@.str = [32 x i8] c"filter must not specify a value\00"
define i32 @cv_filter(%struct.confctl_var* %0, %struct.confctl_var* %1) {
%3 = alloca i32
%4 = alloca %struct.confctl_var*
%5 = alloca %struct.confctl_var*
%6 = alloca %struct.confctl_var*
%7 = alloca %struct.confctl_var*
%8 = alloca i32
store %struct.confctl_var* %0, %struct.confctl_var** %4
store %struct.confctl_var* %1, %struct.confctl_var** %5
%9 = load %struct.confctl_var*, %struct.confctl_var** %5
%10 = call i32* @confctl_var_value(%struct.confctl_var* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load %struct.confctl_var*, %struct.confctl_var** %5
%16 = call i32 @confctl_var_name(%struct.confctl_var* %15)
%17 = load %struct.confctl_var*, %struct.confctl_var** %4
%18 = call i32 @confctl_var_name(%struct.confctl_var* %17)
%19 = call i64 @strcmp(i32 %16, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 0, i32* %3
br label %64
22: ; preds = %14
%23 = load %struct.confctl_var*, %struct.confctl_var** %4
%24 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %23)
store %struct.confctl_var* %24, %struct.confctl_var** %6
br label %25
25: ; preds = %60, %22
%26 = load %struct.confctl_var*, %struct.confctl_var** %6
%27 = icmp ne %struct.confctl_var* %26, null
br i1 %27, label %28, label %63
28: ; preds = %25
%29 = load %struct.confctl_var*, %struct.confctl_var** %5
%30 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %29)
%31 = icmp eq %struct.confctl_var* %30, null
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %8
br label %50
33: ; preds = %28
store i32 0, i32* %8
%34 = load %struct.confctl_var*, %struct.confctl_var** %5
%35 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %34)
store %struct.confctl_var* %35, %struct.confctl_var** %7
br label %36
36: ; preds = %46, %33
%37 = load %struct.confctl_var*, %struct.confctl_var** %7
%38 = icmp ne %struct.confctl_var* %37, null
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load %struct.confctl_var*, %struct.confctl_var** %6
%41 = load %struct.confctl_var*, %struct.confctl_var** %7
%42 = call i32 @cv_filter(%struct.confctl_var* %40, %struct.confctl_var* %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 1, i32* %8
br label %45
45: ; preds = %44, %39
br label %46
46: ; preds = %45
%47 = load %struct.confctl_var*, %struct.confctl_var** %7
%48 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %47)
store %struct.confctl_var* %48, %struct.confctl_var** %7
br label %36
49: ; preds = %36
br label %50
50: ; preds = %49, %32
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load %struct.confctl_var*, %struct.confctl_var** %6
%55 = call i32 @cv_mark(%struct.confctl_var* %54, i32 0)
br label %59
56: ; preds = %50
%57 = load %struct.confctl_var*, %struct.confctl_var** %6
%58 = call i32 @cv_mark(%struct.confctl_var* %57, i32 1)
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59
%61 = load %struct.confctl_var*, %struct.confctl_var** %6
%62 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %61)
store %struct.confctl_var* %62, %struct.confctl_var** %6
br label %25
63: ; preds = %25
store i32 1, i32* %3
br label %64
64: ; preds = %63, %21
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.confctl_var = type { i32 }
@.str = [32 x i8] c"filter must not specify a value\00"
define i32 @cv_filter(%struct.confctl_var* %0, %struct.confctl_var* %1) {
%3 = tail call i32* @confctl_var_value(%struct.confctl_var* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @confctl_var_name(%struct.confctl_var* %1)
%9 = tail call i32 @confctl_var_name(%struct.confctl_var* %0)
%10 = tail call i64 @strcmp(i32 %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %7
%13 = tail call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %0)
%14 = icmp eq %struct.confctl_var* %13, null
br i1 %14, label %38, label %15
15: ; preds = %12, %33
%16 = phi %struct.confctl_var* [ %36, %33 ], [ %13, %12 ]
%17 = tail call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %1)
%18 = icmp eq %struct.confctl_var* %17, null
br i1 %18, label %33, label %19
19: ; preds = %15
%20 = tail call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %1)
%21 = icmp eq %struct.confctl_var* %20, null
br i1 %21, label %32, label %22
22: ; preds = %19, %22
%23 = phi i32 [ %27, %22 ], [ 0, %19 ]
%24 = phi %struct.confctl_var* [ %28, %22 ], [ %20, %19 ]
%25 = tail call i32 @cv_filter(%struct.confctl_var* %16, %struct.confctl_var* %24)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 %23, i32 1
%28 = tail call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %24)
%29 = icmp eq %struct.confctl_var* %28, null
br i1 %29, label %30, label %22
30: ; preds = %22
%31 = icmp eq i32 %27, 0
br i1 %31, label %32, label %33
32: ; preds = %19, %30
br label %33
33: ; preds = %30, %15, %32
%34 = phi i32 [ 1, %32 ], [ 0, %15 ], [ 0, %30 ]
%35 = tail call i32 @cv_mark(%struct.confctl_var* %16, i32 %34)
%36 = tail call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %16)
%37 = icmp eq %struct.confctl_var* %36, null
br i1 %37, label %38, label %15
38: ; preds = %33, %12, %7
%39 = phi i32 [ 0, %7 ], [ 1, %12 ], [ 1, %33 ]
ret i32 %39
}