char *strcasestr(char *s1, char *s2) {
  int l;
  l = strlen(s2);
  while (s1[0]) {
    if (!strncasecmp2(s1, s2, l)) {
      printf("strlen:%d,s1:%s\r\n,s1c1: %d,s1c1lower%d,s2c2: "
             "%d,s2c2lower%d,c1-'a':%d\n\r",
             l, s1, *s1, tolower(*s1), s2, tolower(*s2), *s1 - 'a');
      return s1;
    }
    s1++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1212 <strcasestr+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1060 <strncasecmp2@plt>
cmp    $0x0,%eax
jne    1201 <strcasestr+0xc1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    %eax,%r10d
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x61,%eax
lea    0xe1b(%rip),%rdi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121a <strcasestr+0xda>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <strcasestr+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     118e <strcasestr+0x4e>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <strncasecmp2@plt>
test   %eax,%eax
je     1192 <strcasestr+0x52>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1170 <strcasestr+0x30>
xor    %ebx,%ebx
jmp    11d6 <strcasestr+0x96>
movsbl (%rbx),%r12d
mov    %r12d,%edi
call   1050 <tolower@plt>
mov    %eax,%r13d
movsbl (%r14),%edi
call   1050 <tolower@plt>
mov    %eax,%r10d
lea    -0x61(%r12),%ebp
lea    0xe47(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    %r14,%r9
xor    %eax,%eax
push   %rbp
push   %r10
call   1040 <printf@plt>
add    $0x10,%rsp
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [72 x i8] c"strlen:%d,s1:%s\0D\0A,s1c1: %d,s1c1lower%d,s2c2: %d,s2c2lower%d,c1-'a':%d\0A\0D\00"
define i8* @strcasestr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %6
br label %10
10: ; preds = %42, %2
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strncasecmp2 to i32 (i8*, i8*, i32, ...)*)(i8* %16, i8* %17, i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %42, label %21
21: ; preds = %15
%22 = load i32, i32* %6
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 @tolower(i32 %29)
%31 = load i8*, i8** %5
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 @tolower(i32 %34)
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 97
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %23, i32 %26, i32 %30, i8* %31, i32 %35, i32 %39)
%41 = load i8*, i8** %4
store i8* %41, i8** %3
br label %46
42: ; preds = %15
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
br label %10
45: ; preds = %10
store i8* null, i8** %3
br label %46
46: ; preds = %45, %21
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@.str = [72 x i8] c"strlen:%d,s1:%s\0D\0A,s1c1: %d,s1c1lower%d,s2c2: %d,s2c2lower%d,c1-'a':%d\0A\0D\00"
define i8* @strcasestr(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %2, %20
%8 = phi i8* [ %21, %20 ], [ %0, %2 ]
%9 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @strncasecmp2 to i32 (i8*, i8*, i32, ...)*)(i8* %8, i8* %1, i32 %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i8, i8* %8
%13 = sext i8 %12 to i32
%14 = tail call i32 @tolower(i32 %13)
%15 = load i8, i8* %1
%16 = sext i8 %15 to i32
%17 = tail call i32 @tolower(i32 %16)
%18 = add nsw i32 %13, -97
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %8, i32 %13, i32 %14, i8* %1, i32 %17, i32 %18)
br label %24
20: ; preds = %7
%21 = getelementptr inbounds i8, i8* %8, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %7
24: ; preds = %20, %2, %11
%25 = phi i8* [ %8, %11 ], [ null, %2 ], [ null, %20 ]
ret i8* %25
}