#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 */
typedef int /*<<< orphan*/ tmp_needle;
typedef int /*<<< orphan*/ tmp_haystack;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ *strstr(char *, char *);
char tolower(char);
int strstr_nocase(const char *haystack, const char *needle) {
  int result = 0;
  if (NULL != haystack && NULL != needle) {
    char tmp_haystack[80];
    char tmp_needle[80];
    int len = 0;
    int i = 0;
    strncpy(tmp_haystack, haystack, sizeof(tmp_haystack) - 1);
    tmp_haystack[sizeof(tmp_haystack) - 1] = '\0';
    strncpy(tmp_needle, needle, sizeof(tmp_needle) - 1);
    tmp_needle[sizeof(tmp_haystack) - 1] = '\0';
    len = strlen(tmp_haystack);
    for (i = 0; i < len; i++) {
      tmp_haystack[i] = tolower(tmp_haystack[i]);
    }
    len = strlen(tmp_needle);
    for (i = 0; i < len; i++) {
      tmp_needle[i] = tolower(tmp_needle[i]);
    }
    if (NULL != strstr(tmp_haystack, tmp_needle)) {
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<strstr_nocase>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
je     12a2 <strstr_nocase+0x162>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     12a2 <strstr_nocase+0x162>
movl   $0x0,-0xc4(%rbp)
movl   $0x0,-0xc8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4f,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x21(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4f,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x71(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc4(%rbp)
movl   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    1212 <strstr_nocase+0xd2>
movslq -0xc8(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1050 <tolower@plt>
mov    %al,%cl
movslq -0xc8(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    11ce <strstr_nocase+0x8e>
lea    -0xc0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc4(%rbp)
movl   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    1278 <strstr_nocase+0x138>
movslq -0xc8(%rbp),%rax
movsbl -0xc0(%rbp,%rax,1),%edi
ff
call   1050 <tolower@plt>
mov    %al,%cl
movslq -0xc8(%rbp),%rax
mov    %cl,-0xc0(%rbp,%rax,1)
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    122e <strstr_nocase+0xee>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     129d <strstr_nocase+0x15d>
movl   $0x1,-0x14(%rbp)
jmp    12a2 <strstr_nocase+0x162>
mov    -0x14(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr_nocase>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     120d <strstr_nocase+0xcd>
mov    %rsi,%rbx
test   %rsi,%rsi
je     120d <strstr_nocase+0xcd>
mov    %rdi,%rsi
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x4f,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x9f(%rsp)
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x4f,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4f(%rsp)
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c7 <strstr_nocase+0x87>
mov    %eax,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x50(%rsp,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,0x50(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11b0 <strstr_nocase+0x70>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f5 <strstr_nocase+0xb5>
mov    %eax,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11e0 <strstr_nocase+0xa0>
lea    0x50(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @strstr_nocase(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* null, %10
br i1 %11, label %12, label %68
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = icmp ne i8* null, %13
br i1 %14, label %15, label %68
15: ; preds = %12
store i32 0, i32* %8
store i32 0, i32* %9
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 79)
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 79
store i8 0, i8* %19
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i32 @strncpy(i8* %20, i8* %21, i32 79)
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 79
store i8 0, i8* %23
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %8
store i32 0, i32* %9
br label %26
26: ; preds = %39, %15
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %30
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %26
42: ; preds = %26
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %8
store i32 0, i32* %9
br label %45
45: ; preds = %58, %42
%46 = load i32, i32* %9
%47 = load i32, i32* %8
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = call signext i8 @tolower(i8 signext %53)
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %49
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %45
61: ; preds = %45
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%64 = call i32* @strstr(i8* %62, i8* %63)
%65 = icmp ne i32* null, %64
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 1, i32* %5
br label %67
67: ; preds = %66, %61
br label %68
68: ; preds = %67, %12, %2
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
define i32 @strstr_nocase(i8* %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %42
8: ; preds = %2
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%11 = call i32 @strncpy(i8* %9, i8* %0, i32 79)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 79
store i8 0, i8* %12
%13 = call i32 @strncpy(i8* %10, i8* %1, i32 79)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 79
store i8 0, i8* %14
%15 = call i32 @strlen(i8* %9)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %8
%18 = zext i32 %15 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %24, %19 ]
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = call signext i8 @tolower(i8 signext %22)
store i8 %23, i8* %21
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %18
br i1 %25, label %26, label %19
26: ; preds = %19, %8
%27 = call i32 @strlen(i8* %10)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = zext i32 %27 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %36, %31 ]
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
store i8 %35, i8* %33
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %30
br i1 %37, label %38, label %31
38: ; preds = %31, %26
%39 = call i32* @strstr(i8* %9, i8* %10)
%40 = icmp ne i32* %39, null
%41 = zext i1 %40 to i32
br label %42
42: ; preds = %38, %2
%43 = phi i32 [ %41, %38 ], [ 0, %2 ]
ret i32 %43
}