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

/* Variables and functions */
int REG_EXTENDED;
int REG_ICASE;
int /*<<< orphan*/ *calloc(int, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
char *rdz_strdup(char *);
char *rdz_string_expected(char *, char *, char *);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
scalar_t__ strchr(char *, char);
char *rdz_string_match(char *operator, char * result, char *expected) {
  if (result == NULL)
    return rdz_strdup("     result is NULL");
  char *s = NULL;
  int flags = REG_EXTENDED;
  if (strchr(operator, 'i'))
    flags = flags | REG_ICASE;
  regex_t *r = calloc(1, sizeof(regex_t));
  regcomp(r, expected, flags);
  regmatch_t ms[1];
  if (regexec(r, result, 0, ms, 0)) {
    if (operator[0] != '!')
      s = rdz_string_expected(result, "to match", expected);
  } else {
    if (operator[0] == '!')
      s = rdz_string_expected(result, "not to match", expected);
  }
  regfree(r);
  free(r);
  return s;
}


x86 assembly (clang, -O0):
<rdz_string_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <rdz_string_match+0x34>
lea    0xe5a(%rip),%rdi
call   10a0 <rdz_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    12a7 <rdz_string_match+0x127>
movq   $0x0,-0x28(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x69,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11ef <rdz_string_match+0x6f>
mov    -0x2c(%rbp),%eax
mov    0x2dfe(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <regcomp@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x3c(%rbp),%rcx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1090 <regexec@plt>
cmp    $0x0,%rax
je     1260 <rdz_string_match+0xe0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
je     125b <rdz_string_match+0xdb>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc6(%rip),%rsi
call   1080 <rdz_string_expected@plt>
mov    %rax,-0x28(%rbp)
jmp    128d <rdz_string_match+0x10d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
jne    1288 <rdz_string_match+0x108>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   1080 <rdz_string_expected@plt>
mov    %rax,-0x28(%rbp)
jmp    128d <rdz_string_match+0x10d>
mov    -0x38(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdz_string_match>:
test   %rsi,%rsi
je     120e <rdz_string_match+0x8e>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e33(%rip),%rax
mov    (%rax),%ebx
mov    $0x69,%esi
call   1050 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11c1 <rdz_string_match+0x41>
mov    0x2e29(%rip),%rax
mov    (%rax),%ebp
or     %ebx,%ebp
mov    $0x1,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <regcomp@plt>
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1090 <regexec@plt>
mov    (%r12),%cl
test   %rax,%rax
je     121a <rdz_string_match+0x9a>
cmp    $0x21,%cl
je     1236 <rdz_string_match+0xb6>
lea    0xe0c(%rip),%rsi
jmp    1226 <rdz_string_match+0xa6>
lea    0xdeb(%rip),%rdi
jmp    10a0 <rdz_strdup@plt>
cmp    $0x21,%cl
jne    1236 <rdz_string_match+0xb6>
lea    0xdee(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <rdz_string_expected@plt>
mov    %rax,%rbp
jmp    1238 <rdz_string_match+0xb8>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <regfree@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c" result is NULL\00"
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@.str.1 = [9 x i8] c"to match\00"
@.str.2 = [13 x i8] c"not to match\00"
define i8* @rdz_string_match(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [1 x i32]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i8* @rdz_strdup(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %4
br label %64
16: ; preds = %3
store i8* null, i8** %8
%17 = load i32, i32* @REG_EXTENDED
store i32 %17, i32* %9
%18 = load i8*, i8** %5
%19 = call i64 @strchr(i8* %18, i8 signext 105)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* %9
%23 = load i32, i32* @REG_ICASE
%24 = or i32 %22, %23
store i32 %24, i32* %9
br label %25
25: ; preds = %21, %16
%26 = call i32* @calloc(i32 1, i32 4)
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = call i32 @regcomp(i32* %27, i8* %28, i32 %29)
%31 = load i32*, i32** %10
%32 = load i8*, i8** %6
%33 = getelementptr inbounds [1 x i32], [1 x i32]* %11, i64 0, i64 0
%34 = call i64 @regexec(i32* %31, i8* %32, i32 0, i32* %33, i32 0)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %25
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 33
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = call i8* @rdz_string_expected(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %44)
store i8* %45, i8** %8
br label %46
46: ; preds = %42, %36
br label %58
47: ; preds = %25
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 33
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i8*, i8** %6
%55 = load i8*, i8** %7
%56 = call i8* @rdz_string_expected(i8* %54, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %55)
store i8* %56, i8** %8
br label %57
57: ; preds = %53, %47
br label %58
58: ; preds = %57, %46
%59 = load i32*, i32** %10
%60 = call i32 @regfree(i32* %59)
%61 = load i32*, i32** %10
%62 = call i32 @free(i32* %61)
%63 = load i8*, i8** %8
store i8* %63, i8** %4
br label %64
64: ; preds = %58, %14
%65 = load i8*, i8** %4
ret i8* %65
}

LLVM IR (-O2):
@.str = [20 x i8] c" result is NULL\00"
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@.str.1 = [9 x i8] c"to match\00"
@.str.2 = [13 x i8] c"not to match\00"
define i8* @rdz_string_match(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1 x i32]
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @rdz_strdup(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %32
8: ; preds = %3
%9 = load i32, i32* @REG_EXTENDED
%10 = tail call i64 @strchr(i8* %0, i8 signext 105)
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* @REG_ICASE
%13 = select i1 %11, i32 0, i32 %12
%14 = or i32 %13, %9
%15 = tail call i32* @calloc(i32 1, i32 4)
%16 = tail call i32 @regcomp(i32* %15, i8* %2, i32 %14)
%17 = bitcast [1 x i32]* %4 to i8*
%18 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%19 = call i64 @regexec(i32* %15, i8* %1, i32 0, i32* %18, i32 0)
%20 = icmp eq i64 %19, 0
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 33
br i1 %20, label %24, label %23
23: ; preds = %8
br i1 %22, label %28, label %25
24: ; preds = %8
br i1 %22, label %25, label %28
25: ; preds = %24, %23
%26 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %23 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %24 ]
%27 = call i8* @rdz_string_expected(i8* %1, i8* %26, i8* %2)
br label %28
28: ; preds = %25, %24, %23
%29 = phi i8* [ null, %23 ], [ null, %24 ], [ %27, %25 ]
%30 = call i32 @regfree(i32* %15)
%31 = call i32 @free(i32* %15)
br label %32
32: ; preds = %28, %6
%33 = phi i8* [ %7, %6 ], [ %29, %28 ]
ret i8* %33
}