#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*/ memset(char *, char, int);
char *strcasestr(char const *, char const *);
int strlen(char const *);
char find_matches(const char *haystack, const char *needle, char *bitmap) {
  int nlen = strlen(needle);
  const char *index = haystack;
  char match = 0;
  for (;;) {
    int pos = -1;
    index = strcasestr(index, needle);
    if (!index)
      break;
    match = 1;
    pos = (int)(index - haystack);
    memset(&bitmap[pos], '1', nlen);
    index += nlen;
  }
  return match;
}


x86 assembly (clang, -O0):
<find_matches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0xffffffff,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcasestr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1184 <find_matches+0x54>
jmp    11c4 <find_matches+0x94>
movb   $0x1,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%edx
mov    $0x31,%esi
call   1040 <memset@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    115c <find_matches+0x2c>
movsbl -0x29(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_matches>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcasestr@plt>
test   %rax,%rax
je     11a2 <find_matches+0x72>
mov    %rax,%rbx
movslq %r13d,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
sub    %r15d,%eax
movslq %eax,%rdi
add    %r14,%rdi
mov    $0x31,%esi
mov    %r13d,%edx
call   1040 <memset@plt>
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcasestr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <find_matches+0x40>
mov    $0x1,%al
jmp    11a4 <find_matches+0x74>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define signext i8 @find_matches(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i8* @strcasestr(i8* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = ptrtoint i8* %0 to i64
%9 = sext i32 %4 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i8* [ %5, %7 ], [ %19, %10 ]
%12 = ptrtoint i8* %11 to i64
%13 = sub i64 %12, %8
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds i8, i8* %2, i64 %15
%17 = tail call i32 @memset(i8* %16, i8 signext 49, i32 %4)
%18 = getelementptr inbounds i8, i8* %11, i64 %9
%19 = tail call i8* @strcasestr(i8* %18, i8* %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %10
21: ; preds = %10, %3
%22 = phi i8 [ 0, %3 ], [ 1, %10 ]
ret i8 %22
}