#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);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *trim_index(char *destination, char *attribute_name) {
  char *end_ptr;
  strcpy(destination, attribute_name);
  end_ptr = destination + strlen(destination) - 1;
  while (end_ptr != destination) {
    if (isdigit(*end_ptr)) {
      end_ptr--;
      continue;
    }
    if (*end_ptr == '_') {
      *end_ptr = '\0';
      break;
    } else {
      break;
    }
  }
  return destination;
}


x86 assembly (clang, -O0):
<trim_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11c8 <trim_index+0x98>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a7 <trim_index+0x77>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1172 <trim_index+0x42>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    11c3 <trim_index+0x93>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c8 <trim_index+0x98>
jmp    11c8 <trim_index+0x98>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_index>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%rbx
je     1176 <trim_index+0x46>
movsbl -0x1(%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1150 <trim_index+0x20>
cmpb   $0x5f,(%r14,%rbx,1)
jne    1176 <trim_index+0x46>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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