#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 /*<<< orphan*/ isalpha(char);
int pgn_read_until_move(char *buffer, int index) {
  for (; !isalpha(buffer[index]) && buffer[index] != '\0'; index++)
    ;
  return index;
}


x86 assembly (clang, -O0):
<pgn_read_until_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isalpha@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jne    1155 <pgn_read_until_move+0x45>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1165 <pgn_read_until_move+0x55>
jmp    1178 <pgn_read_until_move+0x68>
jmp    116a <pgn_read_until_move+0x5a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    111f <pgn_read_until_move+0xf>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgn_read_until_move>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
movslq %esi,%rbp
movsbl (%rdi,%rbp,1),%edi
call   1030 <isalpha@plt>
test   %eax,%eax
jne    114b <pgn_read_until_move+0x3b>
jmp    1142 <pgn_read_until_move+0x32>
nopl   0x0(%rax)
movsbl 0x1(%rbx,%rbp,1),%edi
add    $0x1,%rbp
call   1030 <isalpha@plt>
test   %eax,%eax
jne    1148 <pgn_read_until_move+0x38>
cmpb   $0x0,(%rbx,%rbp,1)
jne    1130 <pgn_read_until_move+0x20>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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