#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*/ memcmp(char *, char *, int);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strpbrk(char *, char *);
char *strrchr(char *, char);
int strspn(char *, char *);
char *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';
  }
  if (*arg == 'G') {
    int len = strlen(arg);
    while (len > 8 && !memcmp(arg, "GPLONLY_", 8)) {
      arg += 8;
      len -= 8;
    }
  }
  return arg;
}


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     1190 <chop_version+0x30>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1195 <chop_version+0x35>
mov    -0x8(%rbp),%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <chop_version+0x78>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jbe    11d8 <chop_version+0x78>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5f,%eax
je     11dd <chop_version+0x7d>
jmp    1251 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    11f8 <chop_version+0x98>
jmp    1251 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xdf9(%rip),%rsi
call   1080 <strpbrk@plt>
cmp    $0x0,%rax
je     121b <chop_version+0xbb>
jmp    1251 <chop_version+0xf1>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
lea    0xdea(%rip),%rsi
call   1060 <strspn@plt>
cmp    $0x8,%eax
je     1244 <chop_version+0xe4>
jmp    1251 <chop_version+0xf1>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x1(%rax)
jmp    1195 <chop_version+0x35>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x47,%eax
jne    12cb <chop_version+0x16b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x8,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jle    129c <chop_version+0x13c>
mov    -0x8(%rbp),%rdi
lea    0xda5(%rip),%rsi
mov    $0x8,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    12ac <chop_version+0x14c>
jmp    12c6 <chop_version+0x166>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x18(%rbp)
jmp    126d <chop_version+0x10d>
jmp    12cb <chop_version+0x16b>
mov    -0x8(%rbp),%rax
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     1180 <chop_version+0x20>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     120b <chop_version+0xab>
mov    %rax,%rbx
lea    0x1(%r14),%r13
cmp    %r13,%rax
jbe    120b <chop_version+0xab>
lea    0xe5b(%rip),%r15
lea    0xe6f(%rip),%r12
nopl   0x0(%rax)
cmpb   $0x5f,-0x1(%rbx)
jne    120b <chop_version+0xab>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x9,%eax
jl     120b <chop_version+0xab>
mov    %eax,%ebp
lea    0x1(%rbx),%rdi
mov    %r15,%rsi
call   1080 <strpbrk@plt>
test   %rax,%rax
jne    120b <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    120b <chop_version+0xab>
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
mov    $0x52,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     120b <chop_version+0xab>
mov    %rax,%rbx
cmp    %r13,%rax
ja     11b0 <chop_version+0x50>
cmpb   $0x47,(%r14)
jne    1250 <chop_version+0xf0>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x9,%eax
jl     1250 <chop_version+0xf0>
mov    %eax,%ebx
add    $0x8,%ebx
lea    0xe02(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1070 <memcmp@plt>
test   %eax,%eax
jne    1250 <chop_version+0xf0>
add    $0x8,%r14
add    $0xfffffff8,%ebx
cmp    $0x10,%ebx
jg     1230 <chop_version+0xd0>
mov    %r14,%rax
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"
@.str.2 = [9 x i8] c"GPLONLY_\00"
define i8* @chop_version(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strchr(i8* %6, i8 signext 9)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i8*, i8** %3
store i8 0, i8* %11
br label %12
12: ; preds = %10, %1
br label %13
13: ; preds = %51, %12
%14 = load i8*, i8** %2
%15 = call i8* @strrchr(i8* %14, i8 signext 82)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = icmp ule i8* %19, %21
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 95
br i1 %28, label %29, label %30
29: ; preds = %23, %18, %13
br label %54
30: ; preds = %23
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 9
br i1 %34, label %35, label %36
35: ; preds = %30
br label %54
36: ; preds = %30
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i64 @strpbrk(i8* %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
br label %54
42: ; preds = %36
%43 = load i8*, i8** %3
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = getelementptr inbounds i8, i8* %46, i64 -8
%48 = call i32 @strspn(i8* %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp ne i32 %48, 8
br i1 %49, label %50, label %51
50: ; preds = %42
br label %54
51: ; preds = %42
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 -1
store i8 0, i8* %53
br label %13
54: ; preds = %50, %41, %35, %29
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 71
br i1 %58, label %59, label %78
59: ; preds = %54
%60 = load i8*, i8** %2
%61 = call i32 @strlen(i8* %60)
store i32 %61, i32* %5
br label %62
62: ; preds = %72, %59
%63 = load i32, i32* %5
%64 = icmp sgt i32 %63, 8
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i8*, i8** %2
%67 = call i32 @memcmp(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br label %70
70: ; preds = %65, %62
%71 = phi i1 [ false, %62 ], [ %69, %65 ]
br i1 %71, label %72, label %77
72: ; preds = %70
%73 = load i8*, i8** %2
%74 = getelementptr inbounds i8, i8* %73, i64 8
store i8* %74, i8** %2
%75 = load i32, i32* %5
%76 = sub nsw i32 %75, 8
store i32 %76, i32* %5
br label %62
77: ; preds = %70
br label %78
78: ; preds = %77, %54
%79 = load i8*, i8** %2
ret i8* %79
}

LLVM IR (-O2):
@.str = [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [17 x i8] c"0123456789abcdef\00"
@.str.2 = [9 x i8] c"GPLONLY_\00"
define i8* @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
%35 = load i8, i8* %0
%36 = icmp eq i8 %35, 71
br i1 %36, label %37, label %49
37: ; preds = %34
%38 = tail call i32 @strlen(i8* %0)
%39 = icmp sgt i32 %38, 8
br i1 %39, label %40, label %49
40: ; preds = %37, %45
%41 = phi i32 [ %47, %45 ], [ %38, %37 ]
%42 = phi i8* [ %46, %45 ], [ %0, %37 ]
%43 = tail call i32 @memcmp(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = getelementptr inbounds i8, i8* %42, i64 8
%47 = add nsw i32 %41, -8
%48 = icmp sgt i32 %41, 16
br i1 %48, label %40, label %49
49: ; preds = %45, %40, %37, %34
%50 = phi i8* [ %0, %34 ], [ %0, %37 ], [ %46, %45 ], [ %42, %40 ]
ret i8* %50
}