#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*/ isspace(char);
unsigned int strlen(char *);
unsigned int endIndex(char *value) {
  unsigned int end = strlen(value);
  if (end == 1) {
    return 1;
  }
  for (unsigned int i = end - 1; i > 0; i--) {
    if (!isspace(value[i])) {
      end = i + 1;
      break;
    }
  }
  return end;
}


x86 assembly (clang, -O0):
<endIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    114e <endIndex+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <endIndex+0x81>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jbe    119b <endIndex+0x7b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1188 <endIndex+0x68>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <endIndex+0x7b>
jmp    118d <endIndex+0x6d>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <endIndex+0x37>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endIndex>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
je     116d <endIndex+0x4d>
mov    %eax,%r14d
lea    0x1(%r14),%ebp
add    $0xffffffff,%eax
add    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x2,%ebp
je     116a <endIndex+0x4a>
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    1150 <endIndex+0x30>
jmp    116d <endIndex+0x4d>
mov    %r14d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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