int hashEncodeURL(unsigned char *data, int maxlen) {
  unsigned char buffer[(20 * 3) + 1];
  unsigned char *hexdict = (unsigned char *)"0123456789abcdef";
  unsigned char *nonreserved =
      (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012"
                       "3456789-_.~";
  int i, c;
  i = 0;
  c = 0;
  for (; i < 20; i++) {
    buffer[c] = data[i];
    if (charIndex(nonreserved, data[i]) == -1) {
      buffer[c] = '%';
      buffer[c + 1] = hexdict[(data[i]) >> 4];
      buffer[c + 2] = hexdict[(data[i]) & 0xF];
      c += 2;
    }
    c++;
  }
  buffer[c] = 0;
  strncpy((char *)data, (char *)buffer, maxlen);
  return 0;
}


x86 assembly (clang, -O0):
<hashEncodeURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xed0(%rip),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x14,-0x64(%rbp)
jge    1203 <hashEncodeURL+0xe3>
mov    -0x8(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x68(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x64(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1040 <charIndex@plt>
cmp    $0xffffffff,%eax
jne    11ec <hashEncodeURL+0xcc>
movslq -0x68(%rbp),%rax
movb   $0x25,-0x50(%rbp,%rax,1)
mov    -0x58(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x64(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x68(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x58(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x64(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x68(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x68(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1153 <hashEncodeURL+0x33>
movslq -0x68(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
movslq -0xc(%rbp),%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashEncodeURL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,%rbx
lea    0xed5(%rip),%r13
lea    0xebd(%rip),%r15
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1161 <hashEncodeURL+0x41>
nopw   0x0(%rax,%rax,1)
movslq %r14d,%r14
add    $0x1,%r14
add    $0x1,%rbp
cmp    $0x14,%rbp
je     11b2 <hashEncodeURL+0x92>
movzbl (%rbx,%rbp,1),%esi
movslq %r14d,%r12
mov    %sil,0x10(%rsp,%r12,1)
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <charIndex@plt>
cmp    $0xffffffff,%eax
jne    1150 <hashEncodeURL+0x30>
movb   $0x25,0x10(%rsp,%r12,1)
movzbl (%rbx,%rbp,1),%eax
mov    %rax,%rcx
shr    $0x4,%rcx
movzbl (%rcx,%r15,1),%ecx
lea    0x10(%rsp),%rdx
mov    %cl,0x1(%r12,%rdx,1)
and    $0xf,%eax
movzbl (%rax,%r15,1),%eax
mov    %al,0x12(%rsp,%r12,1)
add    $0x2,%r12
mov    %r12d,%r14d
jmp    1150 <hashEncodeURL+0x30>
movb   $0x0,0x10(%rsp,%r14,1)
movslq 0xc(%rsp),%rdx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [67 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~\00"
define i32 @hashEncodeURL(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [61 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %70, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 20
br i1 %12, label %13, label %73
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 %20
store i8 %18, i8* %21
%22 = load i8*, i8** %7
%23 = load i8*, i8** %3
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @charIndex to i32 (i8*, i32, ...)*)(i8* %22, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %67
31: ; preds = %13
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 %33
store i8 37, i8* %34
%35 = load i8*, i8** %6
%36 = load i8*, i8** %3
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = ashr i32 %41, 4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %35, i64 %43
%45 = load i8, i8* %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 %48
store i8 %45, i8* %49
%50 = load i8*, i8** %6
%51 = load i8*, i8** %3
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = and i32 %56, 15
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %50, i64 %58
%60 = load i8, i8* %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 2
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 %63
store i8 %60, i8* %64
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 2
store i32 %66, i32* %9
br label %67
67: ; preds = %31, %13
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %70
70: ; preds = %67
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
store i32 %72, i32* %8
br label %10
73: ; preds = %10
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 %75
store i8 0, i8* %76
%77 = load i8*, i8** %3
%78 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 0
%79 = load i32, i32* %4
%80 = sext i32 %79 to i64
%81 = call i8* @strncpy(i8* %77, i8* %78, i64 %80)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [67 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~\00"
define i32 @hashEncodeURL(i8* %0, i32 %1) {
%3 = alloca [61 x i8]
%4 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %31
%6 = phi i64 [ 0, %2 ], [ %34, %31 ]
%7 = phi i32 [ 0, %2 ], [ %33, %31 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 %10
store i8 %9, i8* %11
%12 = zext i8 %9 to i32
%13 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @charIndex to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %31
15: ; preds = %5
store i8 37, i8* %11
%16 = load i8, i8* %8
%17 = lshr i8 %16, 4
%18 = zext i8 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = add nsw i32 %7, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 %22
store i8 %20, i8* %23
%24 = and i8 %16, 15
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = add nsw i32 %7, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %15, %5
%32 = phi i32 [ %28, %15 ], [ %7, %5 ]
%33 = add nsw i32 %32, 1
%34 = add nuw nsw i64 %6, 1
%35 = icmp eq i64 %34, 20
br i1 %35, label %36, label %5
36: ; preds = %31
%37 = sext i32 %33 to i64
%38 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 %37
store i8 0, i8* %38
%39 = sext i32 %1 to i64
%40 = call i8* @strncpy(i8* dereferenceable(1) %0, i8* %4, i64 %39)
ret i32 0
}