#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_9__ TYPE_2__;
typedef struct TYPE_8__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ string;
struct TYPE_8__ {
  int rm_so;
  int /*<<< orphan*/ rm_eo;
};
typedef TYPE_1__ regmatch_t;
struct TYPE_9__ {
  int re_nsub;
};
typedef TYPE_2__ regex_t;

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int REG_EXTENDED;
int REG_NEWLINE;
TYPE_1__ *alloca(int);
int /*<<< orphan*/ do_regerror(int, TYPE_2__ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int regcomp(TYPE_2__ *, char *, int);
int regexec(TYPE_2__ *, char *, int, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int main() {
  regex_t p;
  regmatch_t *pmatch;
  int rcomp_err, rexec_err;
  char string[BUFSIZ + 1];
  int i;
  rcomp_err =
      regcomp(&p, "(^(.*[^\\])#.*$)|(^[^#]+$)", REG_EXTENDED | REG_NEWLINE);
  if (rcomp_err) {
    do_regerror(rcomp_err, &p);
  }
  pmatch = alloca(sizeof(regmatch_t) * (p.re_nsub + 1));
  if (!pmatch) {
    perror("alloca");
  }
  printf("Input a string: ");
  fgets(string, sizeof(string), stdin);
  rexec_err = regexec(&p, string, p.re_nsub + 1, pmatch, 0);
  if (rexec_err) {
    do_regerror(rexec_err, &p);
  } else {
    for (i = 0; i <= p.re_nsub; i++) {
      if (pmatch[i].rm_so != -1) {
        char *submatch;
        size_t matchlen = pmatch[i].rm_eo - pmatch[i].rm_so;
        submatch = malloc(matchlen + 1);
        strncpy(submatch, string + pmatch[i].rm_so, matchlen);
        submatch[matchlen] = '\0';
        printf("match %i: %s\n", i, submatch);
        free(submatch);
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    0x2dde(%rip),%rax
or     (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1070 <regcomp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     122d <main+0x7d>
mov    -0x14(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <do_regerror@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <alloca@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    125b <main+0xab>
lea    0xdc4(%rip),%rdi
call   10c0 <perror@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    0x2d6e(%rip),%rax
mov    (%rax),%edx
call   1080 <fgets@plt>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
call   10b0 <regexec@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12b9 <main+0x109>
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <do_regerror@plt>
jmp    136e <main+0x1be>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1369 <main+0x1b9>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,8)
je     1356 <main+0x1a6>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%eax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    (%rcx,%rdx,8),%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    -0x48(%rbp),%rsi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movslq (%rax,%rcx,8),%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)
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    135b <main+0x1ab>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12c0 <main+0x110>
jmp    136e <main+0x1be>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e08(%rip),%rax
mov    (%rax),%r15d
add    $0x1,%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2de1(%rip),%rax
mov    0x2df2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe07(%rip),%rsi
lea    -0x30(%rbp),%rdi
call   1070 <regcomp@plt>
test   %eax,%eax
je     1211 <main+0x61>
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
call   1050 <do_regerror@plt>
mov    -0x30(%rbp),%eax
lea    0x8(,%rax,8),%edi
call   1090 <alloca@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1234 <main+0x84>
lea    0xdeb(%rip),%rdi
call   10c0 <perror@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1080 <fgets@plt>
mov    -0x30(%rbp),%edx
add    $0x1,%edx
lea    -0x30(%rbp),%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %eax,%eax
jne    1284 <main+0xd4>
mov    %rbx,-0x38(%rbp)
mov    -0x30(%rbp),%eax
test   %eax,%eax
jns    1296 <main+0xe6>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
call   1050 <do_regerror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
xor    %r13d,%r13d
jmp    12af <main+0xff>
nopl   0x0(%rax,%rax,1)
lea    0x1(%r13),%rcx
movslq %eax,%rdx
cmp    %rdx,%r13
mov    %rcx,%r13
jge    127d <main+0xcd>
movslq (%r12,%r13,8),%rbx
cmp    $0xffffffffffffffff,%rbx
je     12a0 <main+0xf0>
movslq 0x4(%r12,%r13,8),%r14
sub    %rbx,%r14
lea    0x1(%r14),%rdi
call   10a0 <malloc@plt>
mov    %rax,%r15
add    -0x38(%rbp),%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%r15,%r14,1)
lea    0xd47(%rip),%rdi
mov    %r13d,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
jmp    12a0 <main+0xf0>

LLVM IR (-O0):
%struct.TYPE_9__ = type { i32 }
%struct.TYPE_8__ = type { i32, i32 }
@BUFSIZ = global i32 0
@.str = [26 x i8] c"(^(.*[^\\])#.*$)|(^[^#]+$)\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.1 = [7 x i8] c"alloca\00"
@.str.2 = [17 x i8] c"Input a string: \00"
@stdin = global i32 0
@.str.3 = [14 x i8] c"match %i: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.TYPE_9__
%3 = alloca %struct.TYPE_8__*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
%11 = load i32, i32* @BUFSIZ
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* @REG_EXTENDED
%17 = load i32, i32* @REG_NEWLINE
%18 = or i32 %16, %17
%19 = call i32 @regcomp(%struct.TYPE_9__* %2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = load i32, i32* %4
%24 = call i32 @do_regerror(i32 %23, %struct.TYPE_9__* %2)
br label %25
25: ; preds = %22, %0
%26 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %2, i32 0, i32 0
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call %struct.TYPE_8__* @alloca(i32 %31)
store %struct.TYPE_8__* %32, %struct.TYPE_8__** %3
%33 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%34 = icmp ne %struct.TYPE_8__* %33, null
br i1 %34, label %37, label %35
35: ; preds = %25
%36 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%39 = trunc i64 %13 to i32
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %15, i32 %39, i32 %40)
%42 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %2, i32 0, i32 0
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1
%45 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%46 = call i32 @regexec(%struct.TYPE_9__* %2, i8* %15, i32 %44, %struct.TYPE_8__* %45, i32 0)
store i32 %46, i32* %5
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %37
%50 = load i32, i32* %5
%51 = call i32 @do_regerror(i32 %50, %struct.TYPE_9__* %2)
br label %108
52: ; preds = %37
store i32 0, i32* %8
br label %53
53: ; preds = %104, %52
%54 = load i32, i32* %8
%55 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %2, i32 0, i32 0
%56 = load i32, i32* %55
%57 = icmp sle i32 %54, %56
br i1 %57, label %58, label %107
58: ; preds = %53
%59 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %59, i64 %61
%63 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %103
66: ; preds = %58
%67 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %67, i64 %69
%71 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%74 = load i32, i32* %8
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %73, i64 %75
%77 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = sub nsw i32 %72, %78
%80 = sext i32 %79 to i64
store i64 %80, i64* %10
%81 = load i64, i64* %10
%82 = add i64 %81, 1
%83 = call i8* @malloc(i64 %82)
store i8* %83, i8** %9
%84 = load i8*, i8** %9
%85 = load %struct.TYPE_8__*, %struct.TYPE_8__** %3
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %85, i64 %87
%89 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %15, i64 %91
%93 = load i64, i64* %10
%94 = call i32 @strncpy(i8* %84, i8* %92, i64 %93)
%95 = load i8*, i8** %9
%96 = load i64, i64* %10
%97 = getelementptr inbounds i8, i8* %95, i64 %96
store i8 0, i8* %97
%98 = load i32, i32* %8
%99 = load i8*, i8** %9
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %98, i8* %99)
%101 = load i8*, i8** %9
%102 = call i32 @free(i8* %101)
br label %103
103: ; preds = %66, %58
br label %104
104: ; preds = %103
%105 = load i32, i32* %8
%106 = add nsw i32 %105, 1
store i32 %106, i32* %8
br label %53
107: ; preds = %53
br label %108
108: ; preds = %107, %49
%109 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.TYPE_9__ = type { i32 }
%struct.TYPE_8__ = type { i32, i32 }
@BUFSIZ = global i32 0
@.str = [26 x i8] c"(^(.*[^\\])#.*$)|(^[^#]+$)\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.1 = [7 x i8] c"alloca\00"
@.str.2 = [17 x i8] c"Input a string: \00"
@stdin = global i32 0
@.str.3 = [14 x i8] c"match %i: %s\0A\00"
define i32 @main() {
%1 = alloca %struct.TYPE_9__
%2 = bitcast %struct.TYPE_9__* %1 to i8*
%3 = load i32, i32* @BUFSIZ
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = load i32, i32* @REG_EXTENDED
%8 = load i32, i32* @REG_NEWLINE
%9 = or i32 %8, %7
%10 = call i32 @regcomp(%struct.TYPE_9__* %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @do_regerror(i32 %10, %struct.TYPE_9__* %1)
br label %14
14: ; preds = %12, %0
%15 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = shl i32 %16, 3
%18 = add i32 %17, 8
%19 = call %struct.TYPE_8__* @alloca(i32 %18)
%20 = icmp eq %struct.TYPE_8__* %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %6, i32 %4, i32 %25)
%27 = load i32, i32* %15
%28 = add nsw i32 %27, 1
%29 = call i32 @regexec(%struct.TYPE_9__* %1, i8* %6, i32 %28, %struct.TYPE_8__* %19, i32 0)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load i32, i32* %15
%33 = icmp slt i32 %32, 0
br i1 %33, label %62, label %36
34: ; preds = %23
%35 = call i32 @do_regerror(i32 %29, %struct.TYPE_9__* %1)
br label %62
36: ; preds = %31, %57
%37 = phi i32 [ %58, %57 ], [ %32, %31 ]
%38 = phi i64 [ %59, %57 ], [ 0, %31 ]
%39 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %19, i64 %38, i32 0
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, -1
br i1 %41, label %57, label %42
42: ; preds = %36
%43 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %19, i64 %38, i32 1
%44 = load i32, i32* %43
%45 = sub nsw i32 %44, %40
%46 = sext i32 %45 to i64
%47 = add nsw i64 %46, 1
%48 = call i8* @malloc(i64 %47)
%49 = sext i32 %40 to i64
%50 = getelementptr inbounds i8, i8* %6, i64 %49
%51 = call i32 @strncpy(i8* %48, i8* %50, i64 %46)
%52 = getelementptr inbounds i8, i8* %48, i64 %46
store i8 0, i8* %52
%53 = trunc i64 %38 to i32
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %48)
%55 = call i32 @free(i8* %48)
%56 = load i32, i32* %15
br label %57
57: ; preds = %36, %42
%58 = phi i32 [ %37, %36 ], [ %56, %42 ]
%59 = add nuw nsw i64 %38, 1
%60 = sext i32 %58 to i64
%61 = icmp slt i64 %38, %60
br i1 %61, label %36, label %62
62: ; preds = %57, %31, %34
%63 = call i32 @exit(i32 0)
unreachable
}