#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__ mapred_ischar_delim(int);
size_t mapred_backward_token_len(const char *data, size_t size) {
  size_t sz = size;
  while (sz) {
    int c = data[sz - 1];
    if (!c)
      break;
    if (mapred_ischar_delim(c))
      break;
    sz--;
  }
  return size - sz;
}


x86 assembly (clang, -O0):
<mapred_backward_token_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117d <mapred_backward_token_len+0x6d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1155 <mapred_backward_token_len+0x45>
jmp    117d <mapred_backward_token_len+0x6d>
mov    -0x1c(%rbp),%edi
call   1030 <mapred_ischar_delim@plt>
cmp    $0x0,%rax
je     116c <mapred_backward_token_len+0x5c>
jmp    117d <mapred_backward_token_len+0x6d>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <mapred_backward_token_len+0x18>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapred_backward_token_len>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    (%rsi,%rdi,1),%r15
add    $0xffffffffffffffff,%r15
neg    %r14
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rcx,%rbx
cmp    %rcx,%r14
je     114f <mapred_backward_token_len+0x3f>
movsbl (%r15,%rbx,1),%edi
test   %edi,%edi
je     114f <mapred_backward_token_len+0x3f>
call   1030 <mapred_ischar_delim@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
je     1130 <mapred_backward_token_len+0x20>
neg    %rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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