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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int match_ext2(const char *string, const char *pattern, int pos, char *result,
               size_t len) {
  int r;
  regex_t expr;
  regmatch_t rm[100];
  result[0] = 0;
  if ((r = regcomp(&expr, pattern, REG_EXTENDED)) != 0)
    return 0;
  if ((r = regexec(&expr, string, 100, rm, 0)) != 0) {
    regfree(&expr);
    return 0;
  }
  if (pos < 100 && rm[pos].rm_so >= 0 && rm[pos].rm_eo - rm[pos].rm_so < len) {
    strncpy(result, &string[rm[pos].rm_so], len);
    result[rm[pos].rm_eo - rm[pos].rm_so] = 0;
  }
  regfree(&expr);
  return 1;
}


x86 assembly (clang, -O0):
<match_ext2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rsi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     1193 <match_ext2+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1294 <match_ext2+0x154>
mov    -0x10(%rbp),%rsi
lea    -0x680(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x64,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     11d0 <match_ext2+0x90>
lea    -0x38(%rbp),%rdi
call   1040 <regfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <match_ext2+0x154>
cmpl   $0x64,-0x1c(%rbp)
jge    1284 <match_ext2+0x144>
movslq -0x1c(%rbp),%rcx
lea    -0x680(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
jb     1284 <match_ext2+0x144>
movslq -0x1c(%rbp),%rcx
lea    -0x680(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rdx
lea    -0x680(%rbp),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
sub    (%rcx),%rax
cmp    -0x30(%rbp),%rax
jae    1284 <match_ext2+0x144>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rcx
lea    -0x680(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
add    (%rax),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rdx
lea    -0x680(%rbp),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
mov    0x8(%rcx),%rcx
movslq -0x1c(%rbp),%rsi
lea    -0x680(%rbp),%rdx
shl    $0x4,%rsi
add    %rsi,%rdx
sub    (%rdx),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x38(%rbp),%rdi
call   1040 <regfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_ext2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x650,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %rdi,%r15
movb   $0x0,(%rcx)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11eb <match_ext2+0xab>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
xor    %ebp,%ebp
mov    %r15,%rsi
mov    $0x64,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
jne    11e1 <match_ext2+0xa1>
mov    $0x1,%ebp
cmp    $0x63,%r12d
jg     11e1 <match_ext2+0xa1>
movslq %r12d,%rax
shl    $0x4,%rax
mov    0x10(%rsp,%rax,1),%rcx
mov    0x18(%rsp,%rax,1),%rdx
sub    %rcx,%rdx
cmp    %r14,%rdx
jae    11e1 <match_ext2+0xa1>
lea    (%rsp,%rax,1),%r12
add    $0x10,%r12
add    %rcx,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
mov    0x8(%r12),%rax
sub    (%r12),%rax
movb   $0x0,(%rbx,%rax,1)
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
mov    %ebp,%eax
add    $0x650,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@REG_EXTENDED = global i32 0
define i32 @match_ext2(i8* %0, i8* %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca [100 x %struct.TYPE_3__]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%15 = load i8*, i8** %10
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 0, i8* %16
%17 = load i8*, i8** %8
%18 = load i32, i32* @REG_EXTENDED
%19 = call i32 @regcomp(i32* %13, i8* %17, i32 %18)
store i32 %19, i32* %12
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %5
store i32 0, i32* %6
br label %79
22: ; preds = %5
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 0
%25 = call i32 @regexec(i32* %13, i8* %23, i32 100, %struct.TYPE_3__* %24, i32 0)
store i32 %25, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @regfree(i32* %13)
store i32 0, i32* %6
br label %79
29: ; preds = %22
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 100
br i1 %31, label %32, label %77
32: ; preds = %29
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %34
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = icmp uge i64 %37, 0
br i1 %38, label %39, label %77
39: ; preds = %32
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %41
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 1
%44 = load i64, i64* %43
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %46
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = sub i64 %44, %49
%51 = load i64, i64* %11
%52 = icmp ult i64 %50, %51
br i1 %52, label %53, label %77
53: ; preds = %39
%54 = load i8*, i8** %10
%55 = load i8*, i8** %7
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %57
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 0
%60 = load i64, i64* %59
%61 = getelementptr inbounds i8, i8* %55, i64 %60
%62 = load i64, i64* %11
%63 = call i32 @strncpy(i8* %54, i8* %61, i64 %62)
%64 = load i8*, i8** %10
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %66
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 1
%69 = load i64, i64* %68
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %14, i64 0, i64 %71
%73 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = sub i64 %69, %74
%76 = getelementptr inbounds i8, i8* %64, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %53, %39, %32, %29
%78 = call i32 @regfree(i32* %13)
store i32 1, i32* %6
br label %79
79: ; preds = %77, %27, %21
%80 = load i32, i32* %6
ret i32 %80
}

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