#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 equal_nocase(unsigned char const *, size_t, unsigned char const *, size_t);
unsigned char *wildcard_find_star(unsigned char const *, size_t);
int wildcard_match(unsigned char const *, int, unsigned char const *, int,
                   unsigned char const *, size_t);
int equal_wildcard(const unsigned char *pattern, size_t pattern_len,
                   const unsigned char *subject, size_t subject_len) {
  const unsigned char *star = wildcard_find_star(pattern, pattern_len);
  if (star == NULL)
    return equal_nocase(pattern, pattern_len, subject, subject_len);
  return wildcard_match(pattern, star - pattern, star + 1,
                        (pattern + pattern_len) - star - 1, subject,
                        subject_len);
}


x86 assembly (clang, -O0):
<equal_wildcard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <wildcard_find_star@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1181 <equal_wildcard+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <equal_nocase@plt>
mov    %eax,-0x4(%rbp)
jmp    11bf <equal_wildcard+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1030 <wildcard_match@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<equal_wildcard>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
call   1040 <wildcard_find_star@plt>
test   %rax,%rax
je     117c <equal_wildcard+0x4c>
mov    %eax,%esi
sub    %ebx,%esi
mov    %rax,%rdx
add    $0x1,%rdx
add    %ebx,%r12d
not    %eax
add    %r12d,%eax
mov    %rbx,%rdi
mov    %eax,%ecx
mov    %r15,%r8
mov    %r14,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <wildcard_match@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <equal_nocase@plt>

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

LLVM IR (-O2):
define i32 @equal_wildcard(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = tail call i8* @wildcard_find_star(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @equal_nocase(i8* %0, i64 %1, i8* %2, i64 %3)
br label %21
9: ; preds = %4
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = getelementptr inbounds i8, i8* %5, i64 1
%15 = getelementptr inbounds i8, i8* %0, i64 %1
%16 = ptrtoint i8* %15 to i64
%17 = xor i64 %10, -1
%18 = add i64 %17, %16
%19 = trunc i64 %18 to i32
%20 = tail call i32 @wildcard_match(i8* %0, i32 %13, i8* %14, i32 %19, i8* %2, i64 %3)
br label %21
21: ; preds = %9, %7
%22 = phi i32 [ %8, %7 ], [ %20, %9 ]
ret i32 %22
}