#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*/ REG_NOTBOL;
int /*<<< orphan*/ er_error(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *, int /*<<< orphan*/);
void er_match(char *argv[]) {
  int i, start;
  int error;
  regmatch_t match;
  regex_t reg;
  if ((i = regcomp(&reg, argv[1], REG_EXTENDED)) != 0)
    er_error(i, reg);
  printf("********** string original **********\n%s\n\n", argv[2]);
  i = start = 0;
  error = regexec(&reg, argv[2], 1, &match, 0);
  while (error == 0) {
    printf("início da string de pesquisa atual no caractere %d\n", start);
    printf("string de pesquisa = \"%s\"\n", argv[2] + start);
    printf("casou do caractere = %d ao %d\n\n", match.rm_so, match.rm_eo);
    start += match.rm_eo;
    i++;
    error = regexec(&reg, argv[2] + start, 1, &match, REG_NOTBOL);
  }
  if (start != 0)
    printf("Número total de casamentos = %d\n", i);
}


x86 assembly (clang, -O0):
<er_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     117d <er_match+0x3d>
mov    -0xc(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1050 <er_error@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x24(%rbp),%rdi
mov    $0x1,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1252 <er_match+0x112>
mov    -0x10(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    0x2db3(%rip),%rax
mov    (%rax),%r8d
lea    -0x24(%rbp),%rdi
mov    $0x1,%edx
lea    -0x20(%rbp),%rcx
call   1060 <regexec@plt>
mov    %eax,-0x14(%rbp)
jmp    11c1 <er_match+0x81>
cmpl   $0x0,-0x10(%rbp)
je     126d <er_match+0x12d>
mov    -0xc(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<er_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x8(%rdi),%rsi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %eax,%eax
je     1177 <er_match+0x37>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1050 <er_error@plt>
mov    0x10(%rbx),%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x1,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
jne    1244 <er_match+0x104>
lea    0xc(%rsp),%r13
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    0xe64(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %r15d,%r12
mov    0x10(%rbx),%rsi
add    %r12,%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq 0x14(%rsp),%r15
add    %r12,%r15
add    $0x1,%ebp
mov    %r15,%rsi
add    0x10(%rbx),%rsi
mov    0x2dd0(%rip),%rax
mov    (%rax),%r8d
mov    %r13,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <regexec@plt>
test   %eax,%eax
je     11c0 <er_match+0x80>
test   %r15d,%r15d
je     1244 <er_match+0x104>
lea    0xe60(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%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
@.str = [43 x i8] c"********** string original **********\0A%s\0A\0A\00"
@.str.1 = [53 x i8] c"in\C3\ADcio da string de pesquisa atual no caractere %d\0A\00"
@.str.2 = [27 x i8] c"string de pesquisa = \22%s\22\0A\00"
@.str.3 = [32 x i8] c"casou do caractere = %d ao %d\0A\0A\00"
@REG_NOTBOL = global i32 0
@.str.4 = [34 x i8] c"N\C3\BAmero total de casamentos = %d\0A\00"
define void @er_match(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
%7 = alloca i32
store i8** %0, i8*** %2
%8 = load i8**, i8*** %2
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @REG_EXTENDED
%12 = call i32 @regcomp(i32* %7, i8* %10, i32 %11)
store i32 %12, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* %3
%16 = load i32, i32* %7
%17 = call i32 @er_error(i32 %15, i32 %16)
br label %18
18: ; preds = %14, %1
%19 = load i8**, i8*** %2
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %4
store i32 0, i32* %3
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @regexec(i32* %7, i8* %25, i32 1, %struct.TYPE_3__* %6, i32 0)
store i32 %26, i32* %5
br label %27
27: ; preds = %30, %18
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %59
30: ; preds = %27
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8**, i8*** %2
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %43)
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load i32, i32* %4
%48 = add nsw i32 %47, %46
store i32 %48, i32* %4
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
%51 = load i8**, i8*** %2
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i32, i32* @REG_NOTBOL
%58 = call i32 @regexec(i32* %7, i8* %56, i32 1, %struct.TYPE_3__* %6, i32 %57)
store i32 %58, i32* %5
br label %27
59: ; preds = %27
%60 = load i32, i32* %4
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32, i32* %3
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %59
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
@.str = [43 x i8] c"********** string original **********\0A%s\0A\0A\00"
@.str.1 = [53 x i8] c"in\C3\ADcio da string de pesquisa atual no caractere %d\0A\00"
@.str.2 = [27 x i8] c"string de pesquisa = \22%s\22\0A\00"
@.str.3 = [32 x i8] c"casou do caractere = %d ao %d\0A\0A\00"
@REG_NOTBOL = global i32 0
@.str.4 = [34 x i8] c"N\C3\BAmero total de casamentos = %d\0A\00"
define void @er_match(i8** nocapture %0) {
%2 = alloca %struct.TYPE_3__
%3 = alloca i32
%4 = bitcast %struct.TYPE_3__* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds i8*, i8** %0, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @REG_EXTENDED
%9 = call i32 @regcomp(i32* %3, i8* %7, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @er_error(i32 %9, i32 %12)
br label %14
14: ; preds = %11, %1
%15 = getelementptr inbounds i8*, i8** %0, i64 2
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %15
%19 = call i32 @regexec(i32* %3, i8* %18, i32 1, %struct.TYPE_3__* %2, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %48
21: ; preds = %14
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
br label %24
24: ; preds = %21, %24
%25 = phi i32 [ 0, %21 ], [ %36, %24 ]
%26 = phi i32 [ 0, %21 ], [ %37, %24 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%28 = load i8*, i8** %15
%29 = sext i32 %25 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %22
%33 = load i32, i32* %23
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32, i32* %23
%36 = add nsw i32 %35, %25
%37 = add nuw nsw i32 %26, 1
%38 = load i8*, i8** %15
%39 = sext i32 %36 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i32, i32* @REG_NOTBOL
%42 = call i32 @regexec(i32* %3, i8* %40, i32 1, %struct.TYPE_3__* %2, i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %24, label %44
44: ; preds = %24
%45 = icmp eq i32 %36, 0
br i1 %45, label %48, label %46
46: ; preds = %44
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %48
48: ; preds = %14, %46, %44
ret void
}