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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
char *substring(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
char *regex(const char *regex, const char *string) {
  regex_t exp;
  if (regcomp(&exp, regex, REG_EXTENDED) != 0)
    return NULL;
  regmatch_t match[1];
  if (regexec(&exp, string, 1, match, 0) != 0)
    return NULL;
  return substring(string, match[0].rm_so, match[0].rm_eo);
}


x86 assembly (clang, -O0):
<regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     116d <regex+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <regex+0x80>
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
cmp    $0x0,%rax
je     119d <regex+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <regex+0x80>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1030 <substring@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regex>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
je     1159 <regex+0x29>
xor    %ebx,%ebx
jmp    118d <regex+0x5d>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
xor    %ebx,%ebx
mov    %r14,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
test   %rax,%rax
jne    118d <regex+0x5d>
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%esi
mov    %r14,%rdi
call   1030 <substring@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
define i8* @regex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1 x %struct.TYPE_3__]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @REG_EXTENDED
%10 = call i64 @regcomp(i32* %6, i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %28
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %7, i64 0, i64 0
%16 = call i64 @regexec(i32* %6, i8* %14, i32 1, %struct.TYPE_3__* %15, i32 0)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i8* null, i8** %3
br label %28
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %7, i64 0, i64 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %7, i64 0, i64 0
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i8* @substring(i8* %20, i32 %23, i32 %26)
store i8* %27, i8** %3
br label %28
28: ; preds = %19, %18, %12
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
define i8* @regex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [1 x %struct.TYPE_3__]
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @REG_EXTENDED
%7 = call i64 @regcomp(i32* %3, i8* %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = bitcast [1 x %struct.TYPE_3__]* %4 to i8*
%11 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %4, i64 0, i64 0
%12 = call i64 @regexec(i32* %3, i8* %1, i32 1, %struct.TYPE_3__* %11, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %4, i64 0, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %4, i64 0, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i8* @substring(i8* %1, i32 %16, i32 %18)
br label %20
20: ; preds = %9, %14
%21 = phi i8* [ %19, %14 ], [ null, %9 ]
br label %22
22: ; preds = %2, %20
%23 = phi i8* [ %21, %20 ], [ null, %2 ]
ret i8* %23
}