#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 */
char *strchr(char const *, char const);
int needEncoding(const char *pValue) {
  const char *pRead = strchr(pValue, '%');
  const char *valid = "0123456789ABCDEFabcdef";
  if (!pRead) {
    return 1;
  }
  if (!strchr(valid, pRead[1])) {
    return 1;
  }
  if (!strchr(valid, pRead[2])) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<needEncoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1150 <needEncoding+0x40>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <needEncoding+0x95>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1177 <needEncoding+0x67>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <needEncoding+0x95>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    119e <needEncoding+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <needEncoding+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<needEncoding>:
push   %rbp
push   %rbx
push   %rax
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1158 <needEncoding+0x48>
mov    %rax,%rbx
movsbl 0x1(%rax),%esi
lea    0xecb(%rip),%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1158 <needEncoding+0x48>
movsbl 0x2(%rbx),%esi
lea    0xeb6(%rip),%rdi
call   1030 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"0123456789ABCDEFabcdef\00"
define i32 @needEncoding(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = load i8, i8* %5
%7 = tail call i8* @strchr(i8* dereferenceable(23) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 signext %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %2, i64 2
%11 = load i8, i8* %10
%12 = tail call i8* @strchr(i8* dereferenceable(23) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = icmp eq i8* %12, null
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %9, %4, %1
%16 = phi i32 [ 1, %1 ], [ 1, %4 ], [ %14, %9 ]
ret i32 %16
}