#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 MatchFilePart(char *, char *, int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int MatchWildcard(char *joker, char *filename, char *extension) {
  char *dot = strchr(joker, '.');
  char first[9];
  if (dot) {
    if (dot[1] == 0) {
      if (memcmp(extension, "   ", 3) != 0)
        return 0;
      strcpy(first, joker);
      first[strlen(first)] = 0;
      return MatchFilePart(first, filename, 8);
    } else {
      memcpy(first, joker, (int)(dot - joker));
      first[(int)(dot - joker)] = 0;
      return (MatchFilePart(first, filename, 8) &&
              MatchFilePart(dot + 1, extension, 3));
    }
  } else {
    return MatchFilePart(joker, filename, 8);
  }
}


x86 assembly (clang, -O0):
<MatchWildcard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     127f <MatchWildcard+0x11f>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1202 <MatchWildcard+0xa2>
mov    -0x20(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x3,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     11cd <MatchWildcard+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    1294 <MatchWildcard+0x134>
lea    -0x31(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x31(%rbp),%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x31(%rbp,%rax,1)
lea    -0x31(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <MatchFilePart@plt>
mov    %eax,-0x4(%rbp)
jmp    1294 <MatchWildcard+0x134>
lea    -0x31(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cltq
movb   $0x0,-0x31(%rbp,%rax,1)
lea    -0x31(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <MatchFilePart@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x32(%rbp)
je     126f <MatchWildcard+0x10f>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1060 <MatchFilePart@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <MatchWildcard+0x134>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <MatchFilePart@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatchWildcard>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e7 <MatchWildcard+0x87>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
je     1205 <MatchWildcard+0xa5>
mov    %rbx,%r13
sub    %r12,%r13
lea    0xf(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1080 <memcpy@plt>
movslq %r13d,%rax
movb   $0x0,0xf(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1060 <MatchFilePart@plt>
test   %eax,%eax
je     1252 <MatchWildcard+0xf2>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1060 <MatchFilePart@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    1254 <MatchWildcard+0xf4>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <MatchFilePart@plt>
lea    0xdf4(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1070 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1254 <MatchWildcard+0xf4>
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,0xf(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1060 <MatchFilePart@plt>
jmp    1254 <MatchWildcard+0xf4>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \00"
define i32 @MatchWildcard(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [9 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i8* @strchr(i8* %10, i8 signext 46)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %66
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %14
%21 = load i8*, i8** %7
%22 = call i64 @memcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %4
br label %70
25: ; preds = %20
%26 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%33 = load i8*, i8** %6
%34 = call i32 @MatchFilePart(i8* %32, i8* %33, i32 8)
store i32 %34, i32* %4
br label %70
35: ; preds = %14
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %5
%38 = load i8*, i8** %8
%39 = load i8*, i8** %5
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @memcpy(i8* %36, i8* %37, i32 %43)
%45 = load i8*, i8** %8
%46 = load i8*, i8** %5
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = trunc i64 %49 to i32
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 %51
store i8 0, i8* %52
%53 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%54 = load i8*, i8** %6
%55 = call i32 @MatchFilePart(i8* %53, i8* %54, i32 8)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %35
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8*, i8** %7
%61 = call i32 @MatchFilePart(i8* %59, i8* %60, i32 3)
%62 = icmp ne i32 %61, 0
br label %63
63: ; preds = %57, %35
%64 = phi i1 [ false, %35 ], [ %62, %57 ]
%65 = zext i1 %64 to i32
store i32 %65, i32* %4
br label %70
66: ; preds = %3
%67 = load i8*, i8** %5
%68 = load i8*, i8** %6
%69 = call i32 @MatchFilePart(i8* %67, i8* %68, i32 8)
store i32 %69, i32* %4
br label %70
70: ; preds = %66, %63, %25, %24
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [4 x i8] c" \00"
define i32 @MatchWildcard(i8* %0, i8* %1, i8* %2) {
%4 = alloca [9 x i8]
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %5, null
br i1 %7, label %35, label %8
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = tail call i64 @memcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = call i32 @strcpy(i8* %6, i8* %0)
%17 = call i64 @strlen(i8* %6)
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @MatchFilePart(i8* %6, i8* %1, i32 8)
br label %37
20: ; preds = %8
%21 = ptrtoint i8* %5 to i64
%22 = ptrtoint i8* %0 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = call i32 @memcpy(i8* %6, i8* %0, i32 %24)
%26 = shl i64 %23, 32
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @MatchFilePart(i8* %6, i8* %1, i32 8)
%30 = icmp eq i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %20
%32 = call i32 @MatchFilePart(i8* %9, i8* %2, i32 3)
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
br label %37
35: ; preds = %3
%36 = tail call i32 @MatchFilePart(i8* %0, i8* %1, i32 8)
br label %37
37: ; preds = %20, %31, %12, %35, %15
%38 = phi i32 [ %19, %15 ], [ %36, %35 ], [ 0, %12 ], [ 0, %20 ], [ %34, %31 ]
ret i32 %38
}