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

/* Variables and functions */
int strlen(char *);
int words_count_region(char *, int, int);
int find_sentence_of_length(char *text, int sentence_length, int *found_start,
                            int *found_end) {
  int i, start_pos = 0, end_pos, line_number = 0;
  int length = strlen(text);
  for (i = 0; i < length; i++) {
    if ((text[i] == '.') || (i == length - 1)) {
      end_pos = i;
      if (words_count_region(text, start_pos, end_pos) == sentence_length) {
        *found_start = start_pos;
        *found_end = end_pos;
        return line_number;
      }
      start_pos = end_pos + 1;
    }
    if (text[i] == 13)
      line_number++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_sentence_of_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11ff <find_sentence_of_length+0xdf>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     118a <find_sentence_of_length+0x6a>
mov    -0x2c(%rbp),%eax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11ce <find_sentence_of_length+0xae>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1030 <words_count_region@plt>
cmp    -0x14(%rbp),%eax
jne    11c5 <find_sentence_of_length+0xa5>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <find_sentence_of_length+0xe6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    11ec <find_sentence_of_length+0xcc>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11f1 <find_sentence_of_length+0xd1>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1158 <find_sentence_of_length+0x38>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_sentence_of_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %esi,0x4(%rsp)
mov    %rdi,%r13
call   1040 <strlen@plt>
test   %eax,%eax
jle    11a3 <find_sentence_of_length+0x83>
mov    %rbp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
lea    -0x1(%rax),%r15d
mov    %eax,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1172 <find_sentence_of_length+0x52>
xchg   %ax,%ax
add    $0x1,%rbx
xor    %ecx,%ecx
cmp    $0xd,%al
sete   %cl
add    %ecx,%ebp
cmp    %r12,%rbx
je     11a3 <find_sentence_of_length+0x83>
movzbl 0x0(%r13,%rbx,1),%eax
cmp    $0x2e,%al
je     1181 <find_sentence_of_length+0x61>
cmp    %r15,%rbx
jne    1160 <find_sentence_of_length+0x40>
mov    %r13,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <words_count_region@plt>
cmp    0x4(%rsp),%eax
je     11aa <find_sentence_of_length+0x8a>
movzbl 0x0(%r13,%rbx,1),%eax
add    $0x1,%rbx
mov    %ebx,%r14d
jmp    1164 <find_sentence_of_length+0x44>
mov    $0xffffffff,%ebp
jmp    11b9 <find_sentence_of_length+0x99>
mov    0x8(%rsp),%rax
mov    %r14d,(%rax)
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_sentence_of_length(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %11
store i32 0, i32* %13
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %14
store i32 0, i32* %10
br label %17
17: ; preds = %63, %4
%18 = load i32, i32* %10
%19 = load i32, i32* %14
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %66
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 46
br i1 %28, label %34, label %29
29: ; preds = %21
%30 = load i32, i32* %10
%31 = load i32, i32* %14
%32 = sub nsw i32 %31, 1
%33 = icmp eq i32 %30, %32
br i1 %33, label %34, label %51
34: ; preds = %29, %21
%35 = load i32, i32* %10
store i32 %35, i32* %12
%36 = load i8*, i8** %6
%37 = load i32, i32* %11
%38 = load i32, i32* %12
%39 = call i32 @words_count_region(i8* %36, i32 %37, i32 %38)
%40 = load i32, i32* %7
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i32, i32* %11
%44 = load i32*, i32** %8
store i32 %43, i32* %44
%45 = load i32, i32* %12
%46 = load i32*, i32** %9
store i32 %45, i32* %46
%47 = load i32, i32* %13
store i32 %47, i32* %5
br label %67
48: ; preds = %34
%49 = load i32, i32* %12
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %51
51: ; preds = %48, %29
%52 = load i8*, i8** %6
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 13
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %62
62: ; preds = %59, %51
br label %63
63: ; preds = %62
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %17
66: ; preds = %17
store i32 -1, i32* %5
br label %67
67: ; preds = %66, %42
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
define i32 @find_sentence_of_length(i8* %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %4
%8 = add nsw i32 %5, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %5 to i64
br label %11
11: ; preds = %7, %32
%12 = phi i64 [ 0, %7 ], [ %33, %32 ]
%13 = phi i32 [ 0, %7 ], [ %38, %32 ]
%14 = phi i32 [ 0, %7 ], [ %35, %32 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %12
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 46
%18 = icmp eq i64 %12, %9
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %22, label %20
20: ; preds = %11
%21 = add nuw nsw i64 %12, 1
br label %32
22: ; preds = %11
%23 = trunc i64 %12 to i32
%24 = tail call i32 @words_count_region(i8* %0, i32 %14, i32 %23)
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = trunc i64 %12 to i32
store i32 %14, i32* %2
store i32 %27, i32* %3
br label %40
28: ; preds = %22
%29 = add nuw nsw i64 %12, 1
%30 = trunc i64 %29 to i32
%31 = load i8, i8* %15
br label %32
32: ; preds = %20, %28
%33 = phi i64 [ %21, %20 ], [ %29, %28 ]
%34 = phi i8 [ %16, %20 ], [ %31, %28 ]
%35 = phi i32 [ %14, %20 ], [ %30, %28 ]
%36 = icmp eq i8 %34, 13
%37 = zext i1 %36 to i32
%38 = add nuw nsw i32 %13, %37
%39 = icmp eq i64 %33, %10
br i1 %39, label %40, label %11
40: ; preds = %32, %4, %26
%41 = phi i32 [ %13, %26 ], [ -1, %4 ], [ -1, %32 ]
ret i32 %41
}