#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__ fnmatch(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
int /*<<< orphan*/ strtoupper(char *);
short int shellpattern_match(const char *string, const char *pattern,
                             short int casess) {
  char *stringcp = NULL;
  char *patterncp = NULL;
  short int match = 0;
  if (!pattern || !string)
    return (0);
  stringcp = strdup(string);
  patterncp = strdup(pattern);
  if (!casess) {
    strtoupper(stringcp);
    strtoupper(patterncp);
  }
  match = (fnmatch(patterncp, stringcp, 0) == 0);
  free(patterncp);
  free(stringcp);
  return (match);
}


x86 assembly (clang, -O0):
<shellpattern_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movw   $0x0,-0x32(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1183 <shellpattern_match+0x43>
cmpq   $0x0,-0x10(%rbp)
jne    118e <shellpattern_match+0x4e>
movw   $0x0,-0x2(%rbp)
jmp    11fe <shellpattern_match+0xbe>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpw   $0x0,-0x1a(%rbp)
jne    11c5 <shellpattern_match+0x85>
mov    -0x28(%rbp),%rdi
call   1040 <strtoupper@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strtoupper@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <fnmatch@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,-0x32(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x32(%rbp),%ax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellpattern_match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     11a8 <shellpattern_match+0x68>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11a8 <shellpattern_match+0x68>
mov    %edx,%r15d
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
test   %r15w,%r15w
jne    1182 <shellpattern_match+0x42>
mov    %r14,%rdi
call   1040 <strtoupper@plt>
mov    %rbx,%rdi
call   1040 <strtoupper@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <fnmatch@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @shellpattern_match(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i16
store i8* %0, i8** %5
store i8* %1, i8** %6
store i16 %2, i16* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i16 0, i16* %10
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %3
store i16 0, i16* %4
br label %41
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %6
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %9
%22 = load i16, i16* %7
%23 = icmp ne i16 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %17
%25 = load i8*, i8** %8
%26 = call i32 @strtoupper(i8* %25)
%27 = load i8*, i8** %9
%28 = call i32 @strtoupper(i8* %27)
br label %29
29: ; preds = %24, %17
%30 = load i8*, i8** %9
%31 = load i8*, i8** %8
%32 = call i64 @fnmatch(i8* %30, i8* %31, i32 0)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = trunc i32 %34 to i16
store i16 %35, i16* %10
%36 = load i8*, i8** %9
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
%40 = load i16, i16* %10
store i16 %40, i16* %4
br label %41
41: ; preds = %29, %16
%42 = load i16, i16* %4
ret i16 %42
}

LLVM IR (-O2):
define signext i16 @shellpattern_match(i8* %0, i8* %1, i16 signext %2) {
%4 = icmp ne i8* %1, null
%5 = icmp ne i8* %0, null
%6 = and i1 %5, %4
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = tail call i8* @strdup(i8* %0)
%9 = tail call i8* @strdup(i8* %1)
%10 = icmp eq i16 %2, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @strtoupper(i8* %8)
%13 = tail call i32 @strtoupper(i8* %9)
br label %14
14: ; preds = %11, %7
%15 = tail call i64 @fnmatch(i8* %9, i8* %8, i32 0)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i16
%18 = tail call i32 @free(i8* %9)
%19 = tail call i32 @free(i8* %8)
br label %20
20: ; preds = %3, %14
%21 = phi i16 [ %17, %14 ], [ 0, %3 ]
ret i16 %21
}