#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;
char *malloc(int);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
char *regexp(char *string, char *patrn, int *begin, int *end) {
  int i, w = 0, len;
  char *word = NULL;
  regex_t rgT;
  regmatch_t match;
  regcomp(&rgT, patrn, REG_EXTENDED);
  if ((regexec(&rgT, string, 1, &match, 0)) == 0) {
    *begin = (int)match.rm_so;
    *end = (int)match.rm_eo;
    len = *end - *begin;
    word = malloc(len + 1);
    for (i = *begin; i < *end; i++) {
      word[w] = string[i];
      w++;
    }
    word[w] = 0;
  }
  regfree(&rgT);
  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,-0x28(%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,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    121b <regexp+0xdb>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11df <regexp+0x9f>
mov    -0x38(%rbp),%rax
movslq -0x28(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rdi,%r14
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <regcomp@plt>
lea    0x8(%rsp),%rcx
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %rax,%rax
jne    11e8 <regexp+0x98>
mov    0x10(%rsp),%eax
mov    %eax,0x0(%r13)
mov    0x8(%rsp),%ebp
mov    %ebp,(%r12)
movslq 0x0(%r13),%rbx
mov    %ebp,%edi
sub    %ebx,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
cmp    %ebx,%ebp
jle    11e1 <regexp+0x91>
add    %rbx,%r14
not    %ebx
add    %ebp,%ebx
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %ebx,%eax
jmp    11e3 <regexp+0x93>
xor    %eax,%eax
movb   $0x0,(%r15,%rax,1)
lea    0x4(%rsp),%rdi
call   1030 <regfree@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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* %10
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 %65
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* %11
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
%37 = call i8* @malloc(i32 %36)
store i8* %37, i8** %12
%38 = load i32*, i32** %7
%39 = load i32, i32* %38
store i32 %39, i32* %9
br label %40
40: ; preds = %57, %21
%41 = load i32, i32* %9
%42 = load i32*, i32** %8
%43 = load i32, i32* %42
%44 = icmp slt i32 %41, %43
br i1 %44, label %45, label %60
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %12
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %57
57: ; preds = %45
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %40
60: ; preds = %40
%61 = load i8*, i8** %12
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 0, i8* %64
br label %65
65: ; preds = %60, %4
%66 = call i32 @regfree(i32* %13)
%67 = load i8*, i8** %12
ret i8* %67
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@REG_EXTENDED = global i32 0
define noalias 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 %36
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 i8* @malloc(i32 %22)
%24 = icmp slt i32 %20, %19
br i1 %24, label %25, label %33
25: ; preds = %13
%26 = sext i32 %20 to i64
%27 = getelementptr i8, i8* %0, i64 %26
%28 = xor i32 %20, -1
%29 = add i32 %28, %19
%30 = zext i32 %29 to i64
%31 = add nuw nsw i64 %30, 1
%32 = and i64 %31, 4294967295
br label %33
33: ; preds = %25, %13
%34 = phi i64 [ 0, %13 ], [ %32, %25 ]
%35 = getelementptr inbounds i8, i8* %23, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %33, %4
%37 = phi i8* [ %23, %33 ], [ null, %4 ]
%38 = call i32 @regfree(i32* %5)
ret i8* %37
}