#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*/ isdigit(char);
int strlen(char *);
int rindex_nondigit(char *name) {
  int pos = strlen(name);
  for (pos = strlen(name); pos > 0; pos--) {
    if (!isdigit(name[pos - 1]))
      return pos;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rindex_nondigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    118b <rindex_nondigit+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1178 <rindex_nondigit+0x58>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <rindex_nondigit+0x72>
jmp    117d <rindex_nondigit+0x5d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <rindex_nondigit+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rindex_nondigit>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    115c <rindex_nondigit+0x3c>
movsbl -0x1(%r14,%rbx,1),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1140 <rindex_nondigit+0x20>
add    $0x1,%ebx
jmp    115e <rindex_nondigit+0x3e>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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