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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
char *malloc(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*/ *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int match_ext(const char *string, const char *pattern, char *result[],
              size_t len) {
  int r;
  regex_t expr;
  regmatch_t rm[len];
  result[0] = 0;
  int pos = 0;
  if ((r = regcomp(&expr, pattern, REG_EXTENDED)) != 0)
    return 0;
  if ((r = regexec(&expr, string, len, rm, 0)) != 0) {
    regfree(&expr);
    return 0;
  }
  for (pos = 0; pos < len; pos++) {
    if (rm[pos].rm_so < 0) {
      result[pos] = malloc(1);
      result[pos][0] = 0;
      continue;
    }
    if (rm[pos].rm_so >= 0) {
      result[pos] = malloc(rm[pos].rm_eo - rm[pos].rm_so + 1);
      strncpy(result[pos], &string[rm[pos].rm_so],
              rm[pos].rm_eo - rm[pos].rm_so + 1);
      result[pos][rm[pos].rm_eo - rm[pos].rm_so] = 0;
    }
  }
  regfree(&expr);
  return 1;
}


x86 assembly (clang, -O0):
<match_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     11d7 <match_ext+0x87>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    132d <match_ext+0x1dd>
mov    -0x50(%rbp),%rcx
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
xor    %r8d,%r8d
call   1070 <regexec@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     1217 <match_ext+0xc7>
lea    -0x30(%rbp),%rdi
call   1040 <regfree@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    132d <match_ext+0x1dd>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1316 <match_ext+0x1c6>
mov    -0x50(%rbp),%rax
movslq -0x44(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,8)
jge    126b <match_ext+0x11b>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,(%rax)
jmp    1308 <match_ext+0x1b8>
mov    -0x50(%rbp),%rax
movslq -0x44(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,8)
jl     1303 <match_ext+0x1b3>
mov    -0x50(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
movslq -0x44(%rbp),%rcx
sub    (%rax,%rcx,8),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rsi
mov    -0x50(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x44(%rbp),%rdx
mov    %rsi,(%rcx,%rdx,8)
mov    -0x20(%rbp),%rcx
movslq -0x44(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x44(%rbp),%rcx
movslq (%rax,%rcx,8),%rcx
add    %rcx,%rsi
movslq -0x44(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edx
movslq -0x44(%rbp),%rcx
sub    (%rax,%rcx,8),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x44(%rbp),%rcx
mov    0x4(%rdx,%rcx,8),%ecx
movslq -0x44(%rbp),%rsi
sub    (%rdx,%rsi,8),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1308 <match_ext+0x1b8>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    121e <match_ext+0xce>
lea    -0x30(%rbp),%rdi
call   1040 <regfree@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_ext>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rdi,-0x38(%rbp)
mov    %rsp,%r14
mov    %rsp,%r15
lea    0xf(,%rcx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
movq   $0x0,(%rdx)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rdi
call   1050 <regcomp@plt>
xor    %r13d,%r13d
test   %eax,%eax
jne    1267 <match_ext+0x117>
lea    -0x2c(%rbp),%rdi
xor    %r13d,%r13d
mov    -0x38(%rbp),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
jne    125e <match_ext+0x10e>
test   %rbx,%rbx
je     1258 <match_ext+0x108>
mov    %r14,-0x40(%rbp)
xor    %r14d,%r14d
mov    %rbx,-0x48(%rbp)
jmp    1233 <match_ext+0xe3>
xchg   %ax,%ax
lea    (%r14,%r14,1),%rax
mov    %rax,-0x50(%rbp)
mov    0x4(%r15,%r14,8),%ebx
sub    %r13d,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12,%r14,8)
add    -0x38(%rbp),%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq 0x4(%r15,%r14,8),%rax
mov    -0x50(%rbp),%rcx
movslq (%r15,%rcx,4),%rcx
mov    -0x48(%rbp),%rbx
sub    %rcx,%rax
add    (%r12,%r14,8),%rax
movb   $0x0,(%rax)
add    $0x1,%r14
cmp    %r14,%rbx
je     124c <match_ext+0xfc>
mov    (%r15,%r14,8),%r13d
test   %r13d,%r13d
jns    11e0 <match_ext+0x90>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12,%r14,8)
jmp    1227 <match_ext+0xd7>
mov    $0x1,%r13d
mov    -0x40(%rbp),%r14
jmp    125e <match_ext+0x10e>
mov    $0x1,%r13d
lea    -0x2c(%rbp),%rdi
call   1040 <regfree@plt>
mov    %r14,%rsp
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
define i32 @match_ext(i8* %0, i8* %1, i8** %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i64 %3, i64* %9
%16 = load i64, i64* %9
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %12
%18 = alloca %struct.TYPE_3__, i64 %16
store i64 %16, i64* %13
%19 = load i8**, i8*** %8
%20 = getelementptr inbounds i8*, i8** %19, i64 0
store i8* null, i8** %20
store i32 0, i32* %14
%21 = load i8*, i8** %7
%22 = load i32, i32* @REG_EXTENDED
%23 = call i32 @regcomp(i32* %11, i8* %21, i32 %22)
store i32 %23, i32* %10
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 0, i32* %5
store i32 1, i32* %15
br label %133
26: ; preds = %4
%27 = load i8*, i8** %6
%28 = load i64, i64* %9
%29 = call i32 @regexec(i32* %11, i8* %27, i64 %28, %struct.TYPE_3__* %18, i32 0)
store i32 %29, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @regfree(i32* %11)
store i32 0, i32* %5
store i32 1, i32* %15
br label %133
33: ; preds = %26
store i32 0, i32* %14
br label %34
34: ; preds = %128, %33
%35 = load i32, i32* %14
%36 = sext i32 %35 to i64
%37 = load i64, i64* %9
%38 = icmp ult i64 %36, %37
br i1 %38, label %39, label %131
39: ; preds = %34
%40 = load i32, i32* %14
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %41
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %58
46: ; preds = %39
%47 = call i8* @malloc(i32 1)
%48 = load i8**, i8*** %8
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
%52 = load i8**, i8*** %8
%53 = load i32, i32* %14
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = getelementptr inbounds i8, i8* %56, i64 0
store i8 0, i8* %57
br label %128
58: ; preds = %39
%59 = load i32, i32* %14
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %60
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = icmp sge i32 %63, 0
br i1 %64, label %65, label %127
65: ; preds = %58
%66 = load i32, i32* %14
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %67
%69 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %72
%74 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = sub nsw i32 %70, %75
%77 = add nsw i32 %76, 1
%78 = call i8* @malloc(i32 %77)
%79 = load i8**, i8*** %8
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
store i8* %78, i8** %82
%83 = load i8**, i8*** %8
%84 = load i32, i32* %14
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = load i8*, i8** %6
%89 = load i32, i32* %14
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %90
%92 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %91, i32 0, i32 0
%93 = load i32, i32* %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %88, i64 %94
%96 = load i32, i32* %14
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %97
%99 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %98, i32 0, i32 1
%100 = load i32, i32* %99
%101 = load i32, i32* %14
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %102
%104 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = sub nsw i32 %100, %105
%107 = add nsw i32 %106, 1
%108 = call i32 @strncpy(i8* %87, i8* %95, i32 %107)
%109 = load i8**, i8*** %8
%110 = load i32, i32* %14
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8*, i8** %109, i64 %111
%113 = load i8*, i8** %112
%114 = load i32, i32* %14
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %115
%117 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %116, i32 0, i32 1
%118 = load i32, i32* %117
%119 = load i32, i32* %14
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %120
%122 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %121, i32 0, i32 0
%123 = load i32, i32* %122
%124 = sub nsw i32 %118, %123
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i8, i8* %113, i64 %125
store i8 0, i8* %126
br label %127
127: ; preds = %65, %58
br label %128
128: ; preds = %127, %46
%129 = load i32, i32* %14
%130 = add nsw i32 %129, 1
store i32 %130, i32* %14
br label %34
131: ; preds = %34
%132 = call i32 @regfree(i32* %11)
store i32 1, i32* %5
store i32 1, i32* %15
br label %133
133: ; preds = %131, %31, %25
%134 = load i8*, i8** %12
%135 = load i32, i32* %5
ret i32 %135
}

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