#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 int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ ce_utf8_strlen_between(char const *, char const *);
scalar_t__ isblank(char const);
int64_t utf8_strlen_until_trailing_whitespace(const char *str) {
  const char *itr = str;
  while (*itr)
    itr++;
  itr--;
  while (itr > str && *itr && isblank(*itr))
    itr--;
  return ce_utf8_strlen_between(str, itr);
}


x86 assembly (clang, -O0):
<utf8_strlen_until_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1152 <utf8_strlen_until_trailing_whitespace+0x32>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <utf8_strlen_until_trailing_whitespace+0x14>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x11(%rbp)
jbe    119c <utf8_strlen_until_trailing_whitespace+0x7c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     119c <utf8_strlen_until_trailing_whitespace+0x7c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isblank@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11ac <utf8_strlen_until_trailing_whitespace+0x8c>
jmp    11bd <utf8_strlen_until_trailing_whitespace+0x9d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115e <utf8_strlen_until_trailing_whitespace+0x3e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ce_utf8_strlen_between@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_strlen_until_trailing_whitespace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%rcx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x2(%rcx)
lea    0x1(%rcx),%rcx
jne    1130 <utf8_strlen_until_trailing_whitespace+0x10>
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rbx
cmp    %r14,%rcx
jbe    1160 <utf8_strlen_until_trailing_whitespace+0x40>
movzbl (%rbx),%eax
test   %al,%al
je     1160 <utf8_strlen_until_trailing_whitespace+0x40>
movsbl %al,%edi
call   1030 <isblank@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
jne    1140 <utf8_strlen_until_trailing_whitespace+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <ce_utf8_strlen_between@plt>

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

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