#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__ isalpha(char const);
size_t ends_at(const char *const str, size_t starts_at) {
  size_t i = starts_at;
  do {
    while (isalpha(str[++i]))
      ;
  } while (str[i] == '-' && isalpha(str[i + 1]));
  return i;
}


x86 assembly (clang, -O0):
<ends_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    112d <ends_at+0x1d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <isalpha@plt>
cmp    $0x0,%rax
je     1159 <ends_at+0x49>
jmp    112d <ends_at+0x1d>
jmp    115e <ends_at+0x4e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2d,%ecx
mov    %al,-0x19(%rbp)
jne    1194 <ends_at+0x84>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <isalpha@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1128 <ends_at+0x18>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ends_at>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movsbl (%r14,%rbx,1),%edi
call   1030 <isalpha@plt>
test   %rax,%rax
jne    1120 <ends_at+0x10>
cmpb   $0x2d,(%r14,%rbx,1)
jne    114a <ends_at+0x3a>
movsbl 0x1(%r14,%rbx,1),%edi
call   1030 <isalpha@plt>
test   %rax,%rax
jne    1120 <ends_at+0x10>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @ends_at(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
store i64 %6, i64* %5
br label %7
7: ; preds = %33, %2
br label %8
8: ; preds = %16, %7
%9 = load i8*, i8** %3
%10 = load i64, i64* %5
%11 = add i64 %10, 1
store i64 %11, i64* %5
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = call i64 @isalpha(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %8
br label %8
17: ; preds = %8
br label %18
18: ; preds = %17
%19 = load i8*, i8** %3
%20 = load i64, i64* %5
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = load i64, i64* %5
%28 = add i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i64 @isalpha(i8 signext %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %25, %18
%34 = phi i1 [ false, %18 ], [ %32, %25 ]
br i1 %34, label %7, label %35
35: ; preds = %33
%36 = load i64, i64* %5
ret i64 %36
}

LLVM IR (-O2):
define i64 @ends_at(i8* nocapture %0, i64 %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i64 [ %1, %2 ], [ %5, %10 ]
%5 = add i64 %4, 1
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i64 @isalpha(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %3, %15
br label %3
11: ; preds = %3
%12 = getelementptr inbounds i8, i8* %0, i64 %5
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 45
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = add i64 %4, 2
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @isalpha(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %11, %15
ret i64 %5
}