#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 scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ isgraph(int);
uint16_t firstword_length(const char *s) {
  uint16_t ret = 0;
  if (!s) {
    return 0;
  }
  int c;
  while (c = *s++, isgraph(c)) {
    ret++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<firstword_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <firstword_length+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1180 <firstword_length+0x70>
jmp    1141 <firstword_length+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <isgraph@plt>
cmp    $0x0,%eax
je     1178 <firstword_length+0x68>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <firstword_length+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firstword_length>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1145 <firstword_length+0x35>
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <isgraph@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1147 <firstword_length+0x37>
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%r14,%rbx,1),%edi
add    $0x1,%rbx
call   1030 <isgraph@plt>
test   %eax,%eax
jne    1130 <firstword_length+0x20>
jmp    1147 <firstword_length+0x37>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @firstword_length(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = sext i8 %4 to i32
%6 = tail call i32 @isgraph(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %3, %8
%9 = phi i64 [ %12, %8 ], [ 0, %3 ]
%10 = phi i8* [ %11, %8 ], [ %0, %3 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = add nuw nsw i64 %9, 1
%13 = load i8, i8* %11
%14 = sext i8 %13 to i32
%15 = tail call i32 @isgraph(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %3, %1
%18 = phi i64 [ 0, %1 ], [ 0, %3 ], [ %12, %8 ]
ret i64 %18
}