#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 */
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_ICASE;
int REG_NEWLINE;
scalar_t__ REG_NOMATCH;
int REG_NOSUB;
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                   int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
bool match_string(const char *haystack, const char *needle) {
  regex_t regex;
  bool ret;
  if (haystack == NULL || needle == NULL) {
    return false;
  }
  if (regcomp(&regex, needle,
              REG_ICASE | REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) {
    return false;
  }
  if (regexec(&regex, haystack, 0, 0, 0) != REG_NOMATCH) {
    ret = true;
  } else {
    ret = false;
  }
  regfree(&regex);
  return ret;
}


x86 assembly (clang, -O0):
<match_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <match_string+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <match_string+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <match_string+0xc1>
mov    -0x18(%rbp),%rsi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
or     (%rax),%edx
mov    0x2e49(%rip),%rax
or     (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11a9 <match_string+0x79>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <match_string+0xc1>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1050 <regexec@plt>
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
je     11db <match_string+0xab>
movl   $0x1,-0x20(%rbp)
jmp    11e2 <match_string+0xb2>
movl   $0x0,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     11a9 <match_string+0x79>
test   %rsi,%rsi
je     11a9 <match_string+0x79>
mov    %rdi,%rbx
mov    0x2e9a(%rip),%rax
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    0x2e77(%rip),%rax
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
jne    11a9 <match_string+0x79>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    0x2e40(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
setne  %bpl
mov    %r14,%rdi
call   1030 <regfree@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@REG_ICASE = global i32 0
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@REG_NOMATCH = global i64 0
define i32 @match_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 0, i32* %3
br label %36
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* @REG_ICASE
%17 = load i32, i32* @REG_EXTENDED
%18 = or i32 %16, %17
%19 = load i32, i32* @REG_NOSUB
%20 = or i32 %18, %19
%21 = load i32, i32* @REG_NEWLINE
%22 = or i32 %20, %21
%23 = call i64 @regcomp(i32* %6, i8* %15, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %14
store i32 0, i32* %3
br label %36
26: ; preds = %14
%27 = load i8*, i8** %4
%28 = call i64 @regexec(i32* %6, i8* %27, i32 0, i32 0, i32 0)
%29 = load i64, i64* @REG_NOMATCH
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %7
br label %33
32: ; preds = %26
store i32 0, i32* %7
br label %33
33: ; preds = %32, %31
%34 = call i32 @regfree(i32* %6)
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %33, %25, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@REG_ICASE = global i32 0
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@REG_NOMATCH = global i64 0
define i32 @match_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = load i32, i32* @REG_ICASE
%10 = load i32, i32* @REG_EXTENDED
%11 = or i32 %10, %9
%12 = load i32, i32* @REG_NOSUB
%13 = or i32 %11, %12
%14 = load i32, i32* @REG_NEWLINE
%15 = or i32 %13, %14
%16 = call i64 @regcomp(i32* %3, i8* %1, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %8
%19 = call i64 @regexec(i32* %3, i8* %0, i32 0, i32 0, i32 0)
%20 = load i64, i64* @REG_NOMATCH
%21 = icmp ne i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @regfree(i32* %3)
br label %24
24: ; preds = %8, %2, %18
%25 = phi i32 [ %22, %18 ], [ 0, %2 ], [ 0, %8 ]
ret i32 %25
}