#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__ isalnum(unsigned char const);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char const);
void url_armor_string_unchecked(const unsigned char *s, unsigned char *buf) {
  unsigned char *b = buf;
  const unsigned char *p = s;
  *b = 0;
  if (!s)
    return;
  for (; *p; p++) {
    if (isalnum(*p))
      *b++ = *p;
    else
      b += sprintf(b, "%%%02x", *p);
  }
  *b = 0;
}


x86 assembly (clang, -O0):
<url_armor_string_unchecked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <url_armor_string_unchecked+0x37>
jmp    11df <url_armor_string_unchecked+0xbf>
jmp    115c <url_armor_string_unchecked+0x3c>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d8 <url_armor_string_unchecked+0xb8>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     119b <url_armor_string_unchecked+0x7b>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11c2 <url_armor_string_unchecked+0xa2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
lea    0xe56(%rip),%rsi
movzbl (%rax),%edx
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11c7 <url_armor_string_unchecked+0xa7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115c <url_armor_string_unchecked+0x3c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_armor_string_unchecked>:
push   %r15
push   %r14
push   %rbx
movb   $0x0,(%rsi)
test   %rdi,%rdi
je     118c <url_armor_string_unchecked+0x6c>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1188 <url_armor_string_unchecked+0x68>
add    $0x1,%rbx
lea    0xebc(%rip),%r15
jmp    116e <url_armor_string_unchecked+0x4e>
cs nopw 0x0(%rax,%rax,1)
movzbl %cl,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
cltq
add    %rax,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1188 <url_armor_string_unchecked+0x68>
movzbl %al,%edi
call   1030 <isalnum@plt>
movzbl -0x1(%rbx),%ecx
test   %rax,%rax
je     1150 <url_armor_string_unchecked+0x30>
mov    %cl,(%r14)
add    $0x1,%r14
jmp    1163 <url_armor_string_unchecked+0x43>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%%%02x\00"
define void @url_armor_string_unchecked(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
%8 = load i8*, i8** %3
store i8* %8, i8** %6
%9 = load i8*, i8** %5
store i8 0, i8* %9
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
br label %42
13: ; preds = %2
br label %14
14: ; preds = %37, %13
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = call i64 @isalnum(i8 zeroext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 %25, i8* %26
br label %36
28: ; preds = %18
%29 = load i8*, i8** %5
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
br label %36
36: ; preds = %28, %23
br label %37
37: ; preds = %36
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
br label %14
40: ; preds = %14
%41 = load i8*, i8** %5
store i8 0, i8* %41
br label %42
42: ; preds = %40, %12
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%%02x\00"
define void @url_armor_string_unchecked(i8* %0, i8* nocapture writeonly %1) {
store i8 0, i8* %1
%3 = icmp eq i8* %0, null
br i1 %3, label %27, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %4, %20
%8 = phi i8 [ %23, %20 ], [ %5, %4 ]
%9 = phi i8* [ %22, %20 ], [ %0, %4 ]
%10 = phi i8* [ %21, %20 ], [ %1, %4 ]
%11 = tail call i64 @isalnum(i8 zeroext %8)
%12 = icmp eq i64 %11, 0
%13 = load i8, i8* %9
br i1 %12, label %16, label %14
14: ; preds = %7
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %13, i8* %10
br label %20
16: ; preds = %7
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
br label %20
20: ; preds = %14, %16
%21 = phi i8* [ %15, %14 ], [ %19, %16 ]
%22 = getelementptr inbounds i8, i8* %9, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %7
25: ; preds = %20, %4
%26 = phi i8* [ %1, %4 ], [ %21, %20 ]
store i8 0, i8* %26
br label %27
27: ; preds = %2, %25
ret void
}