#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ block(char *, size_t, char const *);
scalar_t__ memchr(char const *, char, size_t);
void test_path(const char *needle, size_t len) {
  if (memchr(needle, ' ', len) || memchr(needle, '%', len))
    return;
  assert(block("%.*s", len, needle));
  assert(block("http://example.com/some/path%.*s/and/some/more", len, needle));
  assert(block("http://example.com/some/path?and=query&%.*s", len, needle));
}


x86 assembly (clang, -O0):
<test_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x20,%esi
call   1030 <memchr@plt>
cmp    $0x0,%rax
jne    1178 <test_path+0x48>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x25,%esi
call   1030 <memchr@plt>
cmp    $0x0,%rax
je     117d <test_path+0x4d>
jmp    11ce <test_path+0x9e>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xeca(%rip),%rdi
call   1050 <block@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe59(%rip),%rdi
call   1050 <block@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe6d(%rip),%rdi
call   1050 <block@plt>
mov    %eax,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x20,%esi
mov    %r14,%rdx
call   1030 <memchr@plt>
test   %rax,%rax
jne    1161 <test_path+0x31>
mov    %rbx,%rdi
mov    $0x25,%esi
mov    %r14,%rdx
call   1030 <memchr@plt>
test   %rax,%rax
je     1169 <test_path+0x39>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xee6(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <block@plt>
mov    %eax,%edi
call   1040 <assert@plt>
lea    0xe77(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <block@plt>
mov    %eax,%edi
call   1040 <assert@plt>
lea    0xe8d(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <block@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <assert@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%.*s\00"
@.str.1 = [47 x i8] c"http://example.com/some/path%.*s/and/some/more\00"
@.str.2 = [44 x i8] c"http://example.com/some/path?and=query&%.*s\00"
define void @test_path(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i8*, i8** %3
%6 = load i64, i64* %4
%7 = call i64 @memchr(i8* %5, i8 signext 32, i64 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = call i64 @memchr(i8* %10, i8 signext 37, i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9, %2
br label %28
15: ; preds = %9
%16 = load i64, i64* %4
%17 = load i8*, i8** %3
%18 = call i32 @block(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %16, i8* %17)
%19 = call i32 @assert(i32 %18)
%20 = load i64, i64* %4
%21 = load i8*, i8** %3
%22 = call i32 @block(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %20, i8* %21)
%23 = call i32 @assert(i32 %22)
%24 = load i64, i64* %4
%25 = load i8*, i8** %3
%26 = call i32 @block(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %24, i8* %25)
%27 = call i32 @assert(i32 %26)
br label %28
28: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.*s\00"
@.str.1 = [47 x i8] c"http://example.com/some/path%.*s/and/some/more\00"
@.str.2 = [44 x i8] c"http://example.com/some/path?and=query&%.*s\00"
define void @test_path(i8* %0, i64 %1) {
%3 = tail call i64 @memchr(i8* %0, i8 signext 32, i64 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = tail call i64 @memchr(i8* %0, i8 signext 37, i64 %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = tail call i32 @block(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %1, i8* %0)
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @block(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i64 %1, i8* %0)
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @block(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i64 %1, i8* %0)
%14 = tail call i32 @assert(i32 %13)
br label %15
15: ; preds = %2, %5, %8
ret void
}