#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__ isalpha(char);
scalar_t__ isdigit(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *urlify(char *input) {
  static char output[600];
  char *i, *o;
  static char hex[] = "0123456789abcdef";
  memset(output, 0, 600);
  for (i = input, o = output; *i; i++) {
    if (isspace(*i)) {
      *o++ = '+';
    } else if (isalpha(*i) || isdigit(*i)) {
      *o++ = *i;
    } else {
      *o++ = '%';
      *o++ = hex[(*i) / 16];
      *o++ = hex[(*i) % 16];
    }
  }
  return output;
}


x86 assembly (clang, -O0):
<urlify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f2d(%rip),%rdi
xor    %esi,%esi
mov    $0x258,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0x2f12(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     127b <urlify+0x13b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11ac <urlify+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2b,(%rax)
jmp    1265 <urlify+0x125>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
jne    11d8 <urlify+0x98>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11f4 <urlify+0xb4>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1260 <urlify+0x120>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x25,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
lea    0x2e31(%rip),%rax
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
movsbl (%rax),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0x2e04(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1265 <urlify+0x125>
jmp    126a <urlify+0x12a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1172 <urlify+0x32>
lea    0x2dfe(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urlify>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0x2f01(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x258,%edx
call   1040 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     1208 <urlify+0xc8>
lea    0xe91(%rip),%r15
nop
movsbl %al,%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     1190 <urlify+0x50>
movb   $0x2b,(%r14)
jmp    11b0 <urlify+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx),%edi
call   1060 <isalpha@plt>
test   %rax,%rax
jne    11aa <urlify+0x6a>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11c2 <urlify+0x82>
movzbl (%rbx),%eax
mov    %al,(%r14)
add    $0x1,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <urlify+0x30>
jmp    1208 <urlify+0xc8>
movb   $0x25,(%r14)
movzbl (%rbx),%eax
mov    %eax,%ecx
sar    $0x7,%cl
shr    $0x4,%cl
add    %al,%cl
sar    $0x4,%cl
movsbq %cl,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,0x1(%r14)
movzbl (%rbx),%eax
mov    %eax,%ecx
sar    $0x7,%cl
shr    $0x4,%cl
add    %al,%cl
and    $0xf0,%cl
sub    %cl,%al
movsbq %al,%rax
movzbl (%rax,%r15,1),%eax
mov    %al,0x2(%r14)
add    $0x3,%r14
jmp    11b4 <urlify+0x74>
lea    0x2e41(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@urlify.output = internal global [600 x i8] zeroinitializer
@urlify.hex = internal global [17 x i8] c"0123456789abcdef\00"
define i8* @urlify(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i32 @memset(i8* getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0), i32 0, i32 600)
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i8* getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0), i8** %4
br label %7
7: ; preds = %57, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %60
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = call i64 @isspace(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
store i8 43, i8* %17
br label %56
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = call i64 @isalpha(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i64 @isdigit(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24, %19
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 %31, i8* %32
br label %55
34: ; preds = %24
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
store i8 37, i8* %35
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = sdiv i32 %39, 16
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [17 x i8], [17 x i8]* @urlify.hex, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %4
store i8 %43, i8* %44
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = srem i32 %48, 16
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [17 x i8], [17 x i8]* @urlify.hex, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
store i8 %52, i8* %53
br label %55
55: ; preds = %34, %29
br label %56
56: ; preds = %55, %16
br label %57
57: ; preds = %56
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %3
br label %7
60: ; preds = %7
ret i8* getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0)
}

LLVM IR (-O2):
@urlify.output = internal global [600 x i8] zeroinitializer
@urlify.hex = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define i8* @urlify(i8* nocapture %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0), i32 0, i32 600)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %43, label %5
5: ; preds = %1, %38
%6 = phi i8 [ %41, %38 ], [ %3, %1 ]
%7 = phi i8* [ %39, %38 ], [ getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0), %1 ]
%8 = phi i8* [ %40, %38 ], [ %0, %1 ]
%9 = tail call i64 @isspace(i8 signext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 43, i8* %7
br label %38
13: ; preds = %5
%14 = load i8, i8* %8
%15 = tail call i64 @isalpha(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8, i8* %8
%19 = tail call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17, %13
%22 = load i8, i8* %8
%23 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %22, i8* %7
br label %38
24: ; preds = %17
%25 = getelementptr inbounds i8, i8* %7, i64 1
store i8 37, i8* %7
%26 = load i8, i8* %8
%27 = sdiv i8 %26, 16
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds [17 x i8], [17 x i8]* @urlify.hex, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %7, i64 2
store i8 %30, i8* %25
%32 = load i8, i8* %8
%33 = srem i8 %32, 16
%34 = sext i8 %33 to i64
%35 = getelementptr inbounds [17 x i8], [17 x i8]* @urlify.hex, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = getelementptr inbounds i8, i8* %7, i64 3
store i8 %36, i8* %31
br label %38
38: ; preds = %11, %24, %21
%39 = phi i8* [ %12, %11 ], [ %23, %21 ], [ %37, %24 ]
%40 = getelementptr inbounds i8, i8* %8, i64 1
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %5
43: ; preds = %38, %1
ret i8* getelementptr inbounds ([600 x i8], [600 x i8]* @urlify.output, i64 0, i64 0)
}