#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__ strchr(char const *, char const);
int strlen(char const *);
int switch_needs_url_encode(const char *s) {
  const char hex[] = "0123456789ABCDEF";
  const char *p, *e = (*s == '\0' ? s : s + strlen(s) - 1);
  for (p = s; p && *p; p++) {
    if (*p == '%' && e - p > 1) {
      if (strchr(hex, *(p + 1)) && strchr(hex, *(p + 2))) {
        p++;
        continue;
      }
    }
    if (strchr("\r\n \"#%&+:;<=>?@[\\]^`{|}", *p)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<switch_needs_url_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec8(%rip),%al
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <switch_needs_url_encode+0x48>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    118d <switch_needs_url_encode+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x51(%rbp)
je     11bd <switch_needs_url_encode+0x9d>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11cd <switch_needs_url_encode+0xad>
jmp    127d <switch_needs_url_encode+0x15d>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    123e <switch_needs_url_encode+0x11e>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1,%rax
jle    123e <switch_needs_url_encode+0x11e>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1239 <switch_needs_url_encode+0x119>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
movsbl 0x2(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1239 <switch_needs_url_encode+0x119>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    126c <switch_needs_url_encode+0x14c>
jmp    123e <switch_needs_url_encode+0x11e>
mov    -0x38(%rbp),%rax
lea    0xdc8(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1267 <switch_needs_url_encode+0x147>
movl   $0x1,-0x4(%rbp)
jmp    1284 <switch_needs_url_encode+0x164>
jmp    126c <switch_needs_url_encode+0x14c>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    119d <switch_needs_url_encode+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switch_needs_url_encode>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movaps 0xecb(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
cmpb   $0x0,(%rdi)
mov    %rdi,%r12
je     1158 <switch_needs_url_encode+0x38>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%r12
add    $0xffffffffffffffff,%r12
mov    %rsp,%r14
lea    0xeaf(%rip),%r15
jmp    1188 <switch_needs_url_encode+0x68>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %al,%al
je     11ca <switch_needs_url_encode+0xaa>
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11c3 <switch_needs_url_encode+0xa3>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1170 <switch_needs_url_encode+0x50>
mov    %r12,%rax
sub    %rbx,%rax
cmp    $0x2,%rax
jl     1174 <switch_needs_url_encode+0x54>
movsbl 0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1174 <switch_needs_url_encode+0x54>
movsbl 0x2(%rbx),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1174 <switch_needs_url_encode+0x54>
add    $0x1,%rbx
jmp    1184 <switch_needs_url_encode+0x64>
mov    $0x1,%eax
jmp    11cc <switch_needs_url_encode+0xac>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.switch_needs_url_encode.hex = [17 x i8] c"0123456789ABCDEF\00"
@.str = [24 x i8] c"\0D\0A \22#%&+:;<=>?@[\\]^`{|}\00"
define i32 @switch_needs_url_encode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [17 x i8]
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = bitcast [17 x i8]* %4 to i8*
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %3
br label %21
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
br label %21
21: ; preds = %14, %12
%22 = phi i8* [ %13, %12 ], [ %20, %14 ]
store i8* %22, i8** %6
%23 = load i8*, i8** %3
store i8* %23, i8** %5
br label %24
24: ; preds = %71, %21
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br label %32
32: ; preds = %27, %24
%33 = phi i1 [ false, %24 ], [ %31, %27 ]
br i1 %33, label %34, label %74
34: ; preds = %32
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 37
br i1 %38, label %39, label %64
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i8*, i8** %5
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = icmp sgt i64 %44, 1
br i1 %45, label %46, label %64
46: ; preds = %39
%47 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = call i64 @strchr(i8* %47, i8 signext %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %46
%54 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 2
%57 = load i8, i8* %56
%58 = call i64 @strchr(i8* %54, i8 signext %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %5
br label %71
63: ; preds = %53, %46
br label %64
64: ; preds = %63, %39, %34
%65 = load i8*, i8** %5
%66 = load i8, i8* %65
%67 = call i64 @strchr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %64
store i32 1, i32* %2
br label %75
70: ; preds = %64
br label %71
71: ; preds = %70, %60
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %5
br label %24
74: ; preds = %32
store i32 0, i32* %2
br label %75
75: ; preds = %74, %69
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@__const.switch_needs_url_encode.hex = [17 x i8] c"0123456789ABCDEF\00"
@.str = [24 x i8] c"\0D\0A \22#%&+:;<=>?@[\\]^`{|}\00"
define i32 @switch_needs_url_encode(i8* %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
br label %11
11: ; preds = %1, %6
%12 = phi i8* [ %10, %6 ], [ %0, %1 ]
%13 = ptrtoint i8* %12 to i64
br label %14
14: ; preds = %35, %11
%15 = phi i8* [ %0, %11 ], [ %37, %35 ]
%16 = load i8, i8* %15
switch i8 %16, label %31 [
i8 0, label %38
i8 37, label %17
]
17: ; preds = %14
%18 = ptrtoint i8* %15 to i64
%19 = sub i64 %13, %18
%20 = icmp sgt i64 %19, 1
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %15, i64 1
%23 = load i8, i8* %22
%24 = call i64 @strchr(i8* %3, i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %15, i64 2
%28 = load i8, i8* %27
%29 = call i64 @strchr(i8* %3, i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %14, %21, %26, %17
%32 = load i8, i8* %15
%33 = call i64 @strchr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %26, %31
%36 = phi i8* [ %15, %31 ], [ %22, %26 ]
%37 = getelementptr inbounds i8, i8* %36, i64 1
br label %14
38: ; preds = %14, %31
%39 = phi i32 [ 1, %31 ], [ 0, %14 ]
ret i32 %39
}