#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 ber_element {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ber_free_elements(struct ber_element *);
int /*<<< orphan*/ ber_link_elements(struct ber_element *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
struct ber_element *ldap_do_parse_search_filter(struct ber_element *, char **);
struct ber_element *ldap_parse_search_filter(struct ber_element *ber,
                                             char *filter) {
  struct ber_element *elm;
  char *cp;
  cp = filter;
  if (cp == NULL || *cp == '\0') {
    errno = EINVAL;
    return (NULL);
  }
  if ((elm = ldap_do_parse_search_filter(ber, &cp)) == NULL)
    return (NULL);
  if (*cp != '\0') {
    ber_free_elements(elm);
    ber_link_elements(ber, NULL);
    errno = EINVAL;
    return (NULL);
  }
  return (elm);
}


x86 assembly (clang, -O0):
<ldap_parse_search_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1163 <ldap_parse_search_filter+0x33>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1182 <ldap_parse_search_filter+0x52>
mov    0x2e6e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6d(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f7 <ldap_parse_search_filter+0xc7>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <ldap_do_parse_search_filter@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11aa <ldap_parse_search_filter+0x7a>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <ldap_parse_search_filter+0xc7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <ldap_parse_search_filter+0xbf>
mov    -0x20(%rbp),%rdi
call   1030 <ber_free_elements@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ber_link_elements@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%ecx
mov    0x2e00(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f7 <ldap_parse_search_filter+0xc7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldap_parse_search_filter>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,0x8(%rsp)
test   %rsi,%rsi
je     1172 <ldap_parse_search_filter+0x42>
cmpb   $0x0,(%rsi)
je     1172 <ldap_parse_search_filter+0x42>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <ldap_do_parse_search_filter@plt>
test   %rax,%rax
je     1184 <ldap_parse_search_filter+0x54>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1186 <ldap_parse_search_filter+0x56>
mov    %rax,%rdi
call   1030 <ber_free_elements@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <ber_link_elements@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    0x2e5e(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ber_element = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.ber_element* @ldap_parse_search_filter(%struct.ber_element* %0, i8* %1) {
%3 = alloca %struct.ber_element*
%4 = alloca %struct.ber_element*
%5 = alloca i8*
%6 = alloca %struct.ber_element*
%7 = alloca i8*
store %struct.ber_element* %0, %struct.ber_element** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i8*, i8** %7
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11, %2
%17 = load i32, i32* @EINVAL
store i32 %17, i32* @errno
store %struct.ber_element* null, %struct.ber_element** %3
br label %36
18: ; preds = %11
%19 = load %struct.ber_element*, %struct.ber_element** %4
%20 = call %struct.ber_element* @ldap_do_parse_search_filter(%struct.ber_element* %19, i8** %7)
store %struct.ber_element* %20, %struct.ber_element** %6
%21 = icmp eq %struct.ber_element* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
store %struct.ber_element* null, %struct.ber_element** %3
br label %36
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load %struct.ber_element*, %struct.ber_element** %6
%30 = call i32 @ber_free_elements(%struct.ber_element* %29)
%31 = load %struct.ber_element*, %struct.ber_element** %4
%32 = call i32 @ber_link_elements(%struct.ber_element* %31, i32* null)
%33 = load i32, i32* @EINVAL
store i32 %33, i32* @errno
store %struct.ber_element* null, %struct.ber_element** %3
br label %36
34: ; preds = %23
%35 = load %struct.ber_element*, %struct.ber_element** %6
store %struct.ber_element* %35, %struct.ber_element** %3
br label %36
36: ; preds = %34, %28, %22, %16
%37 = load %struct.ber_element*, %struct.ber_element** %3
ret %struct.ber_element* %37
}

LLVM IR (-O2):
%struct.ber_element = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.ber_element* @ldap_parse_search_filter(%struct.ber_element* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %1, i8** %3
%5 = icmp eq i8* %1, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = call %struct.ber_element* @ldap_do_parse_search_filter(%struct.ber_element* %0, i8** %3)
%11 = icmp eq %struct.ber_element* %10, null
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = call i32 @ber_free_elements(%struct.ber_element* %10)
%18 = call i32 @ber_link_elements(%struct.ber_element* %0, i32* null)
br label %19
19: ; preds = %2, %6, %16
%20 = load i32, i32* @EINVAL
store i32 %20, i32* @errno
br label %21
21: ; preds = %19, %12, %9
%22 = phi %struct.ber_element* [ null, %9 ], [ %10, %12 ], [ null, %19 ]
ret %struct.ber_element* %22
}