#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*/ ReadWord(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long long, int /*<<< orphan*/);
scalar_t__ isEndOfSentence(char *);
long long findStartOfLine(char *file, long long start) {
  char word[100];
  if (start == 0)
    return 0;
  while (start != 0) {
    FILE *fi = fopen(file, "rb");
    fseek(fi, start, SEEK_SET);
    ReadWord(word, fi);
    if (isEndOfSentence(word)) {
      fclose(fi);
      return start + 1;
    }
    fclose(fi);
    start--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<findStartOfLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <findStartOfLine+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    1220 <findStartOfLine+0xd0>
jmp    1180 <findStartOfLine+0x30>
cmpq   $0x0,-0x18(%rbp)
je     1218 <findStartOfLine+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rsi
call   1050 <ReadWord@plt>
lea    -0x80(%rbp),%rdi
call   1070 <isEndOfSentence@plt>
cmp    $0x0,%rax
je     11fb <findStartOfLine+0xab>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <findStartOfLine+0xd0>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1180 <findStartOfLine+0x30>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findStartOfLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
test   %rsi,%rsi
je     11c9 <findStartOfLine+0x79>
mov    %rsi,%r13
mov    %rdi,%r14
mov    0x2e70(%rip),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    (%r15),%edx
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <fseek@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <ReadWord@plt>
mov    %r12,%rdi
call   1070 <isEndOfSentence@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rbp,%rbp
jne    11ce <findStartOfLine+0x7e>
add    $0xffffffffffffffff,%r13
jne    1180 <findStartOfLine+0x30>
xor    %r13d,%r13d
jmp    11d2 <findStartOfLine+0x82>
add    $0x1,%r13
mov    %r13,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i64 @findStartOfLine(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [100 x i8]
%7 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 0, i64* %3
br label %39
11: ; preds = %2
br label %12
12: ; preds = %33, %11
%13 = load i64, i64* %5
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = load i64, i64* %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %18, i64 %19, i32 %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = load i32*, i32** %7
%24 = call i32 @ReadWord(i8* %22, i32* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%26 = call i64 @isEndOfSentence(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %15
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
%31 = load i64, i64* %5
%32 = add nsw i64 %31, 1
store i64 %32, i64* %3
br label %39
33: ; preds = %15
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i64, i64* %5
%37 = add nsw i64 %36, -1
store i64 %37, i64* %5
br label %12
38: ; preds = %12
store i64 0, i64* %3
br label %39
39: ; preds = %38, %28, %10
%40 = load i64, i64* %3
ret i64 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i64 @findStartOfLine(i8* nocapture %0, i64 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i64 %1, 0
br i1 %5, label %20, label %6
6: ; preds = %2, %17
%7 = phi i64 [ %18, %17 ], [ %1, %2 ]
%8 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %8, i64 %7, i32 %9)
%11 = call i32 @ReadWord(i8* %4, i32* %8)
%12 = call i64 @isEndOfSentence(i8* %4)
%13 = icmp eq i64 %12, 0
%14 = call i32 @fclose(i32* %8)
br i1 %13, label %17, label %15
15: ; preds = %6
%16 = add nsw i64 %7, 1
br label %20
17: ; preds = %6
%18 = add nsw i64 %7, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %6
20: ; preds = %17, %15, %2
%21 = phi i64 [ 0, %2 ], [ %16, %15 ], [ 0, %17 ]
ret i64 %21
}