#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__ strcmp(char const *, char const *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int mp_strmatch(const char *string, const char *match) {
  size_t len = strlen(match);
  if (match[len - 1] == '*') {
    return (strncmp(string, match, len - 1) == 0);
  } else {
    return (strcmp(string, match) == 0);
  }
}


x86 assembly (clang, -O0):
<mp_strmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    118f <mp_strmatch+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <mp_strmatch+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_strmatch>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmpb   $0x2a,-0x1(%rbx,%rax,1)
jne    115d <mp_strmatch+0x2d>
add    $0xffffffffffffffff,%rax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
jmp    1168 <mp_strmatch+0x38>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @mp_strmatch(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = sub i64 %10, 1
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 42
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = sub i64 %19, 1
%21 = call i64 @strncmp(i8* %17, i8* %18, i64 %20)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
store i32 %23, i32* %3
br label %30
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %3
br label %30
30: ; preds = %24, %16
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @mp_strmatch(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add i64 %3, -1
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 42
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %4)
br label %12
10: ; preds = %2
%11 = tail call i64 @strcmp(i8* %0, i8* %1)
br label %12
12: ; preds = %10, %8
%13 = phi i64 [ %9, %8 ], [ %11, %10 ]
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
ret i32 %15
}