#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int rm_eo;
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char const *, size_t, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *matchre(const char *strdata, const char *pattern) {
  regex_t preg;
  int rc;
  size_t nmatch = 10;
  regmatch_t pmatch[10];
  char *ret_val = NULL;
  if (strlen(strdata) == 0 || strlen(pattern) == 0)
    return NULL;
  if ((rc = regcomp(&preg, pattern, REG_EXTENDED)) != 0) {
    return NULL;
  }
  if ((rc = regexec(&preg, strdata, nmatch, pmatch, 0)) != 0) {
    regfree(&preg);
    return NULL;
  }
  int len = (pmatch[0].rm_eo - pmatch[0].rm_so);
  ret_val = malloc(len + 1);
  memset(ret_val, 0, len + 1);
  strncpy(ret_val, strdata + pmatch[0].rm_so, len);
  regfree(&preg);
  return ret_val;
}


x86 assembly (clang, -O0):
<matchre>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0xa,-0x28(%rbp)
movq   $0x0,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     11bc <matchre+0x4c>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    11c9 <matchre+0x59>
movq   $0x0,-0x8(%rbp)
jmp    129b <matchre+0x12b>
mov    -0x18(%rbp),%rsi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1070 <regcomp@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     11f8 <matchre+0x88>
movq   $0x0,-0x8(%rbp)
jmp    129b <matchre+0x12b>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
call   1090 <regexec@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1232 <matchre+0xc2>
lea    -0x1c(%rbp),%rdi
call   1040 <regfree@plt>
movq   $0x0,-0x8(%rbp)
jmp    129b <matchre+0x12b>
mov    -0x80(%rbp),%eax
sub    -0x7c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x8c(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x88(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x7c(%rbp),%rax
add    %rax,%rsi
mov    -0x8c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x88(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchre>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmpb   $0x0,(%rdi)
je     118e <matchre+0x2e>
cmpb   $0x0,(%rsi)
je     118e <matchre+0x2e>
mov    %rdi,%rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1060 <regcomp@plt>
test   %eax,%eax
je     119f <matchre+0x3f>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
xor    %r14d,%r14d
mov    $0xa,%edx
mov    %rbx,%rsi
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
jne    11fa <matchre+0x9a>
mov    0x10(%rsp),%r15d
sub    0x14(%rsp),%r15d
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
movslq 0x14(%rsp),%rax
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
jmp    1191 <matchre+0x31>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
define i8* @matchre(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [10 x %struct.TYPE_3__]
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 10, i64* %8
store i8* null, i8** %10
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15, %2
store i8* null, i8** %3
br label %60
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i32, i32* @REG_EXTENDED
%23 = call i32 @regcomp(i32* %6, i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i8* null, i8** %3
br label %60
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = load i64, i64* %8
%29 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %9, i64 0, i64 0
%30 = call i32 @regexec(i32* %6, i8* %27, i64 %28, %struct.TYPE_3__* %29, i32 0)
store i32 %30, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @regfree(i32* %6)
store i8* null, i8** %3
br label %60
34: ; preds = %26
%35 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %9, i64 0, i64 0
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %9, i64 0, i64 0
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = sub nsw i32 %37, %40
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
%48 = call i32 @memset(i8* %45, i32 0, i32 %47)
%49 = load i8*, i8** %10
%50 = load i8*, i8** %4
%51 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %9, i64 0, i64 0
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %51, i32 0, i32 1
%53 = load i32, i32* %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = load i32, i32* %11
%57 = call i32 @strncpy(i8* %49, i8* %55, i32 %56)
%58 = call i32 @regfree(i32* %6)
%59 = load i8*, i8** %10
store i8* %59, i8** %3
br label %60
60: ; preds = %34, %32, %25, %19
%61 = load i8*, i8** %3
ret i8* %61
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
define i8* @matchre(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [10 x %struct.TYPE_3__]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [10 x %struct.TYPE_3__]* %4 to i8*
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %2
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %36, label %12
12: ; preds = %9
%13 = load i32, i32* @REG_EXTENDED
%14 = call i32 @regcomp(i32* %3, i8* %1, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %4, i64 0, i64 0
%18 = call i32 @regexec(i32* %3, i8* %0, i64 10, %struct.TYPE_3__* %17, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %4, i64 0, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds [10 x %struct.TYPE_3__], [10 x %struct.TYPE_3__]* %4, i64 0, i64 0, i32 1
%24 = load i32, i32* %23
%25 = sub nsw i32 %22, %24
%26 = add nsw i32 %25, 1
%27 = call i8* @malloc(i32 %26)
%28 = call i32 @memset(i8* %27, i32 0, i32 %26)
%29 = load i32, i32* %23
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = call i32 @strncpy(i8* %27, i8* %31, i32 %25)
br label %33
33: ; preds = %16, %20
%34 = phi i8* [ %27, %20 ], [ null, %16 ]
%35 = call i32 @regfree(i32* %3)
br label %36
36: ; preds = %33, %12, %2, %9
%37 = phi i8* [ null, %9 ], [ null, %2 ], [ null, %12 ], [ %34, %33 ]
ret i8* %37
}