#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ rem;
  int /*<<< orphan*/ quot;
};
typedef TYPE_1__ div_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
TYPE_1__ div(char, int);
void *hextoc(int /*<<< orphan*/);
scalar_t__ iscntrl(char);
scalar_t__ ispunct(char);
char *UrlEncodeChar(char *dest, char c) {
  div_t sdiv;
  assert(dest != NULL);
  if (ispunct(c) || iscntrl(c)) {
    if ((c != '-') && (c != '@') && (c != '*') && (c != '_')) {
      *dest++ = '%';
      sdiv = div(c, 16);
      *dest++ = hextoc(sdiv.quot);
      *dest++ = hextoc(sdiv.rem);
      return (dest);
    }
  } else if (c == ' ')
    c = '+';
  *dest++ = c;
  return (dest);
}


x86 assembly (clang, -O0):
<UrlEncodeChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movsbl -0x11(%rbp),%edi
call   1040 <ispunct@plt>
cmp    $0x0,%rax
jne    119a <UrlEncodeChar+0x4a>
movsbl -0x11(%rbp),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
je     1242 <UrlEncodeChar+0xf2>
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
je     123d <UrlEncodeChar+0xed>
movsbl -0x11(%rbp),%eax
cmp    $0x40,%eax
je     123d <UrlEncodeChar+0xed>
movsbl -0x11(%rbp),%eax
cmp    $0x2a,%eax
je     123d <UrlEncodeChar+0xed>
movsbl -0x11(%rbp),%eax
cmp    $0x5f,%eax
je     123d <UrlEncodeChar+0xed>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x25,(%rax)
mov    $0x10,%esi
movsbl -0x11(%rbp),%edi
call   1060 <div@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <hextoc@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%edi
call   1070 <hextoc@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1274 <UrlEncodeChar+0x124>
jmp    1258 <UrlEncodeChar+0x108>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jne    1253 <UrlEncodeChar+0x103>
movb   $0x2b,-0x11(%rbp)
jmp    1258 <UrlEncodeChar+0x108>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UrlEncodeChar>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
mov    %ebx,%edi
call   1040 <ispunct@plt>
test   %rax,%rax
jne    1180 <UrlEncodeChar+0x30>
movsbl %bl,%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
je     11e1 <UrlEncodeChar+0x91>
lea    -0x2a(%rbx),%eax
cmp    $0x35,%al
ja     11ac <UrlEncodeChar+0x5c>
movzbl %al,%eax
movabs $0x20000000400009,%rcx
bt     %rax,%rcx
jae    11ac <UrlEncodeChar+0x5c>
mov    %bl,(%r14)
add    $0x1,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movb   $0x25,(%r14)
movsbl %bl,%edi
mov    $0x10,%esi
call   1060 <div@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x20,%rdi
call   1070 <hextoc@plt>
mov    %al,0x1(%r14)
mov    %ebx,%edi
call   1070 <hextoc@plt>
mov    %al,0x2(%r14)
add    $0x3,%r14
jmp    11a1 <UrlEncodeChar+0x51>
cmp    $0x20,%bl
movzbl %bl,%eax
mov    $0x2b,%ebx
cmovne %eax,%ebx
jmp    119a <UrlEncodeChar+0x4a>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define i8* @UrlEncodeChar(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca %struct.TYPE_3__
%7 = alloca %struct.TYPE_3__
store i8* %0, i8** %4
store i8 %1, i8* %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8, i8* %5
%13 = call i64 @ispunct(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i8, i8* %5
%17 = call i64 @iscntrl(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %57
19: ; preds = %15, %2
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 45
br i1 %22, label %23, label %56
23: ; preds = %19
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 64
br i1 %26, label %27, label %56
27: ; preds = %23
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 42
br i1 %30, label %31, label %56
31: ; preds = %27
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 95
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
store i8 37, i8* %36
%38 = load i8, i8* %5
%39 = call i64 @div(i8 signext %38, i32 16)
%40 = bitcast %struct.TYPE_3__* %7 to i64*
store i64 %39, i64* %40
%41 = bitcast %struct.TYPE_3__* %6 to i8*
%42 = bitcast %struct.TYPE_3__* %7 to i8*
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i8* @hextoc(i32 %44)
%46 = ptrtoint i8* %45 to i8
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %4
store i8 %46, i8* %47
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i8* @hextoc(i32 %50)
%52 = ptrtoint i8* %51 to i8
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
store i8 %52, i8* %53
%55 = load i8*, i8** %4
store i8* %55, i8** %3
br label %68
56: ; preds = %31, %27, %23, %19
br label %63
57: ; preds = %15
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 32
br i1 %60, label %61, label %62
61: ; preds = %57
store i8 43, i8* %5
br label %62
62: ; preds = %61, %57
br label %63
63: ; preds = %62, %56
%64 = load i8, i8* %5
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %4
store i8 %64, i8* %65
%67 = load i8*, i8** %4
store i8* %67, i8** %3
br label %68
68: ; preds = %63, %35
%69 = load i8*, i8** %3
ret i8* %69
}

LLVM IR (-O2):
define i8* @UrlEncodeChar(i8* writeonly %0, i8 signext %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i64 @ispunct(i8 signext %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i64 @iscntrl(i8 signext %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %8, %2
switch i8 %1, label %12 [
i8 95, label %29
i8 64, label %29
i8 45, label %29
i8 42, label %29
]
12: ; preds = %11
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 37, i8* %0
%14 = tail call i64 @div(i8 signext %1, i32 16)
%15 = trunc i64 %14 to i32
%16 = lshr i64 %14, 32
%17 = trunc i64 %16 to i32
%18 = tail call i8* @hextoc(i32 %17)
%19 = ptrtoint i8* %18 to i64
%20 = trunc i64 %19 to i8
%21 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %20, i8* %13
%22 = tail call i8* @hextoc(i32 %15)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i8
%25 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %24, i8* %21
br label %32
26: ; preds = %8
%27 = icmp eq i8 %1, 32
%28 = select i1 %27, i8 43, i8 %1
br label %29
29: ; preds = %11, %11, %11, %11, %26
%30 = phi i8 [ %1, %11 ], [ %28, %26 ], [ %1, %11 ], [ %1, %11 ], [ %1, %11 ]
%31 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %30, i8* %0
br label %32
32: ; preds = %29, %12
%33 = phi i8* [ %25, %12 ], [ %31, %29 ]
ret i8* %33
}