#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;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char *argv[]) {
  regex_t re;
  regmatch_t matches[100];
  char input[100];
  char *next;
  int idx = 2;
  if (argc < 2) {
    printf("usage: %s <pattern> [ <input> <input> <input> ]\n", argv[0]);
    printf("if <input> not specified, input is read from stdin.\n");
    exit(-1);
  }
  if (regcomp(&re, argv[1], REG_EXTENDED) != 0) {
    printf("invalid pattern.\n");
    exit(-1);
  }
  while (1) {
    if (argc > 2) {
      if (idx < argc)
        next = argv[idx++];
      else
        break;
    } else {
      scanf("%s", input);
      next = input;
    }
    if (regexec(&re, next, 100, matches, 0) != 0) {
      printf("%s: no matches.\n", next);
      continue;
    }
    {
      int i;
      for (i = 0; i < 100; ++i) {
        if (matches[i].rm_so != -1) {
          printf("%s: match[%d]:%d-%d\n", next, i, matches[i].rm_so,
                 matches[i].rm_eo);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x3bc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11aa <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11e6 <main+0x96>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11eb <main+0x9b>
cmpl   $0x2,-0x8(%rbp)
jle    1236 <main+0xe6>
mov    -0x3bc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    -0x3bc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x3bc(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x3b8(%rbp)
jmp    1231 <main+0xe1>
jmp    131c <main+0x1cc>
jmp    1257 <main+0x107>
lea    -0x3b0(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x3b0(%rbp),%rax
mov    %rax,-0x3b8(%rbp)
mov    -0x3b8(%rbp),%rsi
lea    -0x340(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x64,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
cmp    $0x0,%rax
je     129a <main+0x14a>
mov    -0x3b8(%rbp),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11eb <main+0x9b>
movl   $0x0,-0x3c0(%rbp)
cmpl   $0x64,-0x3c0(%rbp)
jge    1317 <main+0x1c7>
movslq -0x3c0(%rbp),%rax
cmpl   $0xffffffff,-0x340(%rbp,%rax,8)
ff
je     12fe <main+0x1ae>
mov    -0x3b8(%rbp),%rsi
mov    -0x3c0(%rbp),%edx
movslq -0x3c0(%rbp),%rax
mov    -0x340(%rbp,%rax,8),%ecx
movslq -0x3c0(%rbp),%rax
mov    -0x33c(%rbp,%rax,8),%r8d
ff
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1303 <main+0x1b3>
mov    -0x3c0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c0(%rbp)
jmp    12a4 <main+0x154>
jmp    11eb <main+0x9b>
xor    %eax,%eax
add    $0x3c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3a8,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jle    1299 <main+0x139>
mov    %edi,%ebp
mov    0x8(%r15),%rsi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
test   %rax,%rax
jne    12b3 <main+0x153>
mov    $0x2,%r12d
lea    0xc(%rsp),%r14
lea    0xe94(%rip),%rbx
mov    %ebp,0x8(%rsp)
cmp    $0x3,%ebp
jb     11f0 <main+0x90>
jmp    11d6 <main+0x76>
nopl   0x0(%rax)
lea    0xe6d(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%ebp
jb     11f0 <main+0x90>
cmp    %ebp,%r12d
jge    1285 <main+0x125>
movslq %r12d,%rax
add    $0x1,%r12d
mov    (%r15,%rax,8),%r13
jmp    1204 <main+0xa4>
nopl   0x0(%rax)
lea    0xe3a(%rip),%rdi
lea    0x10(%rsp),%r13
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x64,%edx
lea    0x80(%rsp),%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r15,%rbp
xor    %r15d,%r15d
jmp    123a <main+0xda>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    $0x64,%r15
je     1270 <main+0x110>
mov    0x80(%rsp,%r15,8),%ecx
cmp    $0xffffffff,%ecx
je     1230 <main+0xd0>
mov    0x84(%rsp,%r15,8),%r8d
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1230 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r15
mov    0x8(%rsp),%ebp
cmp    $0x3,%ebp
jb     11f0 <main+0x90>
jmp    11d6 <main+0x76>
xor    %eax,%eax
add    $0x3a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xd5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdba(%rip),%rdi
jmp    12ba <main+0x15a>
lea    0xda0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [49 x i8] c"usage: %s <pattern> [ <input> <input> <input> ]\0A\00"
@.str.1 = [53 x i8] c"if <input> not specified, input is read from stdin.\0A\00"
@REG_EXTENDED = global i32 0
@.str.2 = [18 x i8] c"invalid pattern.\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [17 x i8] c"%s: no matches.\0A\00"
@.str.5 = [21 x i8] c"%s: match[%d]:%d-%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x %struct.TYPE_3__]
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @REG_EXTENDED
%26 = call i64 @regcomp(i32* %6, i8* %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %21
br label %32
32: ; preds = %31, %57, %89
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 2
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = load i32, i32* %10
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
store i8* %45, i8** %9
br label %47
46: ; preds = %35
br label %90
47: ; preds = %39
br label %52
48: ; preds = %32
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
store i8* %51, i8** %9
br label %52
52: ; preds = %48, %47
%53 = load i8*, i8** %9
%54 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %7, i64 0, i64 0
%55 = call i64 @regexec(i32* %6, i8* %53, i32 100, %struct.TYPE_3__* %54, i32 0)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = load i8*, i8** %9
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %58)
br label %32
60: ; preds = %52
store i32 0, i32* %11
br label %61
61: ; preds = %86, %60
%62 = load i32, i32* %11
%63 = icmp slt i32 %62, 100
br i1 %63, label %64, label %89
64: ; preds = %61
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %7, i64 0, i64 %66
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = icmp ne i32 %69, -1
br i1 %70, label %71, label %85
71: ; preds = %64
%72 = load i8*, i8** %9
%73 = load i32, i32* %11
%74 = load i32, i32* %11
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %7, i64 0, i64 %75
%77 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = load i32, i32* %11
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %7, i64 0, i64 %80
%82 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %81, i32 0, i32 1
%83 = load i32, i32* %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %72, i32 %73, i32 %78, i32 %83)
br label %85
85: ; preds = %71, %64
br label %86
86: ; preds = %85
%87 = load i32, i32* %11
%88 = add nsw i32 %87, 1
store i32 %88, i32* %11
br label %61
89: ; preds = %61
br label %32
90: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [49 x i8] c"usage: %s <pattern> [ <input> <input> <input> ]\0A\00"
@REG_EXTENDED = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [17 x i8] c"%s: no matches.\0A\00"
@.str.5 = [21 x i8] c"%s: match[%d]:%d-%d\0A\00"
@str = [17 x i8] c"invalid pattern.\00"
@str.6 = [52 x i8] c"if <input> not specified, input is read from stdin.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [100 x %struct.TYPE_3__]
%5 = alloca [100 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast [100 x %struct.TYPE_3__]* %4 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.6, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @REG_EXTENDED
%19 = call i64 @regcomp(i32* %3, i8* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = icmp ugt i32 %0, 2
%23 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %4, i64 0, i64 0
br label %27
24: ; preds = %15
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %45, %21
%28 = phi i32 [ 2, %21 ], [ %40, %45 ]
br i1 %22, label %29, label %36
29: ; preds = %27
%30 = icmp slt i32 %28, %0
br i1 %30, label %31, label %59
31: ; preds = %29
%32 = add nsw i32 %28, 1
%33 = sext i32 %28 to i64
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
br label %38
36: ; preds = %27
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %38
38: ; preds = %36, %31
%39 = phi i8* [ %35, %31 ], [ %8, %36 ]
%40 = phi i32 [ %32, %31 ], [ %28, %36 ]
%41 = call i64 @regexec(i32* %3, i8* %39, i32 100, %struct.TYPE_3__* %23, i32 0)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %39)
br label %45
45: ; preds = %56, %43
br label %27
46: ; preds = %38, %56
%47 = phi i64 [ %57, %56 ], [ 0, %38 ]
%48 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %4, i64 0, i64 %47, i32 0
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, -1
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = getelementptr inbounds [100 x %struct.TYPE_3__], [100 x %struct.TYPE_3__]* %4, i64 0, i64 %47, i32 1
%53 = load i32, i32* %52
%54 = trunc i64 %47 to i32
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %39, i32 %54, i32 %49, i32 %53)
br label %56
56: ; preds = %46, %51
%57 = add nuw nsw i64 %47, 1
%58 = icmp eq i64 %57, 100
br i1 %58, label %45, label %46
59: ; preds = %29
ret i32 0
}