#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__ charmatches(char const, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
int subexplen(char const *);
int namematches(const char *name, const char *pattern) {
  int n;
  while (n = subexplen(pattern)) {
    if (*pattern == '[' && !name[1]) {
      if (charmatches(*name, pattern))
        return 1;
    } else if (!strncmp(name, pattern, n) && n == strlen(name))
      return 1;
    pattern += n;
    if (*pattern == '|')
      pattern++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<namematches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <subexplen@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1228 <namematches+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    11b0 <namematches+0x70>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    11b0 <namematches+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <charmatches@plt>
cmp    $0x0,%rax
je     11ab <namematches+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    122f <namematches+0xef>
jmp    11f6 <namematches+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11f1 <namematches+0xb1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jne    11f1 <namematches+0xb1>
movl   $0x1,-0x4(%rbp)
jmp    122f <namematches+0xef>
jmp    11f6 <namematches+0xb6>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7c,%eax
jne    1223 <namematches+0xe3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1150 <namematches+0x10>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<namematches>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <subexplen@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11e3 <namematches+0xa3>
mov    %eax,%r12d
jmp    11a7 <namematches+0x67>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d0 <namematches+0x90>
movslq %r12d,%rax
xor    %ebp,%ebp
cmpb   $0x7c,(%rbx,%rax,1)
sete   %bpl
add    %rbx,%rbp
add    %rax,%rbp
mov    %rbp,%rdi
call   1060 <subexplen@plt>
mov    %eax,%r12d
mov    %rbp,%rbx
test   %eax,%eax
je     11e3 <namematches+0xa3>
cmpb   $0x5b,(%rbx)
jne    1170 <namematches+0x30>
cmpb   $0x0,0x1(%r15)
jne    1170 <namematches+0x30>
movsbl (%r15),%edi
mov    %rbx,%rsi
call   1050 <charmatches@plt>
test   %rax,%rax
je     1182 <namematches+0x42>
jmp    11dd <namematches+0x9d>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r12d
jne    1182 <namematches+0x42>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @namematches(i8* %0, i8* %1) {
%3 = tail call i32 @subexplen(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %34, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
br label %7
7: ; preds = %5, %25
%8 = phi i32 [ %3, %5 ], [ %32, %25 ]
%9 = phi i8* [ %1, %5 ], [ %31, %25 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 91
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = load i8, i8* %6
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i8, i8* %0
%17 = tail call i64 @charmatches(i8 signext %16, i8* %9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %34
19: ; preds = %12, %7
%20 = tail call i32 @strncmp(i8* %0, i8* %9, i32 %8)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @strlen(i8* %0)
%24 = icmp eq i32 %8, %23
br i1 %24, label %34, label %25
25: ; preds = %19, %22, %15
%26 = sext i32 %8 to i64
%27 = getelementptr inbounds i8, i8* %9, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 124
%30 = zext i1 %29 to i64
%31 = getelementptr i8, i8* %27, i64 %30
%32 = tail call i32 @subexplen(i8* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %7
34: ; preds = %15, %22, %25, %2
%35 = phi i32 [ 0, %2 ], [ 0, %25 ], [ 1, %22 ], [ 1, %15 ]
ret i32 %35
}