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

/* Variables and functions */
int EOF;
int REG_EXTENDED;
int REG_ICASE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ *build_regex(char *, int);
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int fseeko(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
scalar_t__ get_filesize(char *);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_to_eof(int /*<<< orphan*/ *, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, int);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int buflen, ch, matched, opt, re_flags, status;
  char *buf, *re, *file;
  off_t fsize, cur_pos, prev_eol;
  regex_t *preg;
  FILE *fp;
  re_flags = 0;
  while ((opt = getopt(argc, argv, "Ehi")) != -1) {
    switch (opt) {
    case 'E':
      re_flags |= REG_EXTENDED;
      break;
    case 'i':
      re_flags |= REG_ICASE;
      break;
    default:
      usage();
      exit(-1);
    }
  }
  argc -= optind;
  argv += optind;
  if (2 != argc) {
    usage();
    exit(-1);
  }
  re = argv[0];
  preg = build_regex(re, re_flags);
  file = argv[1];
  fsize = get_filesize(file);
  fp = fopen(file, "r");
  if (NULL == fp) {
    perror(file);
    exit(-1);
  }
  prev_eol = fsize - 1;
  cur_pos = prev_eol - 1;
  buf = NULL;
  buflen = 0;
  matched = 0;
  while (0 <= cur_pos && !matched) {
    status = fseeko(fp, cur_pos, SEEK_SET);
    if (0 != status) {
      perror(file);
      exit(-1);
    }
    if (0 != cur_pos) {
      ch = fgetc(fp);
      if (EOF == ch) {
        perror(file);
        exit(-1);
      }
    }
    if ('\n' == ch || 0 == cur_pos) {
      int l = prev_eol - cur_pos - (0 != cur_pos ? 1 : 0);
      size_t read = 0;
      if (l + 1 > buflen) {
        buflen = l + 1;
        buf = realloc(buf, buflen);
        assert(NULL != buf);
      }
      do {
        read = fread(&buf[read], sizeof(char), l - read, fp);
        if (EOF == read) {
          perror(file);
          exit(-1);
        }
      } while (read < l);
      buf[l] = '\0';
      status = regexec(preg, buf, 0, NULL, 0);
      if (0 == status) {
        printf("%s\n", buf);
        print_to_eof(fp, file, buf, buflen);
        matched = 1;
      }
      prev_eol = cur_pos;
    }
    cur_pos--;
  }
  return !matched;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xde2(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1292 <main+0xa2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x7c(%rbp)
sub    $0x45,%eax
je     1254 <main+0x64>
jmp    1243 <main+0x53>
mov    -0x7c(%rbp),%eax
sub    $0x69,%eax
je     1268 <main+0x78>
jmp    127c <main+0x8c>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    128d <main+0x9d>
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    128d <main+0x9d>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    1210 <main+0x20>
mov    0x2d3f(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     12db <main+0xeb>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <build_regex@plt>
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1100 <get_filesize@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xcea(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x68(%rbp)
xor    %eax,%eax
cmp    -0x68(%rbp),%rax
jne    1342 <main+0x152>
mov    -0x40(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x48(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x50(%rbp),%rcx
mov    %al,-0x7d(%rbp)
jg     138d <main+0x19d>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x7d(%rbp)
mov    -0x7d(%rbp),%al
test   $0x1,%al
jne    139d <main+0x1ad>
jmp    1574 <main+0x384>
mov    -0x68(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    0x2c1c(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseeko@plt>
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
je     13d4 <main+0x1e4>
mov    -0x40(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
je     1416 <main+0x226>
mov    -0x68(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2bed(%rip),%rax
mov    (%rax),%eax
cmp    -0x18(%rbp),%eax
jne    1411 <main+0x221>
mov    -0x40(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    1416 <main+0x226>
mov    $0xa,%eax
cmp    -0x18(%rbp),%eax
je     1430 <main+0x240>
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jne    1563 <main+0x373>
mov    -0x58(%rbp),%rax
sub    -0x50(%rbp),%rax
mov    -0x50(%rbp),%rdi
xor    %ecx,%ecx
mov    %ecx,%esi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    %rdi,%rsi
cmovne %edx,%ecx
movslq %ecx,%rcx
sub    %rcx,%rax
mov    %eax,-0x6c(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jle    1499 <main+0x2a9>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    149e <main+0x2ae>
mov    -0x30(%rbp),%rdi
add    -0x78(%rbp),%rdi
movslq -0x6c(%rbp),%rax
sub    -0x78(%rbp),%rax
mov    %eax,%edx
mov    -0x68(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x78(%rbp)
mov    0x2b17(%rip),%rax
movslq (%rax),%rax
cmp    -0x78(%rbp),%rax
jne    14e9 <main+0x2f9>
mov    -0x40(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    14ee <main+0x2fe>
mov    -0x78(%rbp),%rax
movslq -0x6c(%rbp),%rcx
cmp    %rcx,%rax
jb     149e <main+0x2ae>
mov    -0x30(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x60(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1080 <regexec@plt>
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
jne    155b <main+0x36b>
mov    -0x30(%rbp),%rsi
lea    0xacb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1110 <print_to_eof@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x50(%rbp)
jmp    1370 <main+0x180>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %ebp,%ebp
lea    0xdf4(%rip),%r15
mov    0x2dad(%rip),%r12
mov    0x2dce(%rip),%r13
jmp    1225 <main+0x35>
nopl   0x0(%rax)
mov    %r13,%rcx
or     (%rcx),%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10e0 <getopt@plt>
mov    %r12,%rcx
cmp    $0x45,%eax
je     1223 <main+0x33>
cmp    $0x69,%eax
je     1220 <main+0x30>
cmp    $0xffffffff,%eax
jne    13fc <main+0x20c>
mov    0x2d89(%rip),%rax
mov    (%rax),%r15
sub    %r15d,%ebx
cmp    $0x2,%ebx
jne    13fc <main+0x20c>
mov    (%r14,%r15,8),%rdi
mov    %ebp,%esi
call   1070 <build_regex@plt>
mov    %rax,0x18(%rsp)
mov    0x8(%r14,%r15,8),%rbp
mov    %rbp,%rdi
call   1100 <get_filesize@plt>
mov    %rax,%rbx
lea    0xd7f(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     140d <main+0x21d>
mov    %rax,%r13
mov    $0x1,%eax
cmp    $0x2,%rbx
jl     13d9 <main+0x1e9>
mov    %rbp,0x8(%rsp)
lea    -0x2(%rbx),%r12
add    $0xffffffffffffffff,%rbx
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    0x2d1d(%rip),%r15
xor    %r14d,%r14d
jmp    12dc <main+0xec>
nopl   0x0(%rax,%rax,1)
test   %r12,%r12
mov    %rbp,%r12
jle    13ac <main+0x1bc>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   10b0 <fseeko@plt>
test   %eax,%eax
jne    13e8 <main+0x1f8>
mov    %r12,%rbp
sub    $0x1,%rbp
jb     1317 <main+0x127>
mov    %r13,%rdi
call   1050 <fgetc@plt>
cmp    %eax,(%r15)
je     13e8 <main+0x1f8>
cmp    $0xa,%eax
jne    12d0 <main+0xe0>
sub    %r12,%rbx
cmp    $0x1,%r12
adc    $0xffffffffffffffff,%rbx
cmp    %ebx,0x10(%rsp)
mov    %r12,0x20(%rsp)
jg     134e <main+0x15e>
lea    0x1(%rbx),%esi
mov    %r14,%rdi
mov    %rsi,0x10(%rsp)
call   1090 <realloc@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
movslq %ebx,%r12
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%rax,1),%rdi
mov    %ebx,%edx
sub    %eax,%edx
mov    $0x1,%esi
mov    %r13,%rcx
call   1030 <fread@plt>
movslq (%r15),%rcx
cmp    %rcx,%rax
je     13e8 <main+0x1f8>
cmp    %r12,%rax
jb     1360 <main+0x170>
movb   $0x0,(%r14,%r12,1)
mov    0x18(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     13b3 <main+0x1c3>
mov    0x20(%rsp),%r12
mov    %r12,%rbx
jmp    12d0 <main+0xe0>
mov    $0x1,%eax
jmp    13d9 <main+0x1e9>
lea    0xc4c(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    0x10(%rsp),%rcx
call   1110 <print_to_eof@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    %rbp,%rdi
jmp    13ed <main+0x1fd>

LLVM IR (-O0):
@.str = [4 x i8] c"Ehi\00"
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@optind = global i64 0
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
br label %22
22: ; preds = %40, %2
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 @getopt(i32 %23, i8** %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %25, i32* %9
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %41
27: ; preds = %22
%28 = load i32, i32* %9
switch i32 %28, label %37 [
i32 69, label %29
i32 105, label %33
]
29: ; preds = %27
%30 = load i32, i32* @REG_EXTENDED
%31 = load i32, i32* %10
%32 = or i32 %31, %30
store i32 %32, i32* %10
br label %40
33: ; preds = %27
%34 = load i32, i32* @REG_ICASE
%35 = load i32, i32* %10
%36 = or i32 %35, %34
store i32 %36, i32* %10
br label %40
37: ; preds = %27
%38 = call i32 (...) @usage()
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %33, %29
br label %22
41: ; preds = %22
%42 = load i64, i64* @optind
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = sub nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %4
%47 = load i64, i64* @optind
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 %47
store i8** %49, i8*** %5
%50 = load i32, i32* %4
%51 = icmp ne i32 2, %50
br i1 %51, label %52, label %55
52: ; preds = %41
%53 = call i32 (...) @usage()
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %41
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
store i8* %58, i8** %13
%59 = load i8*, i8** %13
%60 = load i32, i32* %10
%61 = call i32* @build_regex(i8* %59, i32 %60)
store i32* %61, i32** %18
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
store i8* %64, i8** %14
%65 = load i8*, i8** %14
%66 = call i64 @get_filesize(i8* %65)
store i64 %66, i64* %15
%67 = load i8*, i8** %14
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %68, i32** %19
%69 = load i32*, i32** %19
%70 = icmp eq i32* null, %69
br i1 %70, label %71, label %75
71: ; preds = %55
%72 = load i8*, i8** %14
%73 = call i32 @perror(i8* %72)
%74 = call i32 @exit(i32 -1)
unreachable
75: ; preds = %55
%76 = load i64, i64* %15
%77 = sub nsw i64 %76, 1
store i64 %77, i64* %17
%78 = load i64, i64* %17
%79 = sub nsw i64 %78, 1
store i64 %79, i64* %16
store i8* null, i8** %12
store i32 0, i32* %6
store i32 0, i32* %8
br label %80
80: ; preds = %191, %75
%81 = load i64, i64* %16
%82 = icmp sle i64 0, %81
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i32, i32* %8
%85 = icmp ne i32 %84, 0
%86 = xor i1 %85, true
br label %87
87: ; preds = %83, %80
%88 = phi i1 [ false, %80 ], [ %86, %83 ]
br i1 %88, label %89, label %194
89: ; preds = %87
%90 = load i32*, i32** %19
%91 = load i64, i64* %16
%92 = load i32, i32* @SEEK_SET
%93 = call i32 @fseeko(i32* %90, i64 %91, i32 %92)
store i32 %93, i32* %11
%94 = load i32, i32* %11
%95 = icmp ne i32 0, %94
br i1 %95, label %96, label %100
96: ; preds = %89
%97 = load i8*, i8** %14
%98 = call i32 @perror(i8* %97)
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %89
%101 = load i64, i64* %16
%102 = icmp ne i64 0, %101
br i1 %102, label %103, label %114
103: ; preds = %100
%104 = load i32*, i32** %19
%105 = call i32 @fgetc(i32* %104)
store i32 %105, i32* %7
%106 = load i32, i32* @EOF
%107 = load i32, i32* %7
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %113
109: ; preds = %103
%110 = load i8*, i8** %14
%111 = call i32 @perror(i8* %110)
%112 = call i32 @exit(i32 -1)
unreachable
113: ; preds = %103
br label %114
114: ; preds = %113, %100
%115 = load i32, i32* %7
%116 = icmp eq i32 10, %115
br i1 %116, label %120, label %117
117: ; preds = %114
%118 = load i64, i64* %16
%119 = icmp eq i64 0, %118
br i1 %119, label %120, label %191
120: ; preds = %117, %114
%121 = load i64, i64* %17
%122 = load i64, i64* %16
%123 = sub nsw i64 %121, %122
%124 = load i64, i64* %16
%125 = icmp ne i64 0, %124
%126 = zext i1 %125 to i64
%127 = select i1 %125, i32 1, i32 0
%128 = sext i32 %127 to i64
%129 = sub nsw i64 %123, %128
%130 = trunc i64 %129 to i32
store i32 %130, i32* %20
store i64 0, i64* %21
%131 = load i32, i32* %20
%132 = add nsw i32 %131, 1
%133 = load i32, i32* %6
%134 = icmp sgt i32 %132, %133
br i1 %134, label %135, label %145
135: ; preds = %120
%136 = load i32, i32* %20
%137 = add nsw i32 %136, 1
store i32 %137, i32* %6
%138 = load i8*, i8** %12
%139 = load i32, i32* %6
%140 = call i8* @realloc(i8* %138, i32 %139)
store i8* %140, i8** %12
%141 = load i8*, i8** %12
%142 = icmp ne i8* null, %141
%143 = zext i1 %142 to i32
%144 = call i32 @assert(i32 %143)
br label %145
145: ; preds = %135, %120
br label %146
146: ; preds = %166, %145
%147 = load i8*, i8** %12
%148 = load i64, i64* %21
%149 = getelementptr inbounds i8, i8* %147, i64 %148
%150 = load i32, i32* %20
%151 = sext i32 %150 to i64
%152 = load i64, i64* %21
%153 = sub i64 %151, %152
%154 = trunc i64 %153 to i32
%155 = load i32*, i32** %19
%156 = call i64 @fread(i8* %149, i32 1, i32 %154, i32* %155)
store i64 %156, i64* %21
%157 = load i32, i32* @EOF
%158 = sext i32 %157 to i64
%159 = load i64, i64* %21
%160 = icmp eq i64 %158, %159
br i1 %160, label %161, label %165
161: ; preds = %146
%162 = load i8*, i8** %14
%163 = call i32 @perror(i8* %162)
%164 = call i32 @exit(i32 -1)
unreachable
165: ; preds = %146
br label %166
166: ; preds = %165
%167 = load i64, i64* %21
%168 = load i32, i32* %20
%169 = sext i32 %168 to i64
%170 = icmp ult i64 %167, %169
br i1 %170, label %146, label %171
171: ; preds = %166
%172 = load i8*, i8** %12
%173 = load i32, i32* %20
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds i8, i8* %172, i64 %174
store i8 0, i8* %175
%176 = load i32*, i32** %18
%177 = load i8*, i8** %12
%178 = call i32 @regexec(i32* %176, i8* %177, i32 0, i32* null, i32 0)
store i32 %178, i32* %11
%179 = load i32, i32* %11
%180 = icmp eq i32 0, %179
br i1 %180, label %181, label %189
181: ; preds = %171
%182 = load i8*, i8** %12
%183 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %182)
%184 = load i32*, i32** %19
%185 = load i8*, i8** %14
%186 = load i8*, i8** %12
%187 = load i32, i32* %6
%188 = call i32 @print_to_eof(i32* %184, i8* %185, i8* %186, i32 %187)
store i32 1, i32* %8
br label %189
189: ; preds = %181, %171
%190 = load i64, i64* %16
store i64 %190, i64* %17
br label %191
191: ; preds = %189, %117
%192 = load i64, i64* %16
%193 = add nsw i64 %192, -1
store i64 %193, i64* %16
br label %80
194: ; preds = %87
%195 = load i32, i32* %8
%196 = icmp ne i32 %195, 0
%197 = xor i1 %196, true
%198 = zext i1 %197 to i32
ret i32 %198
}

LLVM IR (-O2):
@.str = [4 x i8] c"Ehi\00"
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@optind = global i64 0
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i32 [ 0, %2 ], [ %13, %10 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %7 [
i32 -1, label %14
i32 69, label %10
i32 105, label %6
]
6: ; preds = %3
br label %10
7: ; preds = %3
%8 = tail call i32 (...) @usage()
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %3, %6
%11 = phi i32* [ @REG_ICASE, %6 ], [ @REG_EXTENDED, %3 ]
%12 = load i32, i32* %11
%13 = or i32 %12, %4
br label %3
14: ; preds = %3
%15 = load i64, i64* @optind
%16 = trunc i64 %15 to i32
%17 = sub i32 %0, %16
%18 = getelementptr inbounds i8*, i8** %1, i64 %15
%19 = icmp eq i32 %17, 2
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = tail call i32 (...) @usage()
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = load i8*, i8** %18
%25 = tail call i32* @build_regex(i8* %24, i32 %4)
%26 = getelementptr inbounds i8*, i8** %18, i64 1
%27 = load i8*, i8** %26
%28 = tail call i64 @get_filesize(i8* %27)
%29 = tail call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = tail call i32 @perror(i8* %27)
%33 = tail call i32 @exit(i32 -1)
unreachable
34: ; preds = %23
%35 = icmp sgt i64 %28, 1
br i1 %35, label %36, label %106
36: ; preds = %34
%37 = add nsw i64 %28, -2
%38 = add nsw i64 %28, -1
br label %39
39: ; preds = %36, %100
%40 = phi i32 [ %103, %100 ], [ 0, %36 ]
%41 = phi i64 [ %102, %100 ], [ %38, %36 ]
%42 = phi i64 [ %104, %100 ], [ %37, %36 ]
%43 = phi i8* [ %101, %100 ], [ null, %36 ]
%44 = load i32, i32* @SEEK_SET
%45 = tail call i32 @fseeko(i32* %29, i64 %42, i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %39
%48 = tail call i32 @perror(i8* %27)
%49 = tail call i32 @exit(i32 -1)
unreachable
50: ; preds = %39
%51 = icmp eq i64 %42, 0
br i1 %51, label %61, label %52
52: ; preds = %50
%53 = tail call i32 @fgetc(i32* %29)
%54 = load i32, i32* @EOF
%55 = icmp eq i32 %54, %53
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = tail call i32 @perror(i8* %27)
%58 = tail call i32 @exit(i32 -1)
unreachable
59: ; preds = %52
%60 = icmp eq i32 %53, 10
br i1 %60, label %61, label %100
61: ; preds = %50, %59
%62 = sub nsw i64 %41, %42
%63 = xor i1 %51, true
%64 = sext i1 %63 to i64
%65 = add i64 %62, %64
%66 = trunc i64 %65 to i32
%67 = add nsw i32 %66, 1
%68 = icmp sgt i32 %40, %66
br i1 %68, label %74, label %69
69: ; preds = %61
%70 = tail call i8* @realloc(i8* %43, i32 %67)
%71 = icmp ne i8* %70, null
%72 = zext i1 %71 to i32
%73 = tail call i32 @assert(i32 %72)
br label %74
74: ; preds = %69, %61
%75 = phi i8* [ %70, %69 ], [ %43, %61 ]
%76 = phi i32 [ %67, %69 ], [ %40, %61 ]
%77 = shl i64 %65, 32
%78 = ashr exact i64 %77, 32
br label %79
79: ; preds = %91, %74
%80 = phi i64 [ 0, %74 ], [ %84, %91 ]
%81 = getelementptr inbounds i8, i8* %75, i64 %80
%82 = sub i64 %65, %80
%83 = trunc i64 %82 to i32
%84 = tail call i64 @fread(i8* %81, i32 1, i32 %83, i32* %29)
%85 = load i32, i32* @EOF
%86 = sext i32 %85 to i64
%87 = icmp eq i64 %84, %86
br i1 %87, label %88, label %91
88: ; preds = %79
%89 = tail call i32 @perror(i8* %27)
%90 = tail call i32 @exit(i32 -1)
unreachable
91: ; preds = %79
%92 = icmp ult i64 %84, %78
br i1 %92, label %79, label %93
93: ; preds = %91
%94 = getelementptr inbounds i8, i8* %75, i64 %78
store i8 0, i8* %94
%95 = tail call i32 @regexec(i32* %25, i8* %75, i32 0, i32* null, i32 0)
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %93
%98 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %75)
%99 = tail call i32 @print_to_eof(i32* %29, i8* %27, i8* %75, i32 %76)
br label %106
100: ; preds = %93, %59
%101 = phi i8* [ %43, %59 ], [ %75, %93 ]
%102 = phi i64 [ %41, %59 ], [ %42, %93 ]
%103 = phi i32 [ %40, %59 ], [ %76, %93 ]
%104 = add nsw i64 %42, -1
%105 = icmp sgt i64 %42, 0
br i1 %105, label %39, label %106
106: ; preds = %100, %97, %34
%107 = phi i32 [ 1, %34 ], [ 0, %97 ], [ 1, %100 ]
ret i32 %107
}