#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__ memcmp(char const *, char const *, size_t);
int bucket_contains(const char *bucket, const char *value,
                    unsigned char *bitmask) {
  if (bucket == NULL)
    return 0;
  while (*bucket) {
    if (memcmp(bucket + 2, value, (size_t)bucket[0]) == 0) {
      if (bitmask)
        *bitmask = ~bucket[1] & 0xff;
      return 1;
    }
    bucket += *bucket + 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bucket_contains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113b <bucket_contains+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <bucket_contains+0xb3>
jmp    1140 <bucket_contains+0x30>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bc <bucket_contains+0xac>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
movsbq (%rax),%rdx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    119f <bucket_contains+0x8f>
cmpq   $0x0,-0x20(%rbp)
je     1193 <bucket_contains+0x83>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
xor    $0xffffffff,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c3 <bucket_contains+0xb3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
add    $0x2,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1140 <bucket_contains+0x30>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bucket_contains>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     116e <bucket_contains+0x5e>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     116e <bucket_contains+0x5e>
mov    %rdx,%r14
mov    %rsi,%rbp
xchg   %ax,%ax
lea    0x2(%rbx),%rdi
movsbq %al,%rdx
mov    %rbp,%rsi
call   1030 <memcmp@plt>
test   %rax,%rax
je     115b <bucket_contains+0x4b>
movsbq (%rbx),%rcx
movzbl 0x2(%rcx,%rbx,1),%eax
add    %rcx,%rbx
add    $0x2,%rbx
test   %al,%al
jne    1130 <bucket_contains+0x20>
jmp    116e <bucket_contains+0x5e>
mov    $0x1,%r15d
test   %r14,%r14
je     116e <bucket_contains+0x5e>
mov    0x1(%rbx),%al
not    %al
mov    %al,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bucket_contains(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 0, i32* %4
br label %48
11: ; preds = %3
br label %12
12: ; preds = %39, %11
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %47
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i64
%24 = call i64 @memcmp(i8* %18, i8* %19, i64 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %16
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = xor i32 %33, -1
%35 = and i32 %34, 255
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %7
store i8 %36, i8* %37
br label %38
38: ; preds = %29, %26
store i32 1, i32* %4
br label %48
39: ; preds = %16
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = add nsw i32 %42, 2
%44 = load i8*, i8** %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %5
br label %12
47: ; preds = %12
store i32 0, i32* %4
br label %48
48: ; preds = %47, %38, %10
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
define i32 @bucket_contains(i8* %0, i8* %1, i8* writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %5, %21
%9 = phi i8 [ %26, %21 ], [ %6, %5 ]
%10 = phi i8* [ %25, %21 ], [ %0, %5 ]
%11 = getelementptr inbounds i8, i8* %10, i64 2
%12 = sext i8 %9 to i64
%13 = tail call i64 @memcmp(i8* %11, i8* %1, i64 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = icmp eq i8* %2, null
br i1 %16, label %28, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %18
%20 = xor i8 %19, -1
store i8 %20, i8* %2
br label %28
21: ; preds = %8
%22 = load i8, i8* %10
%23 = sext i8 %22 to i64
%24 = add nsw i64 %23, 2
%25 = getelementptr inbounds i8, i8* %10, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %8
28: ; preds = %21, %5, %15, %17, %3
%29 = phi i32 [ 0, %3 ], [ 1, %17 ], [ 1, %15 ], [ 0, %5 ], [ 0, %21 ]
ret i32 %29
}