#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ rm_eo;
  int rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ free(TYPE_1__ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, int);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char *, size_t, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned long long);
char *match(char *string, char *regex) {
  regex_t preg;
  size_t nmatch = (size_t)1;
  regmatch_t *pmatch;
  char *result;
  unsigned long long int resultlength;
  int ret = 0;
  result = 0;
  if (string == 0) {
    return 0;
  }
  if (regex == 0) {
    return 0;
  }
  pmatch = (regmatch_t *)malloc(sizeof(regmatch_t));
  if (pmatch == 0) {
    printf("%s:%d: pmatch memory allocation failed",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/myYearbook/playr/refs/heads/master/src/"
           "match.c",
           52);
    return 0;
  }
  ret = regcomp(&preg, regex, REG_EXTENDED);
  ret = regexec(&preg, string, nmatch, pmatch, 0);
  if (ret != 0) {
    regfree(&preg);
    free(pmatch);
    return 0;
  }
  if (pmatch[0].rm_eo > strlen(string)) {
    regfree(&preg);
    free(pmatch);
    return 0;
  }
  resultlength = (size_t)pmatch[0].rm_eo - (size_t)pmatch[0].rm_so;
  result = (char *)malloc(sizeof(char) * (resultlength + 1));
  if (result == 0) {
    printf("%s:%d: pmatch memory allocation failed",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/myYearbook/playr/refs/heads/master/src/"
           "match.c",
           78);
    free(pmatch);
    return 0;
  }
  strncpy(result, string + pmatch[0].rm_so, resultlength);
  result[resultlength] = (char)0;
  regfree(&preg);
  free(pmatch);
  return result;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x1,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <match+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <match+0x57>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1215 <match+0x95>
lea    0xe09(%rip),%rdi
lea    0xe29(%rip),%rsi
mov    $0x34,%edx
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
mov    -0x18(%rbp),%rsi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1080 <regcomp@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
call   10a0 <regexec@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1272 <match+0xf2>
lea    -0x1c(%rbp),%rdi
call   1050 <regfree@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jle    12b5 <match+0x135>
lea    -0x1c(%rbp),%rdi
call   1050 <regfree@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
movslq 0x8(%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    131b <match+0x19b>
lea    0xd0c(%rip),%rdi
lea    0xd2c(%rip),%rsi
mov    $0x4e,%edx
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    135d <match+0x1dd>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
movslq 0x8(%rax),%rax
add    %rax,%rsi
mov    -0x40(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x1c(%rbp),%rdi
call   1050 <regfree@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r13d,%r13d
test   %rdi,%rdi
je     122c <match+0xac>
mov    %rsi,%rbx
test   %rsi,%rsi
je     122c <match+0xac>
mov    %rdi,%r15
mov    $0x10,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1211 <match+0x91>
mov    %rax,%r14
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <regcomp@plt>
mov    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
xor    %r8d,%r8d
call   10a0 <regexec@plt>
test   %eax,%eax
jne    11fd <match+0x7d>
mov    (%r14),%r12
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    %rax,%r12
jle    123d <match+0xbd>
lea    0xc(%rsp),%rdi
call   1050 <regfree@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1229 <match+0xa9>
lea    0xde8(%rip),%rdi
lea    0xe08(%rip),%rsi
mov    $0x34,%edx
call   1070 <printf@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movslq 0x8(%r14),%rax
sub    %rax,%r12
lea    0x1(%r12),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1285 <match+0x105>
mov    %rax,%r13
movslq 0x8(%r14),%rax
add    %rax,%r15
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strncpy@plt>
movb   $0x0,0x0(%r13,%r12,1)
lea    0xc(%rsp),%rdi
call   1050 <regfree@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    122c <match+0xac>
lea    0xd74(%rip),%rdi
lea    0xd94(%rip),%rsi
mov    $0x4e,%edx
call   1070 <printf@plt>
jmp    1207 <match+0x87>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i32 }
@.str = [39 x i8] c"%s:%d: pmatch memory allocation failed\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/myYearbook/playr/refs/heads/master/src/match.c\00"
@REG_EXTENDED = global i32 0
define i8* @match(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca %struct.TYPE_4__*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 1, i64* %7
store i32 0, i32* %11
store i8* null, i8** %9
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* null, i8** %3
br label %93
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* null, i8** %3
br label %93
19: ; preds = %15
%20 = call i64 @malloc(i32 16)
%21 = inttoptr i64 %20 to %struct.TYPE_4__*
store %struct.TYPE_4__* %21, %struct.TYPE_4__** %8
%22 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%23 = icmp eq %struct.TYPE_4__* %22, null
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 52)
store i8* null, i8** %3
br label %93
26: ; preds = %19
%27 = load i8*, i8** %5
%28 = load i32, i32* @REG_EXTENDED
%29 = call i32 @regcomp(i32* %6, i8* %27, i32 %28)
store i32 %29, i32* %11
%30 = load i8*, i8** %4
%31 = load i64, i64* %7
%32 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%33 = call i32 @regexec(i32* %6, i8* %30, i64 %31, %struct.TYPE_4__* %32, i32 0)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = call i32 @regfree(i32* %6)
%38 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%39 = call i32 @free(%struct.TYPE_4__* %38)
store i8* null, i8** %3
br label %93
40: ; preds = %26
%41 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i64 0
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = load i8*, i8** %4
%46 = call i64 @strlen(i8* %45)
%47 = icmp sgt i64 %44, %46
br i1 %47, label %48, label %52
48: ; preds = %40
%49 = call i32 @regfree(i32* %6)
%50 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%51 = call i32 @free(%struct.TYPE_4__* %50)
store i8* null, i8** %3
br label %93
52: ; preds = %40
%53 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i64 0
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i64, i64* %55
%57 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i64 0
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = sext i32 %60 to i64
%62 = sub i64 %56, %61
store i64 %62, i64* %10
%63 = load i64, i64* %10
%64 = add i64 %63, 1
%65 = mul i64 1, %64
%66 = trunc i64 %65 to i32
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to i8*
store i8* %68, i8** %9
%69 = load i8*, i8** %9
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %75
71: ; preds = %52
%72 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 78)
%73 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%74 = call i32 @free(%struct.TYPE_4__* %73)
store i8* null, i8** %3
br label %93
75: ; preds = %52
%76 = load i8*, i8** %9
%77 = load i8*, i8** %4
%78 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%79 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %78, i64 0
%80 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %79, i32 0, i32 1
%81 = load i32, i32* %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %77, i64 %82
%84 = load i64, i64* %10
%85 = call i32 @strncpy(i8* %76, i8* %83, i64 %84)
%86 = load i8*, i8** %9
%87 = load i64, i64* %10
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8 0, i8* %88
%89 = call i32 @regfree(i32* %6)
%90 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%91 = call i32 @free(%struct.TYPE_4__* %90)
%92 = load i8*, i8** %9
store i8* %92, i8** %3
br label %93
93: ; preds = %75, %71, %48, %36, %24, %18, %14
%94 = load i8*, i8** %3
ret i8* %94
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i32 }
@.str = [39 x i8] c"%s:%d: pmatch memory allocation failed\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/myYearbook/playr/refs/heads/master/src/match.c\00"
@REG_EXTENDED = global i32 0
define i8* @match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %51, label %8
8: ; preds = %2
%9 = tail call i64 @malloc(i32 16)
%10 = inttoptr i64 %9 to %struct.TYPE_4__*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 52)
br label %51
14: ; preds = %8
%15 = load i32, i32* @REG_EXTENDED
%16 = call i32 @regcomp(i32* %3, i8* %1, i32 %15)
%17 = call i32 @regexec(i32* %3, i8* %0, i64 1, %struct.TYPE_4__* %10, i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = call i32 @regfree(i32* %3)
%21 = call i32 @free(%struct.TYPE_4__* %10)
br label %51
22: ; preds = %14
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i64 0, i32 0
%24 = load i64, i64* %23
%25 = call i64 @strlen(i8* %0)
%26 = icmp sgt i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @regfree(i32* %3)
%29 = call i32 @free(%struct.TYPE_4__* %10)
br label %51
30: ; preds = %22
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i64 0, i32 1
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = sub i64 %24, %33
%35 = trunc i64 %34 to i32
%36 = add i32 %35, 1
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
%39 = icmp eq i64 %37, 0
br i1 %39, label %40, label %43
40: ; preds = %30
%41 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 78)
%42 = call i32 @free(%struct.TYPE_4__* %10)
br label %51
43: ; preds = %30
%44 = load i32, i32* %31
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = call i32 @strncpy(i8* %38, i8* %46, i64 %34)
%48 = getelementptr inbounds i8, i8* %38, i64 %34
store i8 0, i8* %48
%49 = call i32 @regfree(i32* %3)
%50 = call i32 @free(%struct.TYPE_4__* %10)
br label %51
51: ; preds = %2, %43, %40, %27, %19, %12
%52 = phi i8* [ null, %12 ], [ null, %19 ], [ null, %27 ], [ null, %40 ], [ %38, %43 ], [ null, %2 ]
ret i8* %52
}