#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 strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int string_search(char *string, char *search) {
  int searchLen;
  int i;
  searchLen = strlen(search);
  if (searchLen > strlen(string)) {
    return (0);
  }
  for (i = 0; i < strlen(string) - searchLen + 1; i++) {
    if (!strncasecmp((char *)&string[i], search, searchLen)) {
      return (1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<string_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jle    1164 <string_search+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <string_search+0xb3>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11cc <string_search+0xac>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11b9 <string_search+0x99>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <string_search+0xb3>
jmp    11be <string_search+0x9e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116b <string_search+0x4b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_search>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    %eax,%ebx
jg     1193 <string_search+0x73>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %ebx,%eax
jl     1193 <string_search+0x73>
mov    $0xffffffffffffffff,%rbp
nopw   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
add    $0x1,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
je     118d <string_search+0x6d>
mov    %r12,%rdi
call   1030 <strlen@plt>
sub    %ebx,%eax
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1160 <string_search+0x40>
jmp    1193 <string_search+0x73>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @string_search(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %3, %4
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp slt i32 %7, %3
br i1 %8, label %20, label %15
9: ; preds = %15
%10 = add nuw nsw i64 %16, 1
%11 = tail call i32 @strlen(i8* %0)
%12 = sub nsw i32 %11, %3
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %16, %13
br i1 %14, label %15, label %20
15: ; preds = %6, %9
%16 = phi i64 [ %10, %9 ], [ 0, %6 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = tail call i32 @strncasecmp(i8* %17, i8* %1, i32 %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %9
20: ; preds = %15, %9, %6, %2
%21 = phi i32 [ 0, %2 ], [ 0, %6 ], [ 1, %15 ], [ 0, %9 ]
ret i32 %21
}