#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_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int find_partial(char *, int, char const *, int);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int strlen(char const *);
int seek_string(FILE *fp, const char *str) {
  char block[8192];
  int str_at;
  int str_len;
  int size;
  int ret;
  int pos;
  str_len = strlen(str);
  str_at = 0;
  pos = ftell(fp);
  while (!feof(fp)) {
    size = fread(block, 1, 8192, fp);
    if (size < 1)
      break;
    ret = find_partial(block, size, str + str_at, str_len - str_at);
    if (ret != -1) {
      if (str_at + (size - ret) >= str_len) {
        if (fseek(fp, pos + ret - str_at + str_len, SEEK_SET) != 0)
          return 0;
        return 1;
      } else
        str_at += (size - ret);
    }
    pos += size;
  }
  return 0;
}


x86 assembly (clang, -O0):
<seek_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2028(%rbp)
movl   $0x0,-0x2024(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x2034(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b9 <seek_string+0x59>
jmp    12ca <seek_string+0x16a>
lea    -0x2020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %eax,-0x202c(%rbp)
cmpl   $0x1,-0x202c(%rbp)
jge    11eb <seek_string+0x8b>
jmp    12ca <seek_string+0x16a>
lea    -0x2020(%rbp),%rdi
mov    -0x202c(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x2024(%rbp),%rax
add    %rax,%rdx
mov    -0x2028(%rbp),%ecx
sub    -0x2024(%rbp),%ecx
call   1080 <find_partial@plt>
mov    %eax,-0x2030(%rbp)
cmpl   $0xffffffff,-0x2030(%rbp)
je     12b3 <seek_string+0x153>
mov    -0x2024(%rbp),%eax
mov    -0x202c(%rbp),%ecx
sub    -0x2030(%rbp),%ecx
add    %ecx,%eax
cmp    -0x2028(%rbp),%eax
jl     1296 <seek_string+0x136>
mov    -0x10(%rbp),%rdi
mov    -0x2034(%rbp),%esi
add    -0x2030(%rbp),%esi
sub    -0x2024(%rbp),%esi
add    -0x2028(%rbp),%esi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     128a <seek_string+0x12a>
movl   $0x0,-0x4(%rbp)
jmp    12d1 <seek_string+0x171>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <seek_string+0x171>
mov    -0x202c(%rbp),%eax
sub    -0x2030(%rbp),%eax
add    -0x2024(%rbp),%eax
mov    %eax,-0x2024(%rbp)
jmp    12b3 <seek_string+0x153>
mov    -0x202c(%rbp),%eax
add    -0x2034(%rbp),%eax
mov    %eax,-0x2034(%rbp)
jmp    119b <seek_string+0x3b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seek_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <ftell@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1060 <feof@plt>
xor    %ecx,%ecx
test   %eax,%eax
jne    124e <seek_string+0xee>
mov    %r14d,0xc(%rsp)
lea    0x20(%rsp),%rbx
xor    %r14d,%r14d
mov    %r12,0x18(%rsp)
mov    %rbp,0x10(%rsp)
jmp    11d9 <seek_string+0x79>
nopl   0x0(%rax,%rax,1)
add    %r15d,%r13d
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <feof@plt>
test   %eax,%eax
mov    0x18(%rsp),%r12
jne    124c <seek_string+0xec>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    124c <seek_string+0xec>
mov    %eax,%r15d
movslq %r14d,%rax
lea    (%r12,%rax,1),%rdx
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
mov    %ebp,%r12d
sub    %eax,%r12d
mov    %r15d,%esi
mov    %r12d,%ecx
call   1080 <find_partial@plt>
cmp    $0xffffffff,%eax
je     11c0 <seek_string+0x60>
mov    %r15d,%ecx
sub    %eax,%ecx
add    %ecx,%r14d
cmp    %ebp,%r14d
jl     11c0 <seek_string+0x60>
add    %r13d,%r12d
add    %eax,%r12d
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
mov    0x10(%rsp),%rdi
mov    %r12d,%esi
call   1070 <fseek@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
jmp    124e <seek_string+0xee>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @seek_string(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [8192 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %8
store i32 0, i32* %7
%14 = load i32*, i32** %4
%15 = call i32 @ftell(i32* %14)
store i32 %15, i32* %11
br label %16
16: ; preds = %70, %2
%17 = load i32*, i32** %4
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %74
21: ; preds = %16
%22 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%23 = load i32*, i32** %4
%24 = call i32 @fread(i8* %22, i32 1, i32 8192, i32* %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %21
br label %74
28: ; preds = %21
%29 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %9
%31 = load i8*, i8** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = sub nsw i32 %35, %36
%38 = call i32 @find_partial(i8* %29, i32 %30, i8* %34, i32 %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %70
41: ; preds = %28
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = sub nsw i32 %43, %44
%46 = add nsw i32 %42, %45
%47 = load i32, i32* %8
%48 = icmp sge i32 %46, %47
br i1 %48, label %49, label %63
49: ; preds = %41
%50 = load i32*, i32** %4
%51 = load i32, i32* %11
%52 = load i32, i32* %10
%53 = add nsw i32 %51, %52
%54 = load i32, i32* %7
%55 = sub nsw i32 %53, %54
%56 = load i32, i32* %8
%57 = add nsw i32 %55, %56
%58 = load i32, i32* @SEEK_SET
%59 = call i64 @fseek(i32* %50, i32 %57, i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %49
store i32 0, i32* %3
br label %75
62: ; preds = %49
store i32 1, i32* %3
br label %75
63: ; preds = %41
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = sub nsw i32 %64, %65
%67 = load i32, i32* %7
%68 = add nsw i32 %67, %66
store i32 %68, i32* %7
br label %69
69: ; preds = %63
br label %70
70: ; preds = %69, %28
%71 = load i32, i32* %9
%72 = load i32, i32* %11
%73 = add nsw i32 %72, %71
store i32 %73, i32* %11
br label %16
74: ; preds = %27, %16
store i32 0, i32* %3
br label %75
75: ; preds = %74, %62, %61
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @seek_string(i32* nocapture %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @ftell(i32* %0)
%7 = call i32 @feof(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %2, %31
%10 = phi i32 [ %33, %31 ], [ %6, %2 ]
%11 = phi i32 [ %32, %31 ], [ 0, %2 ]
%12 = call i32 @fread(i8* %4, i32 1, i32 8192, i32* %0)
%13 = icmp slt i32 %12, 1
br i1 %13, label %36, label %14
14: ; preds = %9
%15 = sext i32 %11 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = sub i32 %5, %11
%18 = call i32 @find_partial(i8* %4, i32 %12, i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %31, label %20
20: ; preds = %14
%21 = sub nsw i32 %12, %18
%22 = add nsw i32 %21, %11
%23 = icmp slt i32 %22, %5
br i1 %23, label %31, label %24
24: ; preds = %20
%25 = add i32 %17, %10
%26 = add i32 %25, %18
%27 = load i32, i32* @SEEK_SET
%28 = call i64 @fseek(i32* %0, i32 %26, i32 %27)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
br label %36
31: ; preds = %20, %14
%32 = phi i32 [ %11, %14 ], [ %22, %20 ]
%33 = add nsw i32 %12, %10
%34 = call i32 @feof(i32* %0)
%35 = icmp eq i32 %34, 0
br i1 %35, label %9, label %36
36: ; preds = %9, %31, %2, %24
%37 = phi i32 [ %30, %24 ], [ 0, %2 ], [ 0, %31 ], [ 0, %9 ]
ret i32 %37
}