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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  const char pattern[] = "31415926535897932385";
  int found_key = 0;
  int i = 0;
  int j = 0;
  char ch = 0;
  long int count = 0;
  long int result = 0;
  FILE *file = fopen("big_pi_test_with_pi_test", "r");
  int endOfFile = 1;
  while (endOfFile > 0 && !found_key) {
    i = 0;
    ch = 0;
    do {
      endOfFile = fread(&ch, 1, 1, file);
      count++;
      i += j;
      j = 0;
      if (ch == pattern[i]) {
        if (i == (sizeof(pattern) - 2)) {
          found_key = 1;
          result = count - 20;
          break;
        }
        j = 1;
      }
    } while (ch == pattern[i]);
  }
  fprintf(stderr, "idx:%li", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeae(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xea9(%rip),%al
mov    %al,-0x1c(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movb   $0x0,-0x3d(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x58(%rbp)
movl   $0x1,-0x5c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x5c(%rbp)
mov    %al,-0x5d(%rbp)
jle    11d0 <main+0xa0>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    11e0 <main+0xb0>
jmp    127f <main+0x14f>
movl   $0x0,-0x38(%rbp)
movb   $0x0,-0x3d(%rbp)
mov    -0x58(%rbp),%rcx
lea    -0x3d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movsbl -0x3d(%rbp),%eax
movslq -0x38(%rbp),%rcx
movsbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1260 <main+0x130>
movslq -0x38(%rbp),%rax
cmp    $0x13,%rax
jne    1259 <main+0x129>
movl   $0x1,-0x34(%rbp)
mov    -0x48(%rbp),%rax
sub    $0x14,%rax
mov    %rax,-0x50(%rbp)
jmp    127a <main+0x14a>
movl   $0x1,-0x3c(%rbp)
jmp    1265 <main+0x135>
movsbl -0x3d(%rbp),%eax
movslq -0x38(%rbp),%rcx
movsbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     11eb <main+0xbb>
jmp    11b5 <main+0x85>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
lea    0xd9d(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xed3(%rip),%rdi
lea    0xee5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
xor    %eax,%eax
lea    0x7(%rsp),%r15
lea    0xea1(%rip),%r12
movb   $0x0,0x7(%rsp)
add    $0xffffffffffffffec,%rax
mov    %rax,%r13
xor    %ebx,%ebx
xor    %ebp,%ebp
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %ebp,%ecx
mov    %ebx,%ebx
add    %rcx,%rbx
movzbl 0x7(%rsp),%ecx
movzbl (%r12,%rbx,1),%edx
cmp    %dl,%cl
jne    11b0 <main+0x80>
add    $0x1,%r13
mov    $0x1,%ebp
cmp    $0x13,%ebx
jne    1170 <main+0x40>
jmp    11ca <main+0x9a>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
jle    11c7 <main+0x97>
add    $0x15,%r13
mov    %r13,%rax
mov    $0x0,%r13d
cmp    %dl,%cl
jne    115f <main+0x2f>
jmp    11ca <main+0x9a>
xor    %r13d,%r13d
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    %r13,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.pattern = [21 x i8] c"31415926535897932385\00"
@.str = [25 x i8] c"big_pi_test_with_pi_test\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"idx:%li\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [21 x i8]* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8 0, i8* %10
store i64 0, i64* %11
store i64 0, i64* %12
%16 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %13
store i32 1, i32* %14
br label %17
17: ; preds = %61, %2
%18 = load i32, i32* %14
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %26, label %62
26: ; preds = %24
store i32 0, i32* %8
store i8 0, i8* %10
br label %27
27: ; preds = %52, %26
%28 = load i32*, i32** %13
%29 = call i32 @fread(i8* %10, i32 1, i32 1, i32* %28)
store i32 %29, i32* %14
%30 = load i64, i64* %11
%31 = add nsw i64 %30, 1
store i64 %31, i64* %11
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = add nsw i32 %33, %32
store i32 %34, i32* %8
store i32 0, i32* %9
%35 = load i8, i8* %10
%36 = sext i8 %35 to i32
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %36, %41
br i1 %42, label %43, label %51
43: ; preds = %27
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = icmp eq i64 %45, 19
br i1 %46, label %47, label %50
47: ; preds = %43
store i32 1, i32* %7
%48 = load i64, i64* %11
%49 = sub nsw i64 %48, 20
store i64 %49, i64* %12
br label %61
50: ; preds = %43
store i32 1, i32* %9
br label %51
51: ; preds = %50, %27
br label %52
52: ; preds = %51
%53 = load i8, i8* %10
%54 = sext i8 %53 to i32
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %54, %59
br i1 %60, label %27, label %61
61: ; preds = %52, %47
br label %17
62: ; preds = %24
%63 = load i32, i32* @stderr
%64 = load i64, i64* %12
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %64)
ret i32 0
}

LLVM IR (-O2):
@__const.main.pattern = [21 x i8] c"31415926535897932385\00"
@.str = [25 x i8] c"big_pi_test_with_pi_test\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"idx:%li\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %2, %23
%6 = phi i64 [ 0, %2 ], [ %12, %23 ]
store i8 0, i8* %3
br label %7
7: ; preds = %19, %5
%8 = phi i32 [ 0, %5 ], [ %13, %19 ]
%9 = phi i32 [ 0, %5 ], [ 1, %19 ]
%10 = phi i64 [ %6, %5 ], [ %12, %19 ]
%11 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %4)
%12 = add nsw i64 %10, 1
%13 = add nuw nsw i32 %9, %8
%14 = load i8, i8* %3
%15 = zext i32 %13 to i64
%16 = getelementptr inbounds [21 x i8], [21 x i8]* @__const.main.pattern, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %14, %17
br i1 %18, label %19, label %23
19: ; preds = %7
%20 = icmp eq i32 %13, 19
br i1 %20, label %21, label %7
21: ; preds = %19
%22 = add nsw i64 %10, -19
br label %27
23: ; preds = %7
%24 = xor i1 %18, true
%25 = icmp sgt i32 %11, 0
%26 = select i1 %25, i1 %24, i1 false
br i1 %26, label %5, label %27
27: ; preds = %23, %21
%28 = phi i64 [ %22, %21 ], [ 0, %23 ]
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %28)
ret i32 0
}