#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ abs(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  int logo[84] = {0, 0, 0, 0, 0, 3, 3, 9, 9, 9, 6, 0, 0, 0, 0, 0, 0,
                  3, 4, 9, 5, 9, 9, 9, 9, 4, 0, 0, 0, 1, 2, 7, 5, 9,
                  5, 9, 9, 9, 9, 7, 1, 0, 3, 9, 5, 9, 5, 9, 5, 9, 9,
                  9, 9, 9, 9, 3, 6, 9, 5, 9, 5, 9, 5, 9, 9, 9, 9, 9,
                  9, 6, 1, 8, 5, 9, 5, 9, 5, 9, 9, 9, 9, 9, 8, 1};
  char buffer[1000000];
  FILE *fp;
  int offset;
  int evaluation;
  int x;
  int chunk_number = 0;
  int chunk_size = 1000000;
  fp = fopen("pi-billion.txt", "r");
  if (fp == NULL) {
    printf("Could not open file 'pi-billion.txt'\n");
    return 1;
  }
  fseek(fp, 2, SEEK_SET);
  while (fgets(buffer, 1000000, fp) != NULL) {
    if (feof(fp)) {
      chunk_size = strlen(buffer);
    } else {
      fseek(fp, -82, SEEK_CUR);
    }
    offset = 0;
    while (offset + 84 <= chunk_size) {
      evaluation = 0;
      for (x = 0; x < 84; x++) {
        evaluation += abs(logo[x] - (buffer[offset + x] - '0'));
        if (evaluation > 194) {
          break;
        }
      }
      if (evaluation <= 194) {
        printf("eval: %d | offset: %d | sequence: %.84s\n", evaluation,
               (1000000 - 83) * chunk_number + offset + 1, &(buffer[offset]));
      }
      offset++;
    }
    chunk_number++;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf43c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x160(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x150,%edx
call   1090 <memcpy@plt>
movl   $0x0,-0xf43b8(%rbp)
movl   $0xf4240,-0xf43bc(%rbp)
lea    0xf7b(%rip),%rdi
lea    0xf83(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xf43a8(%rbp)
cmpq   $0x0,-0xf43a8(%rbp)
jne    1210 <main+0x80>
lea    0xf64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c5 <main+0x235>
mov    -0xf43a8(%rbp),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   10a0 <fseek@plt>
lea    -0xf43a0(%rbp),%rdi
mov    -0xf43a8(%rbp),%rdx
mov    $0xf4240,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     13b2 <main+0x222>
mov    -0xf43a8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1279 <main+0xe9>
lea    -0xf43a0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xf43bc(%rbp)
jmp    1293 <main+0x103>
mov    -0xf43a8(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffae,%esi
call   10a0 <fseek@plt>
movl   $0x0,-0xf43ac(%rbp)
mov    -0xf43ac(%rbp),%eax
add    $0x54,%eax
cmp    -0xf43bc(%rbp),%eax
jg     139e <main+0x20e>
movl   $0x0,-0xf43b0(%rbp)
movl   $0x0,-0xf43b4(%rbp)
cmpl   $0x54,-0xf43b4(%rbp)
jge    1342 <main+0x1b2>
movslq -0xf43b4(%rbp),%rax
mov    -0x160(%rbp,%rax,4),%edi
mov    -0xf43ac(%rbp),%eax
add    -0xf43b4(%rbp),%eax
cltq
movsbl -0xf43a0(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
sub    %eax,%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0xf43b0(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xf43b0(%rbp)
cmpl   $0xc2,-0xf43b0(%rbp)
jle    1329 <main+0x199>
jmp    1342 <main+0x1b2>
jmp    132e <main+0x19e>
mov    -0xf43b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf43b4(%rbp)
jmp    12c6 <main+0x136>
cmpl   $0xc2,-0xf43b0(%rbp)
jg     138a <main+0x1fa>
mov    -0xf43b0(%rbp),%esi
imul   $0xf41ed,-0xf43b8(%rbp),%edx
add    -0xf43ac(%rbp),%edx
add    $0x1,%edx
movslq -0xf43ac(%rbp),%rax
lea    -0xf43a0(%rbp),%rcx
add    %rax,%rcx
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xf43ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf43ac(%rbp)
jmp    129d <main+0x10d>
mov    -0xf43b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf43b8(%rbp)
jmp    122a <main+0x9a>
mov    -0xf43a8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf43c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf4268,%rsp
lea    0xfa8(%rip),%rdi
lea    0xfb0(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     134e <main+0x1be>
mov    %rax,%rbx
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   10a0 <fseek@plt>
lea    0x20(%rsp),%rdi
mov    $0xf4240,%ebp
mov    $0xf4240,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1342 <main+0x1b2>
lea    0xe03(%rip),%r14
movl   $0x0,0x8(%rsp)
mov    %rbx,0x10(%rsp)
jmp    1235 <main+0xa5>
nopl   0x0(%rax)
addl   $0x1,0x8(%rsp)
lea    0x20(%rsp),%rdi
mov    $0xf4240,%esi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1342 <main+0x1b2>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1260 <main+0xd0>
lea    0x20(%rsp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
cmp    $0x54,%ebp
jl     1210 <main+0x80>
jmp    127b <main+0xeb>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffae,%esi
call   10a0 <fseek@plt>
cmp    $0x54,%ebp
jl     1210 <main+0x80>
imul   $0xf41ed,0x8(%rsp),%eax
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
mov    %ebp,0xc(%rsp)
jmp    12b8 <main+0x128>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%r15),%r12
add    $0x55,%r15d
mov    0xc(%rsp),%ebp
cmp    %ebp,%r15d
mov    %r12,%r15
jg     1210 <main+0x80>
lea    (%rsp,%r15,1),%rbx
add    $0x20,%rbx
xor    %ebp,%ebp
mov    $0x1,%r12d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r13d
mov    -0x4(%r14,%r12,4),%edi
movsbl -0x1(%rbx,%r12,1),%eax
sub    %eax,%edi
add    $0x30,%edi
call   1040 <abs@plt>
mov    %rax,%rbp
add    %r13d,%ebp
cmp    $0xc2,%ebp
jg     12a0 <main+0x110>
mov    (%r14,%r12,4),%edi
movsbl (%rbx,%r12,1),%eax
sub    %eax,%edi
add    $0x30,%edi
call   1040 <abs@plt>
add    %eax,%ebp
cmp    $0xc2,%ebp
jg     12a0 <main+0x110>
add    $0x2,%r12
cmp    $0x55,%r12
jne    12d0 <main+0x140>
lea    0x1(%r15),%r12
mov    0x18(%rsp),%rax
lea    (%rax,%r12,1),%edx
lea    0xe30(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a4 <main+0x114>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    135f <main+0x1cf>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0xf4268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.logo = [84 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 3, i32 3, i32 9, i32 9, i32 9, i32 6, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 3, i32 4, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 4, i32 0, i32 0, i32 0, i32 1, i32 2, i32 7, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 7, i32 1, i32 0, i32 3, i32 9, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 3, i32 6, i32 9, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 6, i32 1, i32 8, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 8, i32 1]
@.str = [15 x i8] c"pi-billion.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"Could not open file 'pi-billion.txt'\0A\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.3 = [41 x i8] c"eval: %d | offset: %d | sequence: %.84s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [84 x i32]
%3 = alloca [1000000 x i8]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [84 x i32]* %2 to i8*
store i32 0, i32* %8
store i32 1000000, i32* %9
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %95
16: ; preds = %0
%17 = load i32*, i32** %4
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %17, i32 2, i32 %18)
br label %20
20: ; preds = %89, %16
%21 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i32* @fgets(i8* %21, i32 1000000, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %92
25: ; preds = %20
%26 = load i32*, i32** %4
%27 = call i64 @feof(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %3, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %9
br label %36
32: ; preds = %25
%33 = load i32*, i32** %4
%34 = load i32, i32* @SEEK_CUR
%35 = call i32 @fseek(i32* %33, i32 -82, i32 %34)
br label %36
36: ; preds = %32, %29
store i32 0, i32* %5
br label %37
37: ; preds = %86, %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 84
%40 = load i32, i32* %9
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %89
42: ; preds = %37
store i32 0, i32* %6
store i32 0, i32* %7
br label %43
43: ; preds = %69, %42
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 84
br i1 %45, label %46, label %72
46: ; preds = %43
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [84 x i32], [84 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = load i32, i32* %5
%52 = load i32, i32* %7
%53 = add nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %3, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = sub nsw i32 %57, 48
%59 = sub nsw i32 %50, %58
%60 = call i64 @abs(i32 %59)
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = add nsw i64 %62, %60
%64 = trunc i64 %63 to i32
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp sgt i32 %65, 194
br i1 %66, label %67, label %68
67: ; preds = %46
br label %72
68: ; preds = %46
br label %69
69: ; preds = %68
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %43
72: ; preds = %67, %43
%73 = load i32, i32* %6
%74 = icmp sle i32 %73, 194
br i1 %74, label %75, label %86
75: ; preds = %72
%76 = load i32, i32* %6
%77 = load i32, i32* %8
%78 = mul nsw i32 999917, %77
%79 = load i32, i32* %5
%80 = add nsw i32 %78, %79
%81 = add nsw i32 %80, 1
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %3, i64 0, i64 %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %76, i32 %81, i8* %84)
br label %86
86: ; preds = %75, %72
%87 = load i32, i32* %5
%88 = add nsw i32 %87, 1
store i32 %88, i32* %5
br label %37
89: ; preds = %37
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %20
92: ; preds = %20
%93 = load i32*, i32** %4
%94 = call i32 @fclose(i32* %93)
store i32 0, i32* %1
br label %95
95: ; preds = %92, %14
%96 = load i32, i32* %1
ret i32 %96
}

LLVM IR (-O2):
@__const.main.logo = [84 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 3, i32 3, i32 9, i32 9, i32 9, i32 6, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 3, i32 4, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 4, i32 0, i32 0, i32 0, i32 1, i32 2, i32 7, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 7, i32 1, i32 0, i32 3, i32 9, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 3, i32 6, i32 9, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 6, i32 1, i32 8, i32 5, i32 9, i32 5, i32 9, i32 5, i32 9, i32 9, i32 9, i32 9, i32 9, i32 8, i32 1]
@.str = [15 x i8] c"pi-billion.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.3 = [41 x i8] c"eval: %d | offset: %d | sequence: %.84s\0A\00"
@str = [37 x i8] c"Could not open file 'pi-billion.txt'\00"
define i32 @main() {
%1 = alloca [1000000 x i8]
%2 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %80
7: ; preds = %0
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %3, i32 2, i32 %8)
%10 = call i32* @fgets(i8* %2, i32 1000000, i32* %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %78, label %12
12: ; preds = %7, %74
%13 = phi i32 [ %23, %74 ], [ 1000000, %7 ]
%14 = phi i32 [ %75, %74 ], [ 0, %7 ]
%15 = call i64 @feof(i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @strlen(i8* %2)
br label %22
19: ; preds = %12
%20 = load i32, i32* @SEEK_CUR
%21 = call i32 @fseek(i32* %3, i32 -82, i32 %20)
br label %22
22: ; preds = %19, %17
%23 = phi i32 [ %18, %17 ], [ %13, %19 ]
%24 = icmp slt i32 %23, 84
br i1 %24, label %74, label %25
25: ; preds = %22
%26 = mul nsw i32 %14, 999917
br label %27
27: ; preds = %25, %69
%28 = phi i64 [ 0, %25 ], [ %70, %69 ]
br label %46
29: ; preds = %46
%30 = or i64 %47, 1
%31 = getelementptr inbounds [84 x i32], [84 x i32]* @__const.main.logo, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add nuw nsw i64 %30, %28
%34 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = add i32 %32, 48
%38 = sub i32 %37, %36
%39 = call i64 @abs(i32 %38)
%40 = trunc i64 %39 to i32
%41 = add i32 %59, %40
%42 = icmp sgt i32 %41, 194
br i1 %42, label %67, label %43
43: ; preds = %29
%44 = add nuw nsw i64 %47, 2
%45 = icmp eq i64 %44, 84
br i1 %45, label %61, label %46
46: ; preds = %43, %27
%47 = phi i64 [ 0, %27 ], [ %44, %43 ]
%48 = phi i32 [ 0, %27 ], [ %41, %43 ]
%49 = getelementptr inbounds [84 x i32], [84 x i32]* @__const.main.logo, i64 0, i64 %47
%50 = load i32, i32* %49
%51 = add nuw nsw i64 %47, %28
%52 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = add i32 %50, 48
%56 = sub i32 %55, %54
%57 = call i64 @abs(i32 %56)
%58 = trunc i64 %57 to i32
%59 = add i32 %48, %58
%60 = icmp sgt i32 %59, 194
br i1 %60, label %67, label %29
61: ; preds = %43
%62 = add nuw i64 %28, 1
%63 = trunc i64 %62 to i32
%64 = add i32 %26, %63
%65 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 %28
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %64, i8* %65)
br label %69
67: ; preds = %29, %46
%68 = add nuw i64 %28, 1
br label %69
69: ; preds = %67, %61
%70 = phi i64 [ %68, %67 ], [ %62, %61 ]
%71 = trunc i64 %28 to i32
%72 = add i32 %71, 85
%73 = icmp sgt i32 %72, %23
br i1 %73, label %74, label %27
74: ; preds = %69, %22
%75 = add nuw nsw i32 %14, 1
%76 = call i32* @fgets(i8* %2, i32 1000000, i32* %3)
%77 = icmp eq i32* %76, null
br i1 %77, label %78, label %12
78: ; preds = %74, %7
%79 = call i32 @fclose(i32* %3)
br label %80
80: ; preds = %78, %5
%81 = phi i32 [ 1, %5 ], [ 0, %78 ]
ret i32 %81
}