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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, size_t, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main() {
  char *source = "sanduicheiche";
  char *regexString = "([a-z]+)\\1$";
  size_t maxMatches = 1;
  size_t maxGroups = 1;
  regex_t regexCompiled;
  regmatch_t groupArray[maxGroups];
  unsigned int m;
  char *cursor;
  if (regcomp(&regexCompiled, regexString, REG_EXTENDED)) {
    printf("Could not compile regular expression.\n");
    return 1;
  };
  m = 0;
  cursor = source;
  for (m = 0; m < maxMatches; m++) {
    if (regexec(&regexCompiled, cursor, maxGroups, groupArray, 0))
      break;
    unsigned int g = 0;
    unsigned int offset = 0;
    for (g = 0; g < maxGroups; g++) {
      if (groupArray[g].rm_so == (size_t)-1)
        break;
      if (g == 0)
        offset = groupArray[g].rm_eo;
      char cursorCopy[strlen(cursor) + 1];
      strcpy(cursorCopy, cursor);
      cursorCopy[groupArray[g].rm_eo] = 0;
      printf("Match %u, Group %u: [%2u-%2u]: %s\n", m, g, groupArray[g].rm_so,
             groupArray[g].rm_eo, cursorCopy + groupArray[g].rm_so);
    }
    cursor += offset;
  }
  regfree(&regexCompiled);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
shl    $0x4,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rdi
call   1070 <regcomp@plt>
cmp    $0x0,%rax
je     11fc <main+0x9c>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    138b <main+0x22b>
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    1374 <main+0x214>
mov    -0x78(%rbp),%rcx
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rdi
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    $0x0,%rax
je     1246 <main+0xe6>
jmp    1374 <main+0x214>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x28(%rbp),%rax
jae    1356 <main+0x1f6>
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%ecx
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0xffffffffffffffff,(%rax)
jne    1285 <main+0x125>
jmp    1356 <main+0x1f6>
cmpl   $0x0,-0x58(%rbp)
jne    12a3 <main+0x143>
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%ecx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x50(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x80(%rbp),%r9
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %ecx,%edx
shl    $0x4,%rdx
mov    %rax,%rcx
add    %rdx,%rcx
mov    0x8(%rcx),%ecx
movb   $0x0,(%r9,%rcx,1)
mov    -0x44(%rbp),%esi
mov    -0x58(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    %ecx,%edi
shl    $0x4,%rdi
mov    %rax,%rcx
add    %rdi,%rcx
mov    (%rcx),%rcx
mov    -0x58(%rbp),%edi
mov    %edi,%r8d
shl    $0x4,%r8
mov    %rax,%rdi
add    %r8,%rdi
mov    0x8(%rdi),%r8d
mov    -0x58(%rbp),%edi
shl    $0x4,%rdi
add    %rdi,%rax
add    (%rax),%r9
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    125b <main+0xfb>
mov    -0x5c(%rbp),%ecx
mov    -0x50(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1212 <main+0xb2>
lea    -0x2c(%rbp),%rdi
call   1040 <regfree@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r12
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    0xe7a(%rip),%rsi
lea    -0x2c(%rbp),%rdi
call   1080 <regcomp@plt>
test   %rax,%rax
je     11b9 <main+0x49>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
jmp    1246 <main+0xd6>
lea    0xe40(%rip),%rsi
lea    -0x2c(%rbp),%rdi
lea    -0x40(%rbp),%rcx
xor    %r15d,%r15d
mov    $0x1,%edx
xor    %r8d,%r8d
call   1090 <regexec@plt>
test   %rax,%rax
jne    123d <main+0xcd>
cmpq   $0xffffffffffffffff,-0x40(%rbp)
je     123d <main+0xcd>
lea    0xe15(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rsp,%r13
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%r8d
movb   $0x0,(%r8,%rbx,1)
mov    -0x40(%rbp),%rcx
add    %rcx,%rbx
lea    0xdee(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%r9
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rsp
lea    -0x2c(%rbp),%rdi
call   1050 <regfree@plt>
mov    %r12,%rsp
mov    %r15d,%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 { i64, i32 }
@.str = [14 x i8] c"sanduicheiche\00"
@.str.1 = [12 x i8] c"([a-z]+)\\1$\00"
@REG_EXTENDED = global i32 0
@.str.2 = [39 x i8] c"Could not compile regular expression.\0A\00"
@.str.3 = [35 x i8] c"Match %u, Group %u: [%2u-%2u]: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i64 1, i64* %4
store i64 1, i64* %5
%16 = load i64, i64* %5
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %7
%18 = alloca %struct.TYPE_3__, i64 %16
store i64 %16, i64* %8
%19 = load i8*, i8** %3
%20 = load i32, i32* @REG_EXTENDED
%21 = call i64 @regcomp(i32* %6, i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %11
br label %110
25: ; preds = %0
store i32 0, i32* %9
%26 = load i8*, i8** %2
store i8* %26, i8** %10
store i32 0, i32* %9
br label %27
27: ; preds = %105, %25
%28 = load i32, i32* %9
%29 = zext i32 %28 to i64
%30 = load i64, i64* %4
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %108
32: ; preds = %27
%33 = load i8*, i8** %10
%34 = load i64, i64* %5
%35 = call i64 @regexec(i32* %6, i8* %33, i64 %34, %struct.TYPE_3__* %18, i32 0)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
br label %108
38: ; preds = %32
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %12
br label %39
39: ; preds = %97, %38
%40 = load i32, i32* %12
%41 = zext i32 %40 to i64
%42 = load i64, i64* %5
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %100
44: ; preds = %39
%45 = load i32, i32* %12
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %46
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = icmp eq i64 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %44
br label %100
52: ; preds = %44
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = load i32, i32* %12
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %57
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 1
%60 = load i32, i32* %59
store i32 %60, i32* %13
br label %61
61: ; preds = %55, %52
%62 = load i8*, i8** %10
%63 = call i32 @strlen(i8* %62)
%64 = add nsw i32 %63, 1
%65 = zext i32 %64 to i64
%66 = call i8* @llvm.stacksave()
store i8* %66, i8** %14
%67 = alloca i8, i64 %65
store i64 %65, i64* %15
%68 = load i8*, i8** %10
%69 = call i32 @strcpy(i8* %67, i8* %68)
%70 = load i32, i32* %12
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %71
%73 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %67, i64 %75
store i8 0, i8* %76
%77 = load i32, i32* %9
%78 = load i32, i32* %12
%79 = load i32, i32* %12
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %80
%82 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %81, i32 0, i32 0
%83 = load i64, i64* %82
%84 = load i32, i32* %12
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 %85
%87 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %86, i32 0, i32 1
%88 = load i32, i32* %87
%89 = load i32, i32* %12
%90 = zext 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 i64, i64* %92
%94 = getelementptr inbounds i8, i8* %67, i64 %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %77, i32 %78, i64 %83, i32 %88, i8* %94)
%96 = load i8*, i8** %14
br label %97
97: ; preds = %61
%98 = load i32, i32* %12
%99 = add i32 %98, 1
store i32 %99, i32* %12
br label %39
100: ; preds = %51, %39
%101 = load i32, i32* %13
%102 = load i8*, i8** %10
%103 = zext i32 %101 to i64
%104 = getelementptr inbounds i8, i8* %102, i64 %103
store i8* %104, i8** %10
br label %105
105: ; preds = %100
%106 = load i32, i32* %9
%107 = add i32 %106, 1
store i32 %107, i32* %9
br label %27
108: ; preds = %37, %27
%109 = call i32 @regfree(i32* %6)
store i32 0, i32* %1
store i32 1, i32* %11
br label %110
110: ; preds = %108, %23
%111 = load i8*, i8** %7
%112 = load i32, i32* %1
ret i32 %112
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32 }
@.str = [14 x i8] c"sanduicheiche\00"
@.str.1 = [12 x i8] c"([a-z]+)\\1$\00"
@REG_EXTENDED = global i32 0
@.str.3 = [35 x i8] c"Match %u, Group %u: [%2u-%2u]: %s\0A\00"
@str = [38 x i8] c"Could not compile regular expression.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i8* @llvm.stacksave()
%4 = alloca %struct.TYPE_3__
%5 = load i32, i32* @REG_EXTENDED
%6 = call i64 @regcomp(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%10 = call i64 @regexec(i32* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 1, %struct.TYPE_3__* %4, i32 0)
%11 = icmp ne i64 %10, 0
%12 = load i64, i64* %9
%13 = icmp eq i64 %12, -1
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %31, label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %33
17: ; preds = %8
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
%19 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%20 = add nsw i32 %19, 1
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* %18
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
%28 = load i64, i64* %9
%29 = getelementptr inbounds i8, i8* %23, i64 %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0, i64 %28, i32 %25, i8* %29)
br label %31
31: ; preds = %17, %8
%32 = call i32 @regfree(i32* %1)
br label %33
33: ; preds = %31, %15
%34 = phi i32 [ 1, %15 ], [ 0, %31 ]
ret i32 %34
}