#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*/ add_char(char);
int /*<<< orphan*/ add_word(char *);
int /*<<< orphan*/ add_word_args(char *, unsigned char);
int /*<<< orphan*/ canon_white(char *);
int /*<<< orphan*/ index(char *, char);
int /*<<< orphan*/ isalnum(char);
void add_escaped_anchor_name(char *name, int old) {
  canon_white(name);
  if (!old &&
      !index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", *name)) {
    add_word("g_t");
  }
  for (; *name; name++) {
    if ((((*name) == '\t' || (*name) == ' ') || (*name) == '\r' ||
         (*name) == '\n'))
      add_char('-');
    else if (!old && !(isalnum(*name)))
      add_word_args("_00%x", (unsigned char)*name);
    else if (old && !(isalnum(*name)) && !(index("$-_.+!*'()", *name)))
      add_word_args("%%%x", (unsigned char)*name);
    else
      add_char(*name);
  }
}


x86 assembly (clang, -O0):
<add_escaped_anchor_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <canon_white@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11aa <add_escaped_anchor_name+0x4a>
mov    -0x8(%rbp),%rax
lea    0xe73(%rip),%rdi
movsbl (%rax),%esi
call   1070 <index@plt>
cmp    $0x0,%eax
jne    11aa <add_escaped_anchor_name+0x4a>
lea    0xe90(%rip),%rdi
call   1080 <add_word@plt>
jmp    11af <add_escaped_anchor_name+0x4f>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12c1 <add_escaped_anchor_name+0x161>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     11fc <add_escaped_anchor_name+0x9c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11fc <add_escaped_anchor_name+0x9c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     11fc <add_escaped_anchor_name+0x9c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    120b <add_escaped_anchor_name+0xab>
mov    $0x2d,%edi
call   1030 <add_char@plt>
jmp    12ab <add_escaped_anchor_name+0x14b>
cmpl   $0x0,-0xc(%rbp)
jne    1242 <add_escaped_anchor_name+0xe2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1242 <add_escaped_anchor_name+0xe2>
mov    -0x8(%rbp),%rax
lea    0xe04(%rip),%rdi
movzbl (%rax),%esi
call   1050 <add_word_args@plt>
jmp    12a6 <add_escaped_anchor_name+0x146>
cmpl   $0x0,-0xc(%rbp)
je     1295 <add_escaped_anchor_name+0x135>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1295 <add_escaped_anchor_name+0x135>
mov    -0x8(%rbp),%rax
lea    0xdd3(%rip),%rdi
movsbl (%rax),%esi
call   1070 <index@plt>
cmp    $0x0,%eax
jne    1295 <add_escaped_anchor_name+0x135>
mov    -0x8(%rbp),%rax
lea    0xdc2(%rip),%rdi
movzbl (%rax),%esi
call   1050 <add_word_args@plt>
jmp    12a1 <add_escaped_anchor_name+0x141>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <add_char@plt>
jmp    12a6 <add_escaped_anchor_name+0x146>
jmp    12ab <add_escaped_anchor_name+0x14b>
jmp    12b0 <add_escaped_anchor_name+0x150>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <add_escaped_anchor_name+0x4f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_escaped_anchor_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%rbx
call   1060 <canon_white@plt>
test   %r13d,%r13d
jne    119a <add_escaped_anchor_name+0x3a>
movsbl (%rbx),%esi
lea    0xe7b(%rip),%rdi
call   1070 <index@plt>
test   %eax,%eax
jne    119a <add_escaped_anchor_name+0x3a>
lea    0xea0(%rip),%rdi
call   1080 <add_word@plt>
lea    0xe98(%rip),%r14
lea    0xe97(%rip),%r15
lea    0xe9b(%rip),%r12
movabs $0x100002600,%rbp
jmp    11d9 <add_escaped_anchor_name+0x79>
test   %eax,%eax
je     121c <add_escaped_anchor_name+0xbc>
movsbl (%rbx),%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <add_char@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%rax
ja     11f4 <add_escaped_anchor_name+0x94>
bt     %rax,%rbp
jae    11ef <add_escaped_anchor_name+0x8f>
mov    $0x2d,%edi
jmp    11d0 <add_escaped_anchor_name+0x70>
test   %rax,%rax
je     122d <add_escaped_anchor_name+0xcd>
movsbl %al,%edi
call   1040 <isalnum@plt>
test   %r13d,%r13d
je     11bb <add_escaped_anchor_name+0x5b>
test   %eax,%eax
jne    11bf <add_escaped_anchor_name+0x5f>
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1070 <index@plt>
test   %eax,%eax
jne    11bf <add_escaped_anchor_name+0x5f>
movzbl (%rbx),%esi
mov    %r12,%rdi
jmp    1222 <add_escaped_anchor_name+0xc2>
movzbl (%rbx),%esi
mov    %r14,%rdi
call   1050 <add_word_args@plt>
add    $0x1,%rbx
jmp    11d9 <add_escaped_anchor_name+0x79>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [4 x i8] c"g_t\00"
@.str.2 = [6 x i8] c"_00%x\00"
@.str.3 = [11 x i8] c"$-_.+!*'()\00"
@.str.4 = [5 x i8] c"%%%x\00"
define void @add_escaped_anchor_name(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = call i32 @canon_white(i8* %5)
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i32 @index(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @add_word(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9, %2
br label %17
17: ; preds = %79, %16
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %82
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 9
br i1 %25, label %41, label %26
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 32
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 13
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %43
41: ; preds = %36, %31, %26, %21
%42 = call i32 @add_char(i8 signext 45)
br label %78
43: ; preds = %36
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 0
br i1 %45, label %55, label %46
46: ; preds = %43
%47 = load i8*, i8** %3
%48 = load i8, i8* %47
%49 = call i32 @isalnum(i8 signext %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %46
%52 = load i8*, i8** %3
%53 = load i8, i8* %52
%54 = call i32 @add_word_args(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %53)
br label %77
55: ; preds = %46, %43
%56 = load i32, i32* %4
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %72
58: ; preds = %55
%59 = load i8*, i8** %3
%60 = load i8, i8* %59
%61 = call i32 @isalnum(i8 signext %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %72, label %63
63: ; preds = %58
%64 = load i8*, i8** %3
%65 = load i8, i8* %64
%66 = call i32 @index(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8 signext %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %63
%69 = load i8*, i8** %3
%70 = load i8, i8* %69
%71 = call i32 @add_word_args(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %70)
br label %76
72: ; preds = %63, %58, %55
%73 = load i8*, i8** %3
%74 = load i8, i8* %73
%75 = call i32 @add_char(i8 signext %74)
br label %76
76: ; preds = %72, %68
br label %77
77: ; preds = %76, %51
br label %78
78: ; preds = %77, %41
br label %79
79: ; preds = %78
%80 = load i8*, i8** %3
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %3
br label %17
82: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [53 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [4 x i8] c"g_t\00"
@.str.2 = [6 x i8] c"_00%x\00"
@.str.3 = [11 x i8] c"$-_.+!*'()\00"
@.str.4 = [5 x i8] c"%%%x\00"
define void @add_escaped_anchor_name(i8* %0, i32 %1) {
%3 = tail call i32 @canon_white(i8* %0)
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i8, i8* %0
%7 = tail call i32 @index(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8 signext %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @add_word(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %5, %2
br label %12
12: ; preds = %11, %35
%13 = phi i8* [ %36, %35 ], [ %0, %11 ]
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 0, label %37
i8 9, label %15
i8 32, label %15
i8 13, label %15
i8 10, label %15
]
15: ; preds = %12, %12, %12, %12
%16 = tail call i32 @add_char(i8 signext 45)
br label %35
17: ; preds = %12
%18 = tail call i32 @isalnum(i8 signext %14)
%19 = icmp eq i32 %18, 0
br i1 %4, label %20, label %24
20: ; preds = %17
br i1 %19, label %21, label %32
21: ; preds = %20
%22 = load i8, i8* %13
%23 = tail call i32 @add_word_args(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %22)
br label %35
24: ; preds = %17
br i1 %19, label %25, label %32
25: ; preds = %24
%26 = load i8, i8* %13
%27 = tail call i32 @index(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8 signext %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8, i8* %13
%31 = tail call i32 @add_word_args(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %30)
br label %35
32: ; preds = %20, %25, %24
%33 = load i8, i8* %13
%34 = tail call i32 @add_char(i8 signext %33)
br label %35
35: ; preds = %15, %29, %32, %21
%36 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
37: ; preds = %12
ret void
}