#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 */
scalar_t__ word_terminator(char, char);
int words_count_region(char *text, int start_pos, int end_pos) {
  int i, words = 0;
  if (end_pos - start_pos < 2)
    return 0;
  for (i = start_pos; i < end_pos - 1; i++) {
    if (word_terminator(text[i], text[i + 1]) != 0) {
      words++;
    }
  }
  return words;
}


x86 assembly (clang, -O0):
<words_count_region>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x2,%eax
jge    1144 <words_count_region+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11ab <words_count_region+0x9b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a5 <words_count_region+0x95>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <word_terminator@plt>
cmp    $0x0,%rax
je     1192 <words_count_region+0x82>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <words_count_region+0x87>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <words_count_region+0x3a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<words_count_region>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%eax
sub    %esi,%eax
xor    %ebp,%ebp
cmp    $0x2,%eax
jl     1160 <words_count_region+0x50>
add    $0xffffffff,%edx
cmp    %esi,%edx
jle    1160 <words_count_region+0x50>
mov    %rdi,%r14
movslq %esi,%rbx
movslq %edx,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r14,%rbx,1),%edi
movsbl 0x1(%r14,%rbx,1),%esi
add    $0x1,%rbx
call   1030 <word_terminator@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
cmp    %rbx,%r15
jne    1140 <words_count_region+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @words_count_region(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %9
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %45
15: ; preds = %3
%16 = load i32, i32* %6
store i32 %16, i32* %8
br label %17
17: ; preds = %40, %15
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = sub nsw i32 %19, 1
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = call i64 @word_terminator(i8 signext %27, i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %22
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %39
39: ; preds = %36, %22
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %17
43: ; preds = %17
%44 = load i32, i32* %9
store i32 %44, i32* %4
br label %45
45: ; preds = %43, %14
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
define i32 @words_count_region(i8* nocapture %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = icmp slt i32 %4, 2
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = add i32 %2, -1
%8 = icmp sgt i32 %7, %1
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = sext i32 %1 to i64
%11 = sext i32 %7 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ %10, %9 ], [ %17, %12 ]
%14 = phi i32 [ 0, %9 ], [ %23, %12 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = add nsw i64 %13, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i64 @word_terminator(i8 signext %16, i8 signext %19)
%21 = icmp ne i64 %20, 0
%22 = zext i1 %21 to i32
%23 = add nuw nsw i32 %14, %22
%24 = icmp eq i64 %17, %11
br i1 %24, label %25, label %12
25: ; preds = %12, %6, %3
%26 = phi i32 [ 0, %3 ], [ 0, %6 ], [ %23, %12 ]
ret i32 %26
}