#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*/ assert(char *);
char *m_strdup(char const *);
int /*<<< orphan*/ printf(char *, char const *);
char *strchr(char const *, char);
char *strstr(char const *, char *);
char *get_clean_ref_token(const char *text) {
  char *buf, *t;
  const char *pname, *pcross;
  pname = strstr(text, "<a name=\"");
  pcross = strstr(text, "ss#");
  if (pname && pcross) {
    if (pname < pcross)
      pcross = 0;
    else
      pname = 0;
  }
  if (pname) {
    buf = m_strdup(pname + 9);
    t = strchr(buf, '"');
    *t = 0;
  } else if (pcross) {
    buf = m_strdup(pcross + 3);
    t = strchr(buf, '"');
    *t = 0;
  } else if (!strchr(text, '<') && !strchr(text, '>'))
    buf = m_strdup(text);
  else {
    printf("'%s' was rejected as clean ref token\n", text);
    buf = m_strdup("");
  }
  assert(buf);
  return buf;
}


x86 assembly (clang, -O0):
<get_clean_ref_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c2 <get_clean_ref_token+0x72>
cmpq   $0x0,-0x28(%rbp)
je     11c2 <get_clean_ref_token+0x72>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b5 <get_clean_ref_token+0x65>
movq   $0x0,-0x28(%rbp)
jmp    11bd <get_clean_ref_token+0x6d>
movq   $0x0,-0x20(%rbp)
jmp    11c2 <get_clean_ref_token+0x72>
cmpq   $0x0,-0x20(%rbp)
je     11fc <get_clean_ref_token+0xac>
mov    -0x20(%rbp),%rdi
add    $0x9,%rdi
call   1060 <m_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    12a2 <get_clean_ref_token+0x152>
cmpq   $0x0,-0x28(%rbp)
je     1236 <get_clean_ref_token+0xe6>
mov    -0x28(%rbp),%rdi
add    $0x3,%rdi
call   1060 <m_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    129d <get_clean_ref_token+0x14d>
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1278 <get_clean_ref_token+0x128>
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1278 <get_clean_ref_token+0x128>
mov    -0x8(%rbp),%rdi
call   1060 <m_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    1298 <get_clean_ref_token+0x148>
mov    -0x8(%rbp),%rsi
lea    0xd8b(%rip),%rdi
call   1040 <printf@plt>
lea    0xda4(%rip),%rdi
call   1060 <m_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    129d <get_clean_ref_token+0x14d>
jmp    12a2 <get_clean_ref_token+0x152>
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_clean_ref_token>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rbx
lea    0xe9d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strstr@plt>
test   %rbx,%rbx
setne  %sil
test   %rax,%rax
setne  %dl
xor    %edi,%edi
cmp    %rax,%rbx
mov    $0x0,%ecx
cmovb  %rbx,%rcx
cmovae %rax,%rdi
test   %dl,%sil
cmove  %rbx,%rcx
cmove  %rax,%rdi
test   %rcx,%rcx
je     11ad <get_clean_ref_token+0x5d>
add    $0x9,%rcx
mov    %rcx,%rdi
jmp    11b6 <get_clean_ref_token+0x66>
test   %rdi,%rdi
je     11e1 <get_clean_ref_token+0x91>
add    $0x3,%rdi
call   1060 <m_strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1205 <get_clean_ref_token+0xb5>
mov    %r14,%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1225 <get_clean_ref_token+0xd5>
lea    0xe02(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
call   1060 <m_strdup@plt>
mov    %rax,%rbx
jmp    11ce <get_clean_ref_token+0x7e>
mov    %r14,%rdi
jmp    121b <get_clean_ref_token+0xcb>

LLVM IR (-O0):
@.str = [10 x i8] c"<a name=\22\00"
@.str.1 = [4 x i8] c"ss#\00"
@.str.2 = [38 x i8] c"'%s' was rejected as clean ref token\0A\00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @get_clean_ref_token(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %5
%9 = load i8*, i8** %2
%10 = call i8* @strstr(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = icmp ult i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i8* null, i8** %6
br label %22
21: ; preds = %16
store i8* null, i8** %5
br label %22
22: ; preds = %21, %20
br label %23
23: ; preds = %22, %13, %1
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 9
%29 = call i8* @m_strdup(i8* %28)
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = call i8* @strchr(i8* %30, i8 signext 34)
store i8* %31, i8** %4
%32 = load i8*, i8** %4
store i8 0, i8* %32
br label %60
33: ; preds = %23
%34 = load i8*, i8** %6
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = call i8* @m_strdup(i8* %38)
store i8* %39, i8** %3
%40 = load i8*, i8** %3
%41 = call i8* @strchr(i8* %40, i8 signext 34)
store i8* %41, i8** %4
%42 = load i8*, i8** %4
store i8 0, i8* %42
br label %59
43: ; preds = %33
%44 = load i8*, i8** %2
%45 = call i8* @strchr(i8* %44, i8 signext 60)
%46 = icmp ne i8* %45, null
br i1 %46, label %54, label %47
47: ; preds = %43
%48 = load i8*, i8** %2
%49 = call i8* @strchr(i8* %48, i8 signext 62)
%50 = icmp ne i8* %49, null
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i8*, i8** %2
%53 = call i8* @m_strdup(i8* %52)
store i8* %53, i8** %3
br label %58
54: ; preds = %47, %43
%55 = load i8*, i8** %2
%56 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i8* @m_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i8* %57, i8** %3
br label %58
58: ; preds = %54, %51
br label %59
59: ; preds = %58, %36
br label %60
60: ; preds = %59, %26
%61 = load i8*, i8** %3
%62 = call i32 @assert(i8* %61)
%63 = load i8*, i8** %3
ret i8* %63
}

LLVM IR (-O2):
@.str = [10 x i8] c"<a name=\22\00"
@.str.1 = [4 x i8] c"ss#\00"
@.str.2 = [38 x i8] c"'%s' was rejected as clean ref token\0A\00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @get_clean_ref_token(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp ne i8* %2, null
%5 = icmp ne i8* %3, null
%6 = select i1 %4, i1 %5, i1 false
%7 = icmp ult i8* %2, %3
%8 = select i1 %7, i8* %2, i8* null
%9 = select i1 %6, i8* %8, i8* %2
%10 = select i1 %6, i1 %7, i1 false
%11 = select i1 %10, i8* null, i8* %3
%12 = icmp eq i8* %9, null
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = getelementptr inbounds i8, i8* %9, i64 9
%15 = tail call i8* @m_strdup(i8* %14)
%16 = tail call i8* @strchr(i8* dereferenceable(1) %15, i8 signext 34)
store i8 0, i8* %16
br label %34
17: ; preds = %1
%18 = icmp eq i8* %11, null
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = getelementptr inbounds i8, i8* %11, i64 3
%21 = tail call i8* @m_strdup(i8* %20)
%22 = tail call i8* @strchr(i8* dereferenceable(1) %21, i8 signext 34)
store i8 0, i8* %22
br label %34
23: ; preds = %17
%24 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 60)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 62)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i8* @m_strdup(i8* %0)
br label %34
31: ; preds = %26, %23
%32 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%33 = tail call i8* @m_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %19, %31, %29, %13
%35 = phi i8* [ %15, %13 ], [ %21, %19 ], [ %33, %31 ], [ %30, %29 ]
%36 = tail call i32 @assert(i8* %35)
ret i8* %35
}