#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 */
scalar_t__ isalnum(char const);
int /*<<< orphan*/ sprintf(char *, char *, char const);
char *str2href(const char *src) {
  static char buf[2048];
  char *dst;
  for (dst = buf; *src; ++src) {
    if (*src <= ' ' ||
        !(isalnum(*src) || *src == '.' || *src == '-' || *src == '_')) {
      sprintf(dst, "%%%02x", *src);
      while (*dst)
        ++dst;
    } else
      *dst++ = *src;
  }
  *dst = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<str2href>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1201 <str2href+0xe1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jle    119a <str2href+0x7a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
jne    11d4 <str2href+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11d4 <str2href+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11d4 <str2href+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     11d4 <str2href+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
lea    0xe57(%rip),%rsi
movsbl (%rax),%edx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cf <str2href+0xaf>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b1 <str2href+0x91>
jmp    11eb <str2href+0xcb>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11f0 <str2href+0xd0>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1137 <str2href+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e31(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2href>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     11b1 <str2href+0x91>
mov    %rdi,%r15
lea    0x2f04(%rip),%rbx
lea    0xebd(%rip),%r14
movabs $0x4000000000003,%r12
jmp    1178 <str2href+0x58>
nop
movsbl %cl,%edi
call   1030 <isalnum@plt>
mov    (%r15),%cl
test   %rax,%rax
je     119f <str2href+0x7f>
mov    %cl,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rax
mov    0x1(%r15),%cl
add    $0x1,%r15
mov    %rax,%rbx
test   %cl,%cl
je     11b8 <str2href+0x98>
cmp    $0x21,%cl
jge    1150 <str2href+0x30>
movsbl %cl,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
add    $0xffffffffffffffff,%rbx
nop
lea    0x1(%rbx),%rax
cmpb   $0x0,0x1(%rbx)
mov    %rax,%rbx
jne    1190 <str2href+0x70>
jmp    1169 <str2href+0x49>
lea    -0x2d(%rcx),%eax
cmp    $0x32,%al
ja     117d <str2href+0x5d>
movzbl %al,%eax
bt     %rax,%r12
jb     1160 <str2href+0x40>
jmp    117d <str2href+0x5d>
lea    0x2e88(%rip),%rax
movb   $0x0,(%rax)
lea    0x2e7e(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@str2href.buf = internal global [2048 x i8] zeroinitializer
@.str = [7 x i8] c"%%%02x\00"
define i8* @str2href(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2href.buf, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %52, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %55
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp sle i32 %11, 32
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = call i64 @isalnum(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %46, label %18
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 46
br i1 %22, label %46, label %23
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 45
br i1 %27, label %46, label %28
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 95
br i1 %32, label %46, label %33
33: ; preds = %28, %8
%34 = load i8*, i8** %3
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %36)
br label %38
38: ; preds = %42, %33
%39 = load i8*, i8** %3
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
br label %38
45: ; preds = %38
br label %51
46: ; preds = %28, %23, %18, %13
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
store i8 %48, i8* %49
br label %51
51: ; preds = %46, %45
br label %52
52: ; preds = %51
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %2
br label %4
55: ; preds = %4
%56 = load i8*, i8** %3
store i8 0, i8* %56
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2href.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@str2href.buf = internal global [2048 x i8] zeroinitializer
@.str = [7 x i8] c"%%%02x\00"
define i8* @str2href(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %29, label %4
4: ; preds = %1, %24
%5 = phi i8 [ %27, %24 ], [ %2, %1 ]
%6 = phi i8* [ %25, %24 ], [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2href.buf, i64 0, i64 0), %1 ]
%7 = phi i8* [ %26, %24 ], [ %0, %1 ]
%8 = icmp slt i8 %5, 33
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i64 @isalnum(i8 signext %5)
%11 = icmp eq i64 %10, 0
%12 = load i8, i8* %7
br i1 %11, label %13, label %22
13: ; preds = %9
switch i8 %12, label %14 [
i8 46, label %22
i8 45, label %22
i8 95, label %22
]
14: ; preds = %13, %4
%15 = phi i8 [ %12, %13 ], [ %5, %4 ]
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %15)
br label %17
17: ; preds = %17, %14
%18 = phi i8* [ %6, %14 ], [ %21, %17 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
%21 = getelementptr inbounds i8, i8* %18, i64 1
br i1 %20, label %24, label %17
22: ; preds = %9, %13, %13, %13
%23 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %12, i8* %6
br label %24
24: ; preds = %17, %22
%25 = phi i8* [ %23, %22 ], [ %18, %17 ]
%26 = getelementptr inbounds i8, i8* %7, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %4
29: ; preds = %24, %1
%30 = phi i8* [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2href.buf, i64 0, i64 0), %1 ], [ %25, %24 ]
store i8 0, i8* %30
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2href.buf, i64 0, i64 0)
}