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

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_list(char *);
int /*<<< orphan*/ print_line_colored(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
void search(char string[]) {
  regex_t reg;
  int err;
  char err_msg[80];
  FILE *fp;
  char line[4096];
  if ((err = regcomp(&reg, string, REG_NOSUB | REG_EXTENDED)) != 0) {
    regerror(err, &reg, err_msg, 80);
    printf("Error analyzing regular expression '%s': %s.\n", string, err_msg);
  }
  fp = open_list("r");
  while (fgets(line, sizeof(line), fp)) {
    if (regexec(&reg, line + 4, 0, NULL, 0) == 0)
      print_line_colored(line);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    0x2e35(%rip),%rax
or     (%rax),%edx
lea    -0xc(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11e3 <search+0x63>
mov    -0x10(%rbp),%edi
lea    -0x60(%rbp),%rdx
lea    -0xc(%rbp),%rsi
mov    $0x50,%ecx
call   1070 <regerror@plt>
mov    -0x8(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
lea    0xe44(%rip),%rdi
call   10a0 <open_list@plt>
mov    %rax,-0x68(%rbp)
lea    -0x1070(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     124b <search+0xcb>
lea    -0x1070(%rbp),%rsi
add    $0x4,%rsi
lea    -0xc(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1090 <regexec@plt>
cmp    $0x0,%rax
jne    1246 <search+0xc6>
lea    -0x1070(%rbp),%rdi
call   1080 <print_line_colored@plt>
jmp    11f3 <search+0x73>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1068,%rsp
mov    %rdi,%rbx
mov    0x2e48(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11df <search+0x5f>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x50,%ecx
call   1070 <regerror@plt>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
call   10a0 <open_list@plt>
mov    %rax,%rbx
lea    0x60(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1256 <search+0xd6>
lea    0x64(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x60(%rsp),%r12
jmp    1235 <search+0xb5>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1256 <search+0xd6>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <regexec@plt>
test   %rax,%rax
jne    1220 <search+0xa0>
mov    %r12,%rdi
call   1080 <print_line_colored@plt>
jmp    1220 <search+0xa0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1068,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@REG_NOSUB = global i32 0
@REG_EXTENDED = global i32 0
@.str = [46 x i8] c"Error analyzing regular expression '%s': %s.\0A\00"
@.str.1 = [2 x i8] c"r\00"
define void @search(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32*
%7 = alloca [4096 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = load i32, i32* @REG_NOSUB
%10 = load i32, i32* @REG_EXTENDED
%11 = or i32 %9, %10
%12 = call i32 @regcomp(i32* %3, i8* %8, i32 %11)
store i32 %12, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = load i32, i32* %4
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%17 = call i32 @regerror(i32 %15, i32* %3, i8* %16, i32 80)
%18 = load i8*, i8** %2
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
br label %21
21: ; preds = %14, %1
%22 = call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
br label %23
23: ; preds = %36, %21
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i64 @fgets(i8* %24, i32 4096, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = call i64 @regexec(i32* %3, i8* %30, i32 0, i32* null, i32 0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%35 = call i32 @print_line_colored(i8* %34)
br label %36
36: ; preds = %33, %28
br label %23
37: ; preds = %23
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
ret void
}

LLVM IR (-O2):
@REG_NOSUB = global i32 0
@REG_EXTENDED = global i32 0
@.str = [46 x i8] c"Error analyzing regular expression '%s': %s.\0A\00"
@.str.1 = [2 x i8] c"r\00"
define void @search(i8* %0) {
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca [4096 x i8]
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @REG_NOSUB
%9 = load i32, i32* @REG_EXTENDED
%10 = or i32 %9, %8
%11 = call i32 @regcomp(i32* %2, i8* %0, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = call i32 @regerror(i32 %11, i32* %2, i8* %6, i32 80)
%15 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6)
br label %16
16: ; preds = %13, %1
%17 = call i32* @open_list(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i64 @fgets(i8* %7, i32 4096, i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %16
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 4
br label %22
22: ; preds = %20, %27
%23 = call i64 @regexec(i32* %2, i8* %21, i32 0, i32* null, i32 0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @print_line_colored(i8* %7)
br label %27
27: ; preds = %25, %22
%28 = call i64 @fgets(i8* %7, i32 4096, i32* %17)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %22
30: ; preds = %27, %16
%31 = call i32 @fclose(i32* %17)
ret void
}