#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
int /*<<< orphan*/ REG_NOTBOL;
int /*<<< orphan*/ er_error(int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int get_line(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int strlen(char *);
void er_match(char *er, FILE *fp) {
  int i, error, start;
  char *line = NULL;
  regmatch_t match;
  regex_t reg;
  if ((i = regcomp(&reg, er, REG_EXTENDED | REG_NEWLINE)) != 0)
    er_error(i, reg);
  while ((i = get_line(&line, fp)) != -1) {
    start = 0;
    error = regexec(&reg, line, 1, &match, 0);
    while (error == 0) {
      fwrite(line + start, 1, match.rm_so, stdout);
      printf("%s", "\033[36;1m");
      fwrite(line + start + match.rm_so, 1, match.rm_eo - match.rm_so, stdout);
      printf("%s", "\033[m");
      start += match.rm_eo;
      error = regexec(&reg, line + start, 1, &match, REG_NOTBOL);
    }
    if (start != 0)
      fwrite(line + start, 1, strlen(line + start), stdout);
  }
}


x86 assembly (clang, -O0):
<er_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    0x2e44(%rip),%rax
or     (%rax),%edx
lea    -0x34(%rbp),%rdi
call   1060 <regcomp@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11be <er_match+0x4e>
mov    -0x14(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1070 <er_error@plt>
jmp    11c3 <er_match+0x53>
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1030 <get_line@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12fa <er_match+0x18a>
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rsi
lea    -0x34(%rbp),%rdi
mov    $0x1,%edx
lea    -0x30(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12b3 <er_match+0x143>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%edx
mov    0x2db2(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
lea    0xdcf(%rip),%rdi
lea    0xdcb(%rip),%rsi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x2c(%rbp),%edx
sub    -0x30(%rbp),%edx
mov    0x2d74(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
lea    0xd91(%rip),%rdi
lea    0xd95(%rip),%rsi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    0x2d52(%rip),%rax
mov    (%rax),%r8d
lea    -0x34(%rbp),%rdi
mov    $0x1,%edx
lea    -0x30(%rbp),%rcx
call   1080 <regexec@plt>
mov    %eax,-0x18(%rbp)
jmp    11ff <er_match+0x8f>
cmpl   $0x0,-0x1c(%rbp)
je     12f5 <er_match+0x185>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
mov    0x2ce7(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    11c3 <er_match+0x53>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<er_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
mov    %rdi,%rsi
movq   $0x0,0x8(%rsp)
mov    0x2e34(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x1c(%rsp),%rdi
call   1060 <regcomp@plt>
test   %eax,%eax
je     11b8 <er_match+0x48>
mov    0x1c(%rsp),%esi
mov    %eax,%edi
call   1070 <er_error@plt>
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1030 <get_line@plt>
cmp    $0xffffffff,%eax
je     12f0 <er_match+0x180>
lea    0x1c(%rsp),%r12
lea    0x10(%rsp),%r15
mov    0x2df1(%rip),%rbx
lea    0xe1a(%rip),%r14
mov    %r13,0x20(%rsp)
jmp    1206 <er_match+0x96>
nopl   (%rax)
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1030 <get_line@plt>
cmp    $0xffffffff,%eax
je     12f0 <er_match+0x180>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
jne    11f0 <er_match+0x80>
xor    %ebp,%ebp
mov    0x2dbd(%rip),%r15
nopl   0x0(%rax,%rax,1)
movslq %ebp,%r13
mov    0x8(%rsp),%rdi
add    %r13,%rdi
mov    0x10(%rsp),%edx
mov    (%rbx),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %r14,%rdi
lea    0xdae(%rip),%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
add    %r13,%rdi
movslq 0x10(%rsp),%rax
add    %rax,%rdi
mov    0x14(%rsp),%edx
sub    %eax,%edx
mov    (%rbx),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    %r14,%rdi
lea    0xd85(%rip),%rsi
call   1050 <printf@plt>
movslq 0x14(%rsp),%rbp
add    %r13,%rbp
mov    %rbp,%rsi
add    0x8(%rsp),%rsi
mov    (%r15),%r8d
mov    %r12,%rdi
mov    $0x1,%edx
lea    0x10(%rsp),%rcx
call   1080 <regexec@plt>
test   %eax,%eax
je     1230 <er_match+0xc0>
test   %ebp,%ebp
mov    0x20(%rsp),%r13
lea    0x10(%rsp),%r15
je     11f0 <er_match+0x80>
movslq %ebp,%rbp
add    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    (%rbx),%ecx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1090 <fwrite@plt>
jmp    11f0 <er_match+0x80>
add    $0x28,%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
@REG_NEWLINE = global i32 0
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"\1B[36;1m\00"
@.str.2 = [4 x i8] c"\1B[m\00"
@REG_NOTBOL = global i32 0
define void @er_match(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.TYPE_3__
%10 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %8
%11 = load i8*, i8** %3
%12 = load i32, i32* @REG_EXTENDED
%13 = load i32, i32* @REG_NEWLINE
%14 = or i32 %12, %13
%15 = call i32 @regcomp(i32* %10, i8* %11, i32 %14)
store i32 %15, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i32, i32* %10
%20 = call i32 @er_error(i32 %18, i32 %19)
br label %21
21: ; preds = %17, %2
br label %22
22: ; preds = %83, %21
%23 = load i32*, i32** %4
%24 = call i32 @get_line(i8** %8, i32* %23)
store i32 %24, i32* %5
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %84
26: ; preds = %22
store i32 0, i32* %7
%27 = load i8*, i8** %8
%28 = call i32 @regexec(i32* %10, i8* %27, i32 1, %struct.TYPE_3__* %9, i32 0)
store i32 %28, i32* %6
br label %29
29: ; preds = %32, %26
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %68
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @stdout
%40 = call i32 @fwrite(i8* %36, i32 1, i32 %38, i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8*, i8** %8
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%47 = load i32, i32* %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sub nsw i32 %51, %53
%55 = load i32, i32* @stdout
%56 = call i32 @fwrite(i8* %49, i32 1, i32 %54, i32 %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%58 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%59 = load i32, i32* %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, %59
store i32 %61, i32* %7
%62 = load i8*, i8** %8
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i32, i32* @REG_NOTBOL
%67 = call i32 @regexec(i32* %10, i8* %65, i32 1, %struct.TYPE_3__* %9, i32 %66)
store i32 %67, i32* %6
br label %29
68: ; preds = %29
%69 = load i32, i32* %7
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %83
71: ; preds = %68
%72 = load i8*, i8** %8
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8*, i8** %8
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = call i32 @strlen(i8* %79)
%81 = load i32, i32* @stdout
%82 = call i32 @fwrite(i8* %75, i32 1, i32 %80, i32 %81)
br label %83
83: ; preds = %71, %68
br label %22
84: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@stdout = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"\1B[36;1m\00"
@.str.2 = [4 x i8] c"\1B[m\00"
@REG_NOTBOL = global i32 0
define void @er_match(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca %struct.TYPE_3__
%5 = alloca i32
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast %struct.TYPE_3__* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @REG_EXTENDED
%10 = load i32, i32* @REG_NEWLINE
%11 = or i32 %10, %9
%12 = call i32 @regcomp(i32* %5, i8* %0, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %5
%16 = call i32 @er_error(i32 %12, i32 %15)
br label %17
17: ; preds = %14, %2
%18 = call i32 @get_line(i8** %3, i32* %1)
%19 = icmp eq i32 %18, -1
br i1 %19, label %66, label %20
20: ; preds = %17
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
br label %23
23: ; preds = %20, %63
%24 = load i8*, i8** %3
%25 = call i32 @regexec(i32* %5, i8* %24, i32 1, %struct.TYPE_3__* %4, i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %63
27: ; preds = %23, %27
%28 = phi i32 [ %47, %27 ], [ 0, %23 ]
%29 = load i8*, i8** %3
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i32, i32* %21
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i8* %31, i32 1, i32 %32, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 %30
%38 = load i32, i32* %21
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i32, i32* %22
%42 = sub nsw i32 %41, %38
%43 = load i32, i32* @stdout
%44 = call i32 @fwrite(i8* %40, i32 1, i32 %42, i32 %43)
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %22
%47 = add nsw i32 %46, %28
%48 = load i8*, i8** %3
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = load i32, i32* @REG_NOTBOL
%52 = call i32 @regexec(i32* %5, i8* %50, i32 1, %struct.TYPE_3__* %4, i32 %51)
%53 = icmp eq i32 %52, 0
br i1 %53, label %27, label %54
54: ; preds = %27
%55 = icmp eq i32 %47, 0
br i1 %55, label %63, label %56
56: ; preds = %54
%57 = load i8*, i8** %3
%58 = sext i32 %47 to i64
%59 = getelementptr inbounds i8, i8* %57, i64 %58
%60 = call i32 @strlen(i8* %59)
%61 = load i32, i32* @stdout
%62 = call i32 @fwrite(i8* %59, i32 1, i32 %60, i32 %61)
br label %63
63: ; preds = %23, %56, %54
%64 = call i32 @get_line(i8** %3, i32* %1)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %23
66: ; preds = %63, %17
ret void
}