#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 */
char *strchr(char const *, char);
int /*<<< orphan*/ strcmp(char const *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
int string_match(const char *pattern, const char *text) {
  char *w;
  int headlen, taillen;
  w = strchr(pattern, '*');
  if (!w)
    return !strcmp(pattern, text);
  headlen = w - pattern;
  taillen = strlen(pattern) - headlen - 1;
  return !strncmp(pattern, text, headlen) &&
         !strcmp(&pattern[headlen + 1], &text[strlen(text) - taillen]);
}


x86 assembly (clang, -O0):
<string_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <string_match+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    121f <string_match+0xdf>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    1214 <string_match+0xd4>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdi
sub    -0x28(%rbp),%eax
cltq
add    %rax,%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1181 <string_match+0x41>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1189 <string_match+0x49>
xor    %eax,%eax
jmp    11b5 <string_match+0x75>
mov    %r15,%rdi
mov    %r14,%rsi
jmp    11ab <string_match+0x6b>
mov    %ebx,%eax
add    $0x1,%eax
cltq
add    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %ebp,%ebx
add    %ebx,%eax
add    $0x1,%eax
movslq %eax,%rsi
add    %r14,%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
sete   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @string_match(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 42)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%7 = icmp eq i32 %6, 0
br label %29
8: ; preds = %2
%9 = ptrtoint i8* %3 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %12)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %8
%17 = add i32 %12, 1
%18 = shl i64 %11, 32
%19 = add i64 %18, 4294967296
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = tail call i32 @strlen(i8* %1)
%23 = sub i32 %17, %13
%24 = add i32 %23, %22
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(1) %26)
%28 = icmp eq i32 %27, 0
br label %29
29: ; preds = %8, %16, %5
%30 = phi i1 [ %7, %5 ], [ false, %8 ], [ %28, %16 ]
%31 = zext i1 %30 to i32
ret i32 %31
}