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

/* Variables and functions */
int /*<<< orphan*/ dolog(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
void rf(char *f) {
  long int markers[250000];
  long int headers[250000];
  int header = 0;
  int msg_number = 0;
  long int last = 0;
  long int this_pos = 0;
  int ln = 0;
  FILE *file = fopen(f, "r");
  if (file != NULL) {
    char line[1024] = {0};
    while (fgets(line, sizeof line, file) != NULL) {
      ln++;
      char *loc = strstr(line, "From ");
      if (loc) {
        if ((loc - line) == 0) {
          markers[msg_number] = ftell(file);
          msg_number++;
          header = 1;
        }
      } else {
        if (header > 0) {
          if (strlen(line) == 1) {
            header = 0;
            headers[msg_number] = ftell(file) - 1;
          }
        }
      }
      this_pos = ftell(file);
    }
    last = ftell(file);
    fclose(file);
  } else {
    perror(f);
  }
  char msg[1024] = {0};
  sprintf(msg, "Found %i msgs in %s. (%i bytes)", msg_number, f, last);
  dolog(msg);
  markers[msg_number] = last;
  while (msg_number > 0) {
    msg_number--;
    char cmd[1024] = {0};
    sprintf(cmd, "/home/da3m0n8t3r/elmboxo/pmess \"%s\" %i %i %i", f,
            markers[msg_number], headers[msg_number + 1],
            markers[msg_number + 1]);
    system(cmd);
  }
}


x86 assembly (clang, -O0):
<rf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d1550,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x3d0914(%rbp)
movl   $0x0,-0x3d0918(%rbp)
movq   $0x0,-0x3d0920(%rbp)
movq   $0x0,-0x3d0928(%rbp)
movl   $0x0,-0x3d092c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x3d0938(%rbp)
cmpq   $0x0,-0x3d0938(%rbp)
je     1372 <rf+0x1c2>
lea    -0x3d0d40(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x3d0d40(%rbp),%rdi
mov    -0x3d0938(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     134c <rf+0x19c>
mov    -0x3d092c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d092c(%rbp)
lea    -0x3d0d40(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x3d0d48(%rbp)
cmpq   $0x0,-0x3d0d48(%rbp)
je     12db <rf+0x12b>
mov    -0x3d0d48(%rbp),%rax
lea    -0x3d0d40(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x0,%rax
jne    12d6 <rf+0x126>
mov    -0x3d0938(%rbp),%rdi
call   1090 <ftell@plt>
movslq %eax,%rcx
movslq -0x3d0918(%rbp),%rax
mov    %rcx,-0x1e8490(%rbp,%rax,8)
ff
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
movl   $0x1,-0x3d0914(%rbp)
jmp    1332 <rf+0x182>
cmpl   $0x0,-0x3d0914(%rbp)
jle    132d <rf+0x17d>
lea    -0x3d0d40(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    1328 <rf+0x178>
movl   $0x0,-0x3d0914(%rbp)
mov    -0x3d0938(%rbp),%rdi
call   1090 <ftell@plt>
sub    $0x1,%eax
movslq %eax,%rcx
movslq -0x3d0918(%rbp),%rax
mov    %rcx,-0x3d0910(%rbp,%rax,8)
ff
jmp    132d <rf+0x17d>
jmp    1332 <rf+0x182>
mov    -0x3d0938(%rbp),%rdi
call   1090 <ftell@plt>
cltq
mov    %rax,-0x3d0928(%rbp)
jmp    122b <rf+0x7b>
mov    -0x3d0938(%rbp),%rdi
call   1090 <ftell@plt>
cltq
mov    %rax,-0x3d0920(%rbp)
mov    -0x3d0938(%rbp),%rdi
call   1040 <fclose@plt>
jmp    137b <rf+0x1cb>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
lea    -0x3d1150(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x3d1150(%rbp),%rdi
mov    -0x3d0918(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x3d0920(%rbp),%r8
lea    0xc5b(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x3d1150(%rbp),%rdi
call   1030 <dolog@plt>
mov    -0x3d0920(%rbp),%rcx
movslq -0x3d0918(%rbp),%rax
mov    %rcx,-0x1e8490(%rbp,%rax,8)
ff
cmpl   $0x0,-0x3d0918(%rbp)
jle    1464 <rf+0x2b4>
mov    -0x3d0918(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3d0918(%rbp)
lea    -0x3d1550(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x3d1550(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x3d0918(%rbp),%rax
mov    -0x1e8490(%rbp,%rax,8),%rcx
ff
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x3d0910(%rbp,%rax,8),%r8
ff
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x1e8490(%rbp,%rax,8),%r9
ff
lea    0xbdc(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x3d1550(%rbp),%rdi
call   1060 <system@plt>
jmp    13d6 <rf+0x226>
add    $0x3d1550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3d1108,%rsp
mov    %rdi,%r14
lea    0xe35(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     139e <rf+0x1ee>
mov    %rax,%rbx
mov    %rsp,%r12
xor    %r15d,%r15d
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12cb <rf+0x11b>
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    1247 <rf+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r13d
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %r13d,%ebp
test   %rax,%rax
je     12cb <rf+0x11b>
mov    %r12,%rdi
lea    0xdb1(%rip),%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1280 <rf+0xd0>
cmp    %r12,%rax
jne    1220 <rf+0x70>
mov    %rbx,%rdi
call   1090 <ftell@plt>
cltq
movslq %r15d,%r15
mov    %rax,0x800(%rsp,%r15,8)
add    $0x1,%r15d
jmp    12c0 <rf+0x110>
nopl   0x0(%rax,%rax,1)
xor    %r13d,%r13d
test   %ebp,%ebp
jle    1223 <rf+0x73>
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    12c0 <rf+0x110>
mov    %rbx,%rdi
call   1090 <ftell@plt>
add    $0xffffffff,%eax
cltq
movslq %r15d,%rcx
mov    %rax,0x1e8c80(%rsp,%rcx,8)
jmp    1223 <rf+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r13d
jmp    1223 <rf+0x73>
mov    %rbx,%rdi
call   1090 <ftell@plt>
movslq %eax,%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xd11(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <dolog@plt>
movslq %r15d,%rax
mov    %r12,0x800(%rsp,%rax,8)
test   %eax,%eax
jle    138c <rf+0x1dc>
mov    %r15d,%ebp
add    $0x1,%rbp
lea    0x400(%rsp),%r12
lea    0xcf1(%rip),%r15
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbp),%ebx
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x800(%rsp,%rbx,8),%rcx
mov    0x1e8c78(%rsp,%rbp,8),%r8
mov    0x7f8(%rsp,%rbp,8),%r9
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r12,%rdi
call   1060 <system@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1340 <rf+0x190>
add    $0x3d1108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   10b0 <perror@plt>
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    12de <rf+0x12e>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"From \00"
@.str.2 = [32 x i8] c"Found %i msgs in %s. (%i bytes)\00"
@.str.3 = [45 x i8] c"/home/da3m0n8t3r/elmboxo/pmess \22%s\22 %i %i %i\00"
define void @rf(i8* %0) {
%2 = alloca i8*
%3 = alloca [250000 x i64]
%4 = alloca [250000 x i64]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [1024 x i8]
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
store i8* %0, i8** %2
store i32 0, i32* %5
store i32 0, i32* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i32 0, i32* %9
%15 = load i8*, i8** %2
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
%17 = load i32*, i32** %10
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %77
19: ; preds = %1
%20 = bitcast [1024 x i8]* %11 to i8*
br label %21
21: ; preds = %67, %19
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%23 = load i32*, i32** %10
%24 = call i32* @fgets(i8* %22, i32 1024, i32* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %71
26: ; preds = %21
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %12
%31 = load i8*, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %50
33: ; preds = %26
%34 = load i8*, i8** %12
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %33
%41 = load i32*, i32** %10
%42 = call i32 @ftell(i32* %41)
%43 = sext i32 %42 to i64
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %45
store i64 %43, i64* %46
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
store i32 1, i32* %5
br label %49
49: ; preds = %40, %33
br label %67
50: ; preds = %26
%51 = load i32, i32* %5
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %66
53: ; preds = %50
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %65
57: ; preds = %53
store i32 0, i32* %5
%58 = load i32*, i32** %10
%59 = call i32 @ftell(i32* %58)
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [250000 x i64], [250000 x i64]* %4, i64 0, i64 %63
store i64 %61, i64* %64
br label %65
65: ; preds = %57, %53
br label %66
66: ; preds = %65, %50
br label %67
67: ; preds = %66, %49
%68 = load i32*, i32** %10
%69 = call i32 @ftell(i32* %68)
%70 = sext i32 %69 to i64
store i64 %70, i64* %8
br label %21
71: ; preds = %21
%72 = load i32*, i32** %10
%73 = call i32 @ftell(i32* %72)
%74 = sext i32 %73 to i64
store i64 %74, i64* %7
%75 = load i32*, i32** %10
%76 = call i32 @fclose(i32* %75)
br label %80
77: ; preds = %1
%78 = load i8*, i8** %2
%79 = call i32 @perror(i8* %78)
br label %80
80: ; preds = %77, %71
%81 = bitcast [1024 x i8]* %13 to i8*
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%83 = load i32, i32* %6
%84 = load i8*, i8** %2
%85 = load i64, i64* %7
%86 = call i32 (i8*, i8*, ...) @sprintf(i8* %82, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %83, i8* %84, i64 %85)
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%88 = call i32 @dolog(i8* %87)
%89 = load i64, i64* %7
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %91
store i64 %89, i64* %92
br label %93
93: ; preds = %96, %80
%94 = load i32, i32* %6
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %119
96: ; preds = %93
%97 = load i32, i32* %6
%98 = add nsw i32 %97, -1
store i32 %98, i32* %6
%99 = bitcast [1024 x i8]* %14 to i8*
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%101 = load i8*, i8** %2
%102 = load i32, i32* %6
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %103
%105 = load i64, i64* %104
%106 = load i32, i32* %6
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [250000 x i64], [250000 x i64]* %4, i64 0, i64 %108
%110 = load i64, i64* %109
%111 = load i32, i32* %6
%112 = add nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %113
%115 = load i64, i64* %114
%116 = call i32 (i8*, i8*, ...) @sprintf(i8* %100, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %101, i64 %105, i64 %110, i64 %115)
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%118 = call i32 @system(i8* %117)
br label %93
119: ; preds = %93
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"From \00"
@.str.2 = [32 x i8] c"Found %i msgs in %s. (%i bytes)\00"
@.str.3 = [45 x i8] c"/home/da3m0n8t3r/elmboxo/pmess \22%s\22 %i %i %i\00"
define void @rf(i8* %0) {
%2 = alloca [250000 x i64]
%3 = alloca [250000 x i64]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = bitcast [250000 x i64]* %2 to i8*
%8 = bitcast [250000 x i64]* %3 to i8*
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %50, label %11
11: ; preds = %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = call i32* @fgets(i8* %12, i32 1024, i32* %9)
%14 = icmp eq i32* %13, null
br i1 %14, label %45, label %15
15: ; preds = %11, %39
%16 = phi i32 [ %41, %39 ], [ 0, %11 ]
%17 = phi i32 [ %40, %39 ], [ 0, %11 ]
%18 = call i8* @strstr(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %15
%21 = icmp eq i8* %18, %12
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = call i32 @ftell(i32* %9)
%24 = sext i32 %23 to i64
%25 = sext i32 %17 to i64
%26 = getelementptr inbounds [250000 x i64], [250000 x i64]* %2, i64 0, i64 %25
store i64 %24, i64* %26
%27 = add nsw i32 %17, 1
br label %39
28: ; preds = %15
%29 = icmp sgt i32 %16, 0
br i1 %29, label %30, label %39
30: ; preds = %28
%31 = call i32 @strlen(i8* %12)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = call i32 @ftell(i32* %9)
%35 = add nsw i32 %34, -1
%36 = sext i32 %35 to i64
%37 = sext i32 %17 to i64
%38 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %37
store i64 %36, i64* %38
br label %39
39: ; preds = %28, %33, %30, %20, %22
%40 = phi i32 [ %27, %22 ], [ %17, %20 ], [ %17, %33 ], [ %17, %30 ], [ %17, %28 ]
%41 = phi i32 [ 1, %22 ], [ %16, %20 ], [ 0, %33 ], [ 1, %30 ], [ 0, %28 ]
%42 = call i32 @ftell(i32* %9)
%43 = call i32* @fgets(i8* %12, i32 1024, i32* %9)
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %15
45: ; preds = %39, %11
%46 = phi i32 [ 0, %11 ], [ %40, %39 ]
%47 = call i32 @ftell(i32* %9)
%48 = sext i32 %47 to i64
%49 = call i32 @fclose(i32* %9)
br label %52
50: ; preds = %1
%51 = tail call i32 @perror(i8* %0)
br label %52
52: ; preds = %50, %45
%53 = phi i64 [ %48, %45 ], [ 0, %50 ]
%54 = phi i32 [ %46, %45 ], [ 0, %50 ]
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %55, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %54, i8* %0, i64 %53)
%57 = call i32 @dolog(i8* %55)
%58 = sext i32 %54 to i64
%59 = getelementptr inbounds [250000 x i64], [250000 x i64]* %2, i64 0, i64 %58
store i64 %53, i64* %59
%60 = icmp sgt i32 %54, 0
br i1 %60, label %61, label %77
61: ; preds = %52
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = zext i32 %54 to i64
br label %64
64: ; preds = %61, %64
%65 = phi i64 [ %63, %61 ], [ %66, %64 ]
%66 = add nsw i64 %65, -1
%67 = and i64 %66, 4294967295
%68 = getelementptr inbounds [250000 x i64], [250000 x i64]* %2, i64 0, i64 %67
%69 = load i64, i64* %68
%70 = getelementptr inbounds [250000 x i64], [250000 x i64]* %3, i64 0, i64 %65
%71 = load i64, i64* %70
%72 = getelementptr inbounds [250000 x i64], [250000 x i64]* %2, i64 0, i64 %65
%73 = load i64, i64* %72
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %0, i64 %69, i64 %71, i64 %73)
%75 = call i32 @system(i8* %62)
%76 = icmp ugt i64 %65, 1
br i1 %76, label %64, label %77
77: ; preds = %64, %52
ret void
}