#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 */
int /*<<< orphan*/ strcmp(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int match(char *str, const char **value, unsigned count) {
  const char *val;
  unsigned n;
  int len;
  for (n = 0; n < count; n++) {
    const char *val = value[n];
    int len = strlen(val);
    int match;
    if ((len > 1) && (val[len - 1] == '*')) {
      len--;
      match = !strncmp(val, str, len);
    } else {
      match = !strcmp(val, str);
    }
    if (match)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1209 <match+0xd9>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jle    11c3 <match+0x93>
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    11c3 <match+0x93>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
jmp    11e0 <match+0xb0>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     11f6 <match+0xc6>
movl   $0x1,-0x4(%rbp)
jmp    1210 <match+0xe0>
jmp    11fb <match+0xcb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114a <match+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
je     119c <match+0x6c>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
jmp    1168 <match+0x38>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1195 <match+0x65>
add    $0x1,%rbx
cmp    %rbx,%r12
je     119c <match+0x6c>
mov    (%r14,%rbx,8),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1150 <match+0x20>
add    $0xffffffff,%eax
cmpb   $0x2a,0x0(%r13,%rax,1)
jne    1150 <match+0x20>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    115f <match+0x2f>
mov    $0x1,%eax
jmp    119e <match+0x6e>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @match(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %14
14: ; preds = %59, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %62
18: ; preds = %14
%19 = load i8**, i8*** %6
%20 = load i32, i32* %9
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %47
28: ; preds = %18
%29 = load i8*, i8** %11
%30 = load i32, i32* %12
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 42
br i1 %36, label %37, label %47
37: ; preds = %28
%38 = load i32, i32* %12
%39 = add nsw i32 %38, -1
store i32 %39, i32* %12
%40 = load i8*, i8** %11
%41 = load i8*, i8** %5
%42 = load i32, i32* %12
%43 = call i32 @strncmp(i8* %40, i8* %41, i32 %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
store i32 %46, i32* %13
br label %54
47: ; preds = %28, %18
%48 = load i8*, i8** %11
%49 = load i8*, i8** %5
%50 = call i32 @strcmp(i8* %48, i8* %49)
%51 = icmp ne i32 %50, 0
%52 = xor i1 %51, true
%53 = zext i1 %52 to i32
store i32 %53, i32* %13
br label %54
54: ; preds = %47, %37
%55 = load i32, i32* %13
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 1, i32* %4
br label %63
58: ; preds = %54
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add i32 %60, 1
store i32 %61, i32* %9
br label %14
62: ; preds = %14
store i32 0, i32* %4
br label %63
63: ; preds = %62, %57
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
define i32 @match(i8* %0, i8** nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %29, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %25
%8 = icmp eq i64 %28, %6
br i1 %8, label %29, label %9
9: ; preds = %5, %7
%10 = phi i64 [ 0, %5 ], [ %28, %7 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = add nsw i32 %13, -1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %12, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 42
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @strncmp(i8* %12, i8* %0, i32 %16)
br label %25
23: ; preds = %15, %9
%24 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(1) %0)
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
%27 = icmp eq i32 %26, 0
%28 = add nuw nsw i64 %10, 1
br i1 %27, label %29, label %7
29: ; preds = %25, %7, %3
%30 = phi i32 [ 0, %3 ], [ 0, %7 ], [ 1, %25 ]
ret i32 %30
}