#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 const *);
scalar_t__ tolower(char const);
char *openconnect__strcasestr(const char *haystack, const char *needle) {
  int hlen = strlen(haystack);
  int nlen = strlen(needle);
  int i, j;
  for (i = 0; i < hlen - nlen + 1; i++) {
    for (j = 0; j < nlen; j++) {
      if (tolower(haystack[i + j]) != tolower(needle[j]))
        break;
    }
    if (j == nlen)
      return (char *)haystack + i;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<openconnect__strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11fc <openconnect__strcasestr+0xdc>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c9 <openconnect__strcasestr+0xa9>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11b6 <openconnect__strcasestr+0x96>
jmp    11c9 <openconnect__strcasestr+0xa9>
jmp    11bb <openconnect__strcasestr+0x9b>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116a <openconnect__strcasestr+0x4a>
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11e9 <openconnect__strcasestr+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <openconnect__strcasestr+0xe4>
jmp    11ee <openconnect__strcasestr+0xce>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <openconnect__strcasestr+0x2f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openconnect__strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
jge    114e <openconnect__strcasestr+0x2e>
xor    %eax,%eax
jmp    11df <openconnect__strcasestr+0xbf>
add    $0x1,%ebp
mov    %eax,%ebx
mov    %r15,0x8(%rsp)
xor    %r14d,%r14d
mov    %eax,0x4(%rsp)
mov    %rbp,0x10(%rsp)
mov    $0x0,%r12d
test   %eax,%eax
jle    11b4 <openconnect__strcasestr+0x94>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%r12,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rbp
movsbl 0x0(%r13,%r12,1),%edi
call   1040 <tolower@plt>
cmp    %rax,%rbp
jne    11b0 <openconnect__strcasestr+0x90>
add    $0x1,%r12
cmp    %r12,%rbx
jne    1180 <openconnect__strcasestr+0x60>
jmp    11d4 <openconnect__strcasestr+0xb4>
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
cmp    %eax,%r12d
je     11d4 <openconnect__strcasestr+0xb4>
add    $0x1,%r14
add    $0x1,%r15
mov    0x10(%rsp),%rbp
cmp    %rbp,%r14
mov    0x4(%rsp),%eax
jne    1164 <openconnect__strcasestr+0x44>
jmp    1147 <openconnect__strcasestr+0x27>
mov    %r14d,%ecx
mov    0x8(%rsp),%rax
add    %rcx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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