#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 */

/* Type definitions */
typedef int /*<<< orphan*/ regmatch_t;
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
int REG_NOSUB;
int /*<<< orphan*/ er_error(int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int get_line(char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
void er_match(char *er, FILE *fp) {
  int i;
  char *line = NULL;
  regex_t reg;
  if ((i = regcomp(&reg, er, REG_EXTENDED | REG_NEWLINE | REG_NOSUB)) != 0)
    er_error(i, reg);
  while ((i = get_line(&line, fp)) != -1) {
    if ((regexec(&reg, line, 0, (regmatch_t *)NULL, 0)) == 0)
      printf("%s", line);
    free(line);
  }
}


x86 assembly (clang, -O0):
<er_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
mov    0x2e5c(%rip),%rax
or     (%rax),%edx
mov    0x2e43(%rip),%rax
or     (%rax),%edx
lea    -0x24(%rbp),%rdi
call   1060 <regcomp@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11b7 <er_match+0x57>
mov    -0x14(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <er_error@plt>
jmp    11bc <er_match+0x5c>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <get_line@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1214 <er_match+0xb4>
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1080 <regexec@plt>
cmp    $0x0,%rax
jne    1206 <er_match+0xa6>
mov    -0x20(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11bc <er_match+0x5c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<er_match>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    0x2e58(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
movq   $0x0,0x8(%rsp)
mov    0x2e45(%rip),%rax
or     (%rax),%edx
lea    0x14(%rsp),%rdi
call   1060 <regcomp@plt>
test   %eax,%eax
je     11ae <er_match+0x4e>
mov    0x14(%rsp),%esi
mov    %eax,%edi
call   1070 <er_error@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <get_line@plt>
cmp    $0xffffffff,%eax
je     1222 <er_match+0xc2>
lea    0x14(%rsp),%r14
lea    0xe34(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11fa <er_match+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <get_line@plt>
cmp    $0xffffffff,%eax
je     1222 <er_match+0xc2>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %rax,%rax
jne    11e0 <er_match+0x80>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1050 <printf@plt>
jmp    11e0 <er_match+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@REG_NOSUB = global i32 0
@.str = [3 x i8] c"%s\00"
define void @er_match(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %6
%8 = load i8*, i8** %3
%9 = load i32, i32* @REG_EXTENDED
%10 = load i32, i32* @REG_NEWLINE
%11 = or i32 %9, %10
%12 = load i32, i32* @REG_NOSUB
%13 = or i32 %11, %12
%14 = call i32 @regcomp(i32* %7, i8* %8, i32 %13)
store i32 %14, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = call i32 @er_error(i32 %17, i32 %18)
br label %20
20: ; preds = %16, %2
br label %21
21: ; preds = %32, %20
%22 = load i32*, i32** %4
%23 = call i32 @get_line(i8** %6, i32* %22)
store i32 %23, i32* %5
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = call i64 @regexec(i32* %7, i8* %26, i32 0, i32* null, i32 0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %25
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
br label %21
35: ; preds = %21
ret void
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@REG_NOSUB = global i32 0
@.str = [3 x i8] c"%s\00"
define void @er_match(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @REG_EXTENDED
%8 = load i32, i32* @REG_NEWLINE
%9 = or i32 %8, %7
%10 = load i32, i32* @REG_NOSUB
%11 = or i32 %9, %10
%12 = call i32 @regcomp(i32* %4, i8* %0, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%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 %32, label %20
20: ; preds = %17, %27
%21 = load i8*, i8** %3
%22 = call i64 @regexec(i32* %4, i8* %21, i32 0, i32* null, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %20
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
%30 = call i32 @get_line(i8** %3, i32* %1)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %20
32: ; preds = %27, %17
ret void
}