#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ isalnum(char const);
const char *encodeurl(const char *req) {
  char *h = "0123456789abcdef";
  static char buf[128];
  char *urlenc = buf;
  char *bufend = buf + sizeof(buf) - 3;
  while (*req && urlenc < bufend) {
    if (isalnum(*req) || *req == '-' || *req == '_' || *req == '.')
      *urlenc++ = *req++;
    else {
      *urlenc++ = '%';
      *urlenc++ = h[*req >> 4];
      *urlenc++ = h[*req & 0x0f];
      req++;
    }
  }
  *urlenc = 0;
  return buf;
}


x86 assembly (clang, -O0):
<encodeurl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0x2f12(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0x2f07(%rip),%rax
add    $0x7d,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1164 <encodeurl+0x54>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1174 <encodeurl+0x64>
jmp    124e <encodeurl+0x13e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
jne    11ba <encodeurl+0xaa>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11ba <encodeurl+0xaa>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     11ba <encodeurl+0xaa>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e1 <encodeurl+0xd1>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1249 <encodeurl+0x139>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x25,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sar    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1141 <encodeurl+0x31>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2de4(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeurl>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     11b6 <encodeurl+0xa6>
mov    %rdi,%rbx
lea    0x2f13(%rip),%r14
lea    0xecc(%rip),%r15
movabs $0x4000000000003,%r12
lea    0x2f78(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1030 <isalnum@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
jne    1170 <encodeurl+0x60>
lea    -0x2d(%rcx),%eax
cmp    $0x32,%al
ja     118a <encodeurl+0x7a>
movzbl %al,%eax
bt     %rax,%r12
jae    118a <encodeurl+0x7a>
mov    %cl,(%r14)
add    $0x1,%r14
movzbl 0x1(%rbx),%eax
test   %al,%al
je     11bd <encodeurl+0xad>
add    $0x1,%rbx
cmp    %r13,%r14
jb     1150 <encodeurl+0x40>
jmp    11bd <encodeurl+0xad>
movb   $0x25,(%r14)
movzbl (%rbx),%eax
sar    $0x4,%al
movsbq %al,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,0x1(%r14)
movzbl (%rbx),%eax
and    $0xf,%eax
movzbl (%rax,%r15,1),%eax
mov    %al,0x2(%r14)
add    $0x3,%r14
jmp    1177 <encodeurl+0x67>
lea    0x2e83(%rip),%r14
movb   $0x0,(%r14)
lea    0x2e78(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@encodeurl.buf = internal global [128 x i8] zeroinitializer
define i8* @encodeurl(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 1, i64 -3), i8** %5
br label %6
6: ; preds = %68, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = icmp ult i8* %12, %13
br label %15
15: ; preds = %11, %6
%16 = phi i1 [ false, %6 ], [ %14, %11 ]
br i1 %16, label %17, label %69
17: ; preds = %15
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = call i64 @isalnum(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %37, label %22
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 45
br i1 %26, label %37, label %27
27: ; preds = %22
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 95
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 46
br i1 %36, label %37, label %43
37: ; preds = %32, %27, %22, %17
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %2
%40 = load i8, i8* %38
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
store i8 %40, i8* %41
br label %68
43: ; preds = %32
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %4
store i8 37, i8* %44
%46 = load i8*, i8** %3
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = ashr i32 %49, 4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %46, i64 %51
%53 = load i8, i8* %52
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %4
store i8 %53, i8* %54
%56 = load i8*, i8** %3
%57 = load i8*, i8** %2
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = and i32 %59, 15
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %56, i64 %61
%63 = load i8, i8* %62
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
store i8 %63, i8* %64
%66 = load i8*, i8** %2
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %2
br label %68
68: ; preds = %43, %37
br label %6
69: ; preds = %15
%70 = load i8*, i8** %4
store i8 0, i8* %70
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@encodeurl.buf = internal global [128 x i8] zeroinitializer
define i8* @encodeurl(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %35, label %4
4: ; preds = %1, %28
%5 = phi i8 [ %31, %28 ], [ %2, %1 ]
%6 = phi i8* [ %30, %28 ], [ %0, %1 ]
%7 = phi i8* [ %29, %28 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 0), %1 ]
%8 = tail call i64 @isalnum(i8 signext %5)
%9 = icmp eq i64 %8, 0
%10 = load i8, i8* %6
br i1 %9, label %11, label %12
11: ; preds = %4
switch i8 %10, label %14 [
i8 45, label %12
i8 95, label %12
i8 46, label %12
]
12: ; preds = %4, %11, %11, %11
%13 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %10, i8* %7
br label %28
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %7, i64 1
store i8 37, i8* %7
%16 = load i8, i8* %6
%17 = ashr i8 %16, 4
%18 = sext i8 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %7, i64 2
store i8 %20, i8* %15
%22 = load i8, i8* %6
%23 = and i8 %22, 15
%24 = zext i8 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %7, i64 3
store i8 %26, i8* %21
br label %28
28: ; preds = %14, %12
%29 = phi i8* [ %13, %12 ], [ %27, %14 ]
%30 = getelementptr inbounds i8, i8* %6, i64 1
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
%33 = icmp ult i8* %29, getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 125)
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %4, label %35
35: ; preds = %28, %1
%36 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 0), %1 ], [ %29, %28 ]
store i8 0, i8* %36
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @encodeurl.buf, i64 0, i64 0)
}