#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__ malloc(size_t);
char *strdup(char *);
char *_q_urlencode(const void *bin, size_t size) {
  const char URLCHARTBL[256] = {
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   '-', '.', '/', '0', '1', '2',  '3', '4', '5', '6', '7',
      '8', '9', ':', 0,   0,   0,   0,   0,   '@',  'A', 'B', 'C', 'D', 'E',
      'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',  'O', 'P', 'Q', 'R', 'S',
      'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0,   '\\', 0,   0,   '_', 0,   'a',
      'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',  'k', 'l', 'm', 'n', 'o',
      'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',  'y', 'z', 0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,
      0,   0,   0,   0};
  if (bin == NULL)
    return NULL;
  if (size == 0)
    return strdup("");
  char *pszEncStr = (char *)malloc((size * 3) + 1);
  if (pszEncStr == NULL)
    return NULL;
  char *pszEncPt = pszEncStr;
  char *pBinPt = (char *)bin;
  const char *pBinEnd = (bin + size - 1);
  for (; pBinPt <= pBinEnd; pBinPt++) {
    if (URLCHARTBL[(int)(*pBinPt)] != 0) {
      *pszEncPt++ = *pBinPt;
    } else {
      unsigned char cUpper4 = (*pBinPt >> 4);
      unsigned char cLower4 = (*pBinPt & 0x0F);
      *pszEncPt++ = '%';
      *pszEncPt++ =
          (cUpper4 < 0x0A) ? (cUpper4 + '0') : ((cUpper4 - 0x0A) + 'a');
      *pszEncPt++ =
          (cLower4 < 0x0A) ? (cLower4 + '0') : ((cLower4 - 0x0A) + 'a');
    }
  }
  *pszEncPt = '\0';
  return pszEncStr;
}


