#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__ isdigit(char const);
int strlen(char const *);
signed int rindex_nondigit(const char *string) {
  signed int i = strlen(string);
  if (!i)
    return -1;
  for (i--; i >= 0 && isdigit(string[i]); i--)
    ;
  return i;
}


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)
cmpl   $0x0,-0x14(%rbp)
jne    114e <rindex_nondigit+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <rindex_nondigit+0x8a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jl     1181 <rindex_nondigit+0x61>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1191 <rindex_nondigit+0x71>
jmp    11a4 <rindex_nondigit+0x84>
jmp    1196 <rindex_nondigit+0x76>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <rindex_nondigit+0x37>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rindex_nondigit>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
je     1163 <rindex_nondigit+0x43>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%r15
test   %r15d,%r15d
jle    115d <rindex_nondigit+0x3d>
lea    -0x1(%r15),%rbx
mov    %ebx,%eax
movsbl (%r14,%rax,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <rindex_nondigit+0x20>
add    $0xffffffff,%r15d
jmp    1169 <rindex_nondigit+0x49>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
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 i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %32
10: ; preds = %1
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
br label %13
13: ; preds = %27, %10
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %16, %13
%25 = phi i1 [ false, %13 ], [ %23, %16 ]
br i1 %25, label %26, label %30
26: ; preds = %24
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, -1
store i32 %29, i32* %4
br label %13
30: ; preds = %24
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %9
%33 = load i32, i32* %2
ret i32 %33
}

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