#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 atoi(char *);
scalar_t__ isdigit(char);
int strlen(char *);
int get_index(char *attribute_name) {
  char *end_ptr;
  end_ptr = attribute_name + strlen(attribute_name) - 1;
  while (end_ptr != attribute_name) {
    if (isdigit(*end_ptr)) {
      end_ptr--;
      continue;
    }
    if (*end_ptr == '_') {
      end_ptr++;
      break;
    } else
      break;
  }
  return atoi(end_ptr);
}


x86 assembly (clang, -O0):
<get_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11bc <get_index+0x8c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1196 <get_index+0x66>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1161 <get_index+0x31>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    11b7 <get_index+0x87>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11bc <get_index+0x8c>
jmp    11bc <get_index+0x8c>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%r15
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     1178 <get_index+0x48>
movsbl -0x1(%r15),%edi
add    $0xffffffffffffffff,%r15
call   1030 <isdigit@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1150 <get_index+0x20>
lea    0x1(%r15),%r14
cmpb   $0x5f,(%r15)
cmovne %r15,%r14
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <atoi@plt>

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

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