x86 assembly (clang, -O0):
<_q_urlencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1173 <_q_urlencode+0x43>
movq   $0x0,-0x8(%rbp)
jmp    1362 <_q_urlencode+0x232>
cmpq   $0x0,-0x18(%rbp)
jne    1193 <_q_urlencode+0x63>
lea    0xf7b(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1362 <_q_urlencode+0x232>
imul   $0x3,-0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11c3 <_q_urlencode+0x93>
movq   $0x0,-0x8(%rbp)
jmp    1362 <_q_urlencode+0x232>
mov    -0x128(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rax
cmp    -0x140(%rbp),%rax
ja     134d <_q_urlencode+0x21d>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cltq
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1245 <_q_urlencode+0x115>
mov    -0x138(%rbp),%rax
mov    (%rax),%cl
mov    -0x130(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x130(%rbp)
mov    %cl,(%rax)
jmp    1331 <_q_urlencode+0x201>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
mov    %al,-0x141(%rbp)
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
mov    %al,-0x142(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x130(%rbp)
movb   $0x25,(%rax)
movzbl -0x141(%rbp),%eax
cmp    $0xa,%eax
jge    12a8 <_q_urlencode+0x178>
movzbl -0x141(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x148(%rbp)
jmp    12bb <_q_urlencode+0x18b>
movzbl -0x141(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x148(%rbp)
mov    -0x148(%rbp),%eax
mov    %al,%cl
mov    -0x130(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x130(%rbp)
mov    %cl,(%rax)
movzbl -0x142(%rbp),%eax
cmp    $0xa,%eax
jge    12ff <_q_urlencode+0x1cf>
movzbl -0x142(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x14c(%rbp)
jmp    1312 <_q_urlencode+0x1e2>
movzbl -0x142(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x14c(%rbp)
mov    -0x14c(%rbp),%eax
mov    %al,%cl
mov    -0x130(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x130(%rbp)
mov    %cl,(%rax)
jmp    1336 <_q_urlencode+0x206>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    11ef <_q_urlencode+0xbf>
mov    -0x130(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x128(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_q_urlencode>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     115b <_q_urlencode+0x3b>
mov    %rsi,%r14
test   %rsi,%rsi
je     1165 <_q_urlencode+0x45>
mov    %rdi,%rbx
lea    (%r14,%r14,2),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     115b <_q_urlencode+0x3b>
lea    (%rbx,%r14,1),%r10
add    $0xffffffffffffffff,%r10
mov    %rax,%rdx
cmp    %rbx,%r10
jae    1178 <_q_urlencode+0x58>
movb   $0x0,(%rdx)
jmp    115d <_q_urlencode+0x3d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xf94(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strdup@plt>
lea    0xe81(%rip),%r9
mov    $0x30,%r8d
mov    %rax,%rdx
jmp    11d6 <_q_urlencode+0xb6>
nopw   0x0(%rax,%rax,1)
mov    %edi,%ecx
sar    $0x4,%cl
mov    %edi,%esi
and    $0xf,%sil
test   %dil,%dil
mov    $0x57,%edi
cmovns %r8d,%edi
movb   $0x25,(%rdx)
add    %cl,%dil
mov    %dil,0x1(%rdx)
lea    0x30(%rsi),%ecx
lea    0x57(%rsi),%edi
cmp    $0xa,%sil
movzbl %cl,%ecx
movzbl %dil,%esi
cmovb  %ecx,%esi
mov    %sil,0x2(%rdx)
add    $0x3,%rdx
add    $0x1,%rbx
cmp    %r10,%rbx
ja     1156 <_q_urlencode+0x36>
movsbq (%rbx),%rdi
cmpb   $0x0,(%rdi,%r9,1)
je     1190 <_q_urlencode+0x70>
mov    %dil,(%rdx)
add    $0x1,%rdx
jmp    11cd <_q_urlencode+0xad>

LLVM IR (-O0):
@__const._q_urlencode.URLCHARTBL = <{ [123 x i8], [133 x i8] }> <{ [123 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00-./0123456789:\00\00\00\00\00@ABCDEFGHIJKLMNOPQRSTUVWXYZ\00\\\00\00_\00abcdefghijklmnopqrstuvwxyz", [133 x i8] zeroinitializer }>
@.str = [1 x i8] zeroinitializer
define i8* @_q_urlencode(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i8
store i8* %0, i8** %4
store i64 %1, i64* %5
%13 = bitcast [256 x i8]* %6 to i8*
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %110
17: ; preds = %2
%18 = load i64, i64* %5
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %3
br label %110
22: ; preds = %17
%23 = load i64, i64* %5
%24 = mul i64 %23, 3
%25 = add i64 %24, 1
%26 = call i64 @malloc(i64 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %22
store i8* null, i8** %3
br label %110
31: ; preds = %22
%32 = load i8*, i8** %7
store i8* %32, i8** %8
%33 = load i8*, i8** %4
store i8* %33, i8** %9
%34 = load i8*, i8** %4
%35 = load i64, i64* %5
%36 = getelementptr i8, i8* %34, i64 %35
%37 = getelementptr i8, i8* %36, i64 -1
store i8* %37, i8** %10
br label %38
38: ; preds = %104, %31
%39 = load i8*, i8** %9
%40 = load i8*, i8** %10
%41 = icmp ule i8* %39, %40
br i1 %41, label %42, label %107
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %42
%52 = load i8*, i8** %9
%53 = load i8, i8* %52
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %8
store i8 %53, i8* %54
br label %103
56: ; preds = %42
%57 = load i8*, i8** %9
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = ashr i32 %59, 4
%61 = trunc i32 %60 to i8
store i8 %61, i8* %11
%62 = load i8*, i8** %9
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = and i32 %64, 15
%66 = trunc i32 %65 to i8
store i8 %66, i8* %12
%67 = load i8*, i8** %8
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %8
store i8 37, i8* %67
%69 = load i8, i8* %11
%70 = zext i8 %69 to i32
%71 = icmp slt i32 %70, 10
br i1 %71, label %72, label %76
72: ; preds = %56
%73 = load i8, i8* %11
%74 = zext i8 %73 to i32
%75 = add nsw i32 %74, 48
br label %81
76: ; preds = %56
%77 = load i8, i8* %11
%78 = zext i8 %77 to i32
%79 = sub nsw i32 %78, 10
%80 = add nsw i32 %79, 97
br label %81
81: ; preds = %76, %72
%82 = phi i32 [ %75, %72 ], [ %80, %76 ]
%83 = trunc i32 %82 to i8
%84 = load i8*, i8** %8
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %8
store i8 %83, i8* %84
%86 = load i8, i8* %12
%87 = zext i8 %86 to i32
%88 = icmp slt i32 %87, 10
br i1 %88, label %89, label %93
89: ; preds = %81
%90 = load i8, i8* %12
%91 = zext i8 %90 to i32
%92 = add nsw i32 %91, 48
br label %98
93: ; preds = %81
%94 = load i8, i8* %12
%95 = zext i8 %94 to i32
%96 = sub nsw i32 %95, 10
%97 = add nsw i32 %96, 97
br label %98
98: ; preds = %93, %89
%99 = phi i32 [ %92, %89 ], [ %97, %93 ]
%100 = trunc i32 %99 to i8
%101 = load i8*, i8** %8
%102 = getelementptr inbounds i8, i8* %101, i32 1
store i8* %102, i8** %8
store i8 %100, i8* %101
br label %103
103: ; preds = %98, %51
br label %104
104: ; preds = %103
%105 = load i8*, i8** %9
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %9
br label %38
107: ; preds = %38
%108 = load i8*, i8** %8
store i8 0, i8* %108
%109 = load i8*, i8** %7
store i8* %109, i8** %3
br label %110
110: ; preds = %107, %30, %20, %16
%111 = load i8*, i8** %3
ret i8* %111
}

LLVM IR (-O2):
@__const._q_urlencode.URLCHARTBL = <{ [123 x i8], [133 x i8] }> <{ [123 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00-./0123456789:\00\00\00\00\00@ABCDEFGHIJKLMNOPQRSTUVWXYZ\00\\\00\00_\00abcdefghijklmnopqrstuvwxyz", [133 x i8] zeroinitializer }>
@.str = [1 x i8] zeroinitializer
define i8* @_q_urlencode(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %47, label %4
4: ; preds = %2
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %47
8: ; preds = %4
%9 = mul i64 %1, 3
%10 = add i64 %9, 1
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %47, label %14
14: ; preds = %8
%15 = getelementptr i8, i8* %0, i64 %1
%16 = getelementptr i8, i8* %15, i64 -1
%17 = icmp ult i8* %16, %0
br i1 %17, label %45, label %18
18: ; preds = %14, %41
%19 = phi i8* [ %42, %41 ], [ %12, %14 ]
%20 = phi i8* [ %43, %41 ], [ %0, %14 ]
%21 = load i8, i8* %20
%22 = sext i8 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* bitcast (<{ [123 x i8], [133 x i8] }>* @__const._q_urlencode.URLCHARTBL to [256 x i8]*), i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %18
%27 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %21, i8* %19
br label %41
28: ; preds = %18
%29 = ashr i8 %21, 4
%30 = and i8 %21, 15
%31 = getelementptr inbounds i8, i8* %19, i64 1
store i8 37, i8* %19
%32 = icmp sgt i8 %21, -1
%33 = select i1 %32, i8 48, i8 87
%34 = add nsw i8 %33, %29
%35 = getelementptr inbounds i8, i8* %19, i64 2
store i8 %34, i8* %31
%36 = icmp ult i8 %30, 10
%37 = or i8 %30, 48
%38 = add nuw nsw i8 %30, 87
%39 = select i1 %36, i8 %37, i8 %38
%40 = getelementptr inbounds i8, i8* %19, i64 3
store i8 %39, i8* %35
br label %41
41: ; preds = %26, %28
%42 = phi i8* [ %27, %26 ], [ %40, %28 ]
%43 = getelementptr inbounds i8, i8* %20, i64 1
%44 = icmp ugt i8* %43, %16
br i1 %44, label %45, label %18
45: ; preds = %41, %14
%46 = phi i8* [ %12, %14 ], [ %42, %41 ]
store i8 0, i8* %46
br label %47
47: ; preds = %45, %8, %2, %6
%48 = phi i8* [ %7, %6 ], [ null, %2 ], [ %12, %45 ], [ null, %8 ]
ret i8* %48
}