#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const);
scalar_t__ isalnum(char const);
void urlencode(FILE *fp, const char *s) {
  while (*s != '\0') {
    if (isalnum(*s))
      fprintf(fp, "%c", *s);
    else
      fprintf(fp, "%%%02x", *s & 0xff);
    s++;
  }
}


x86 assembly (clang, -O0):
<urlencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a2 <urlencode+0x82>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     1172 <urlencode+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xe9b(%rip),%rsi
movsbl (%rax),%edx
call   1040 <fprintf@plt>
jmp    1191 <urlencode+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
lea    0xe7a(%rip),%rsi
movsbl %al,%edx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <urlencode+0x10>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urlencode>:
push   %r15
push   %r14
push   %rbx
mov    (%rsi),%al
test   %al,%al
je     1183 <urlencode+0x53>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
lea    0xeb4(%rip),%r15
jmp    1166 <urlencode+0x36>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1183 <urlencode+0x53>
movsbl %al,%edi
call   1030 <isalnum@plt>
movsbl -0x1(%rbx),%edx
test   %rax,%rax
je     1150 <urlencode+0x20>
mov    %edx,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
jmp    115b <urlencode+0x2b>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [7 x i8] c"%%%02x\00"
define void @urlencode(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %28, %2
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %5
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = call i64 @isalnum(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br label %28
20: ; preds = %10
%21 = load i32*, i32** %3
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = and i32 %24, 255
%26 = trunc i32 %25 to i8
%27 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 signext %26)
br label %28
28: ; preds = %20, %15
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
br label %5
31: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%%%02x\00"
define void @urlencode(i32* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %16
%6 = phi i8 [ %18, %16 ], [ %3, %2 ]
%7 = phi i8* [ %17, %16 ], [ %1, %2 ]
%8 = tail call i64 @isalnum(i8 signext %6)
%9 = icmp eq i64 %8, 0
%10 = load i8, i8* %7
br i1 %9, label %14, label %11
11: ; preds = %5
%12 = sext i8 %10 to i32
%13 = tail call i32 @fputc(i32 %12, i32* %0)
br label %16
14: ; preds = %5
%15 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 signext %10)
br label %16
16: ; preds = %14, %11
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %16, %2
ret void
}