#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 */
void *memchr(void *, char, int);
int strlen(char *);
int /*<<< orphan*/ strncmp(void *, char *, int);
int anywhere(void *buf, char *str) {
  int k, n;
  void *s;
  k = strlen(str);
  n = 512 - k;
  s = memchr(buf, *str, n);
  while (s) {
    if (!strncmp(s, str, k))
      return 1;
    s++;
    n = 512 - k - (int)(s - buf);
    s = memchr(s, *str, n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<anywhere>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x200,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x20(%rbp),%edx
movsbl %al,%esi
call   1050 <memchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e2 <anywhere+0xb2>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a0 <anywhere+0x70>
movl   $0x1,-0x4(%rbp)
jmp    11e9 <anywhere+0xb9>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x200,%eax
sub    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x20(%rbp),%edx
movsbl %al,%esi
call   1050 <memchr@plt>
mov    %rax,-0x28(%rbp)
jmp    1170 <anywhere+0x40>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anywhere>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    $0x200,%r13d
sub    %eax,%r13d
movsbl (%rbx),%esi
mov    %r14,%rdi
mov    %r13d,%edx
call   1050 <memchr@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11a9 <anywhere+0x79>
mov    %rax,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a3 <anywhere+0x73>
add    $0x1,%rbp
mov    %r14d,%edx
sub    %ebp,%edx
add    %r13d,%edx
movsbl (%rbx),%esi
mov    %rbp,%rdi
call   1050 <memchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1170 <anywhere+0x40>
jmp    11a9 <anywhere+0x79>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @anywhere(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = sub nsw i32 512, %11
store i32 %12, i32* %7
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = load i32, i32* %7
%17 = call i8* @memchr(i8* %13, i8 signext %15, i32 %16)
store i8* %17, i8** %8
br label %18
18: ; preds = %28, %2
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %45
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = call i32 @strncmp(i8* %22, i8* %23, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21
store i32 1, i32* %3
br label %46
28: ; preds = %21
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %8
%31 = load i32, i32* %6
%32 = sub nsw i32 512, %31
%33 = load i8*, i8** %8
%34 = load i8*, i8** %4
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = sub nsw i32 %32, %38
store i32 %39, i32* %7
%40 = load i8*, i8** %8
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = load i32, i32* %7
%44 = call i8* @memchr(i8* %40, i8 signext %42, i32 %43)
store i8* %44, i8** %8
br label %18
45: ; preds = %18
store i32 0, i32* %3
br label %46
46: ; preds = %45, %27
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @anywhere(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = sub nsw i32 512, %3
%5 = load i8, i8* %1
%6 = tail call i8* @memchr(i8* %0, i8 signext %5, i32 %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %2
%9 = ptrtoint i8* %0 to i64
br label %10
10: ; preds = %8, %14
%11 = phi i8* [ %6, %8 ], [ %21, %14 ]
%12 = tail call i32 @strncmp(i8* %11, i8* %1, i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = ptrtoint i8* %15 to i64
%17 = sub i64 %9, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %4, %18
%20 = load i8, i8* %1
%21 = tail call i8* @memchr(i8* %15, i8 signext %20, i32 %19)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %10
23: ; preds = %10, %14, %2
%24 = phi i32 [ 0, %2 ], [ 0, %14 ], [ 1, %10 ]
ret i32 %24
}