#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__ {
  scalar_t__ rm_eo;
  scalar_t__ rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
scalar_t__ malloc(int);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char const *,
                           int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
char *regexp(const char *string, const char *patrn, int *begin, int *end) {
  int len;
  int i;
  int wcnt = 0;
  char *word = NULL;
  regex_t rgxt;
  regmatch_t match;
  regcomp(&rgxt, patrn, REG_EXTENDED);
  if ((regexec(&rgxt, string, 1, &match, 0)) == 0) {
    *begin = (int)match.rm_so;
    *end = (int)match.rm_eo;
    len = *end - *begin;
    word = (char *)malloc(len + 1);
    for (i = *begin; i < *end; i++) {
      word[wcnt] = string[i];
      wcnt++;
    }
    word[wcnt] = 0x00;
  }
  regfree(&rgxt);
  return word;
}


x86 assembly (clang, -O0):
<regexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rdi
call   1040 <regcomp@plt>
mov    -0x8(%rbp),%rsi
lea    -0x3c(%rbp),%rdi
mov    $0x1,%edx
lea    -0x50(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
cmp    $0x0,%rax
jne    1227 <regexp+0xe7>
mov    -0x48(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    121b <regexp+0xdb>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11df <regexp+0x9f>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x3c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regexp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rdi,%r15
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r13
mov    %r13,%rdi
call   1040 <regcomp@plt>
lea    0x10(%rsp),%rcx
xor    %ebx,%ebx
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %rax,%rax
jne    11e4 <regexp+0xa4>
mov    0x18(%rsp),%eax
mov    %eax,(%r12)
mov    0x10(%rsp),%edi
mov    %edi,(%r14)
sub    (%r12),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movslq (%r12),%rax
cmp    (%r14),%eax
jge    11de <regexp+0x9e>
add    %rax,%r15
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rcx,1),%edx
mov    %dl,(%rbx,%rcx,1)
movslq (%r14),%rdx
lea    (%rax,%rcx,1),%rsi
add    $0x1,%rsi
add    $0x1,%rcx
cmp    %rdx,%rsi
jl     11c0 <regexp+0x80>
jmp    11e0 <regexp+0xa0>
xor    %ecx,%ecx
movb   $0x0,(%rbx,%rcx,1)
lea    0xc(%rsp),%rdi
call   1030 <regfree@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@REG_EXTENDED = global i32 0
define i8* @regexp(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
%7 = bitcast i32* %5 to i8*
%8 = bitcast %struct.TYPE_3__* %6 to i8*
%9 = load i32, i32* @REG_EXTENDED
%10 = call i32 @regcomp(i32* %5, i8* %1, i32 %9)
%11 = call i64 @regexec(i32* %5, i8* %0, i32 1, %struct.TYPE_3__* %6, i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %46
13: ; preds = %4
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i64 0, i32 1
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %2
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i64 0, i32 0
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = add i32 %19, 1
%22 = sub i32 %21, %20
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %43
28: ; preds = %13
%29 = sext i32 %25 to i64
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ %29, %28 ], [ %37, %30 ]
%32 = phi i64 [ 0, %28 ], [ %36, %30 ]
%33 = getelementptr inbounds i8, i8* %0, i64 %31
%34 = load i8, i8* %33
%35 = getelementptr inbounds i8, i8* %24, i64 %32
store i8 %34, i8* %35
%36 = add nuw nsw i64 %32, 1
%37 = add nsw i64 %31, 1
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %30, label %41
41: ; preds = %30
%42 = and i64 %36, 4294967295
br label %43
43: ; preds = %41, %13
%44 = phi i64 [ 0, %13 ], [ %42, %41 ]
%45 = getelementptr inbounds i8, i8* %24, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %43, %4
%47 = phi i8* [ %24, %43 ], [ null, %4 ]
%48 = call i32 @regfree(i32* %5)
ret i8* %47
}