#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 */
int /*<<< orphan*/ asprintf(char **, char *, char *, unsigned char);
char *msg_2_spec(unsigned char *str) {
  char *tmp;
  for (tmp = ""; str && *str; str++)
    if ((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z') ||
        (*str >= '0' && *str <= '9') || *str == '_' || *str == '-' ||
        *str == '.')
      asprintf(&tmp, "%s%c", tmp, *str);
    else
      asprintf(&tmp, "%s%%%02X", tmp, *str);
  return tmp;
}


x86 assembly (clang, -O0):
<msg_2_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeea(%rip),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1147 <msg_2_spec+0x37>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1157 <msg_2_spec+0x47>
jmp    1238 <msg_2_spec+0x128>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x61,%eax
jl     1177 <msg_2_spec+0x67>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7a,%eax
jle    11e7 <msg_2_spec+0xd7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x41,%eax
jl     1197 <msg_2_spec+0x87>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5a,%eax
jle    11e7 <msg_2_spec+0xd7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
jl     11b7 <msg_2_spec+0xa7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x39,%eax
jle    11e7 <msg_2_spec+0xd7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5f,%eax
je     11e7 <msg_2_spec+0xd7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2d,%eax
je     11e7 <msg_2_spec+0xd7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2e,%eax
jne    1207 <msg_2_spec+0xf7>
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
lea    -0x10(%rbp),%rdi
lea    0xe06(%rip),%rsi
movzbl (%rax),%ecx
call   1030 <asprintf@plt>
jmp    1222 <msg_2_spec+0x112>
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
lea    -0x10(%rbp),%rdi
lea    0xdeb(%rip),%rsi
movzbl (%rax),%ecx
call   1030 <asprintf@plt>
jmp    1227 <msg_2_spec+0x117>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <msg_2_spec+0x17>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_2_spec>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xee9(%rip),%rax
mov    %rax,0x8(%rsp)
test   %rdi,%rdi
je     11b4 <msg_2_spec+0xa4>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     11af <msg_2_spec+0x9f>
add    $0x1,%rbx
lea    0xeba(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xeb3(%rip),%r12
movabs $0x4000000000003,%r13
jmp    117b <msg_2_spec+0x6b>
xchg   %ax,%ax
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <asprintf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11af <msg_2_spec+0x9f>
mov    %eax,%edx
and    $0xdf,%dl
add    $0xbf,%dl
movzbl %al,%ecx
cmp    $0x1a,%dl
jb     1160 <msg_2_spec+0x50>
lea    -0x30(%rax),%edx
cmp    $0xa,%dl
jb     1160 <msg_2_spec+0x50>
add    $0xd3,%al
cmp    $0x32,%al
ja     11a2 <msg_2_spec+0x92>
movzbl %al,%eax
bt     %rax,%r13
jb     1160 <msg_2_spec+0x50>
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
jmp    116b <msg_2_spec+0x5b>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%c\00"
@.str.2 = [9 x i8] c"%s%%%02X\00"
define i8* @msg_2_spec(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %70, %1
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br label %12
12: ; preds = %7, %4
%13 = phi i1 [ false, %4 ], [ %11, %7 ]
br i1 %13, label %14, label %73
14: ; preds = %12
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp sge i32 %17, 97
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp sle i32 %22, 122
br i1 %23, label %59, label %24
24: ; preds = %19, %14
%25 = load i8*, i8** %2
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp sge i32 %27, 65
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp sle i32 %32, 90
br i1 %33, label %59, label %34
34: ; preds = %29, %24
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp sge i32 %37, 48
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp sle i32 %42, 57
br i1 %43, label %59, label %44
44: ; preds = %39, %34
%45 = load i8*, i8** %2
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp eq i32 %47, 95
br i1 %48, label %59, label %49
49: ; preds = %44
%50 = load i8*, i8** %2
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp eq i32 %52, 45
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 46
br i1 %58, label %59, label %64
59: ; preds = %54, %49, %44, %39, %29, %19
%60 = load i8*, i8** %3
%61 = load i8*, i8** %2
%62 = load i8, i8* %61
%63 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %60, i8 zeroext %62)
br label %69
64: ; preds = %54
%65 = load i8*, i8** %3
%66 = load i8*, i8** %2
%67 = load i8, i8* %66
%68 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %65, i8 zeroext %67)
br label %69
69: ; preds = %64, %59
br label %70
70: ; preds = %69
%71 = load i8*, i8** %2
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %2
br label %4
73: ; preds = %12
%74 = load i8*, i8** %3
ret i8* %74
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%c\00"
@.str.2 = [9 x i8] c"%s%%%02X\00"
define i8* @msg_2_spec(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %30, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %5, %24
%9 = phi i8 [ %26, %24 ], [ %6, %5 ]
%10 = phi i8* [ %25, %24 ], [ %0, %5 ]
%11 = and i8 %9, -33
%12 = add i8 %11, -65
%13 = icmp ult i8 %12, 26
%14 = add i8 %9, -48
%15 = icmp ult i8 %14, 10
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %18, label %17
17: ; preds = %8
switch i8 %9, label %21 [
i8 95, label %18
i8 45, label %18
i8 46, label %18
]
18: ; preds = %17, %17, %17, %8
%19 = load i8*, i8** %2
%20 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8 zeroext %9)
br label %24
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8 zeroext %9)
br label %24
24: ; preds = %18, %21
%25 = getelementptr inbounds i8, i8* %10, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %8
28: ; preds = %24, %5
%29 = load i8*, i8** %2
br label %30
30: ; preds = %28, %1
%31 = phi i8* [ %29, %28 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %31
}