#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 */
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strpbrk(char *, char *);
char *strrchr(char *, char);
int strspn(char *, char *);
void chop_version(char *arg) {
  char *cp;
  cp = strchr(arg, '\t');
  if (cp)
    *cp = '\0';
  for (;;) {
    int len;
    cp = strrchr(arg, 'R');
    if (!cp || cp <= arg + 1 || cp[-1] != '_')
      break;
    len = strlen(cp);
    if (len < 9)
      break;
    if (strpbrk(cp + 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
      break;
    if (strspn(cp + len - 8, "0123456789abcdef") != 8)
      break;
    cp[-1] = '\0';
  }
}


x86 assembly (clang, -O0):
<chop_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x9,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1180 <chop_version+0x30>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1185 <chop_version+0x35>
mov    -0x8(%rbp),%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c8 <chop_version+0x78>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jbe    11c8 <chop_version+0x78>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5f,%eax
je     11cd <chop_version+0x7d>
jmp    1241 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    11e8 <chop_version+0x98>
jmp    1241 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xe09(%rip),%rsi
call   1070 <strpbrk@plt>
cmp    $0x0,%rax
je     120b <chop_version+0xbb>
jmp    1241 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
lea    0xdfa(%rip),%rsi
call   1060 <strspn@plt>
cmp    $0x8,%eax
je     1234 <chop_version+0xe4>
jmp    1241 <chop_version+0xf1>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x1(%rax)
jmp    1185 <chop_version+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop_version>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x9,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <chop_version+0x20>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11fb <chop_version+0xab>
mov    %rax,%rbx
lea    0x1(%r14),%r13
cmp    %r13,%rax
jbe    11fb <chop_version+0xab>
lea    0xe6b(%rip),%r15
lea    0xe7f(%rip),%r12
nopl   0x0(%rax)
cmpb   $0x5f,-0x1(%rbx)
jne    11fb <chop_version+0xab>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x9,%eax
jl     11fb <chop_version+0xab>
mov    %eax,%ebp
lea    0x1(%rbx),%rdi
mov    %r15,%rsi
call   1070 <strpbrk@plt>
test   %rax,%rax
jne    11fb <chop_version+0xab>
mov    %ebp,%eax
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffff8,%rdi
mov    %r12,%rsi
call   1060 <strspn@plt>
cmp    $0x8,%eax
jne    11fb <chop_version+0xab>
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11fb <chop_version+0xab>
mov    %rax,%rbx
cmp    %r13,%rax
ja     11a0 <chop_version+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [17 x i8] c"0123456789abcdef\00"
define void @chop_version(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 9)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i8*, i8** %3
store i8 0, i8* %10
br label %11
11: ; preds = %9, %1
br label %12
12: ; preds = %50, %11
%13 = load i8*, i8** %2
%14 = call i8* @strrchr(i8* %13, i8 signext 82)
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = icmp ule i8* %18, %20
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 95
br i1 %27, label %28, label %29
28: ; preds = %22, %17, %12
br label %53
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %4
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 9
br i1 %33, label %34, label %35
34: ; preds = %29
br label %53
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i64 @strpbrk(i8* %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %53
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = getelementptr inbounds i8, i8* %45, i64 -8
%47 = call i32 @strspn(i8* %46, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp ne i32 %47, 8
br i1 %48, label %49, label %50
49: ; preds = %41
br label %53
50: ; preds = %41
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 -1
store i8 0, i8* %52
br label %12
53: ; preds = %49, %40, %34, %28
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [17 x i8] c"0123456789abcdef\00"
define void @chop_version(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 9)
%3 = icmp eq i8* %2, null
br i1 %3, label %5, label %4
4: ; preds = %1
store i8 0, i8* %2
br label %5
5: ; preds = %4, %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 82)
%8 = icmp ne i8* %7, null
%9 = icmp ugt i8* %7, %6
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %34
11: ; preds = %5, %29
%12 = phi i8* [ %30, %29 ], [ %7, %5 ]
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = tail call i32 @strlen(i8* %12)
%18 = icmp slt i32 %17, 9
br i1 %18, label %34, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = tail call i64 @strpbrk(i8* %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = zext i32 %17 to i64
%25 = getelementptr inbounds i8, i8* %12, i64 -8
%26 = getelementptr inbounds i8, i8* %25, i64 %24
%27 = tail call i32 @strspn(i8* %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32 %27, 8
br i1 %28, label %29, label %34
29: ; preds = %23
store i8 0, i8* %13
%30 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 82)
%31 = icmp ne i8* %30, null
%32 = icmp ugt i8* %30, %6
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %11, label %34
34: ; preds = %23, %19, %16, %29, %11, %5
ret void
}