#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 */
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
char tolower(unsigned char);
char *transport_strcasestr(const char *buffer, const char *key) {
  char c, sc;
  size_t len;
  if ((c = *key++) != 0) {
    c = tolower((unsigned char)c);
    len = strlen(key);
    do {
      do {
        if ((sc = *buffer++) == 0)
          return (NULL);
      } while ((char)tolower((unsigned char)sc) != c);
    } while (strncasecmp(buffer, key, len) != 0);
    buffer--;
  }
  return ((char *)buffer);
}


x86 assembly (clang, -O0):
<transport_strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11f4 <transport_strcasestr+0xc4>
movzbl -0x19(%rbp),%edi
call   1040 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    117e <transport_strcasestr+0x4e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jne    11ab <transport_strcasestr+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    11fc <transport_strcasestr+0xcc>
jmp    11b0 <transport_strcasestr+0x80>
movzbl -0x1a(%rbp),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    117e <transport_strcasestr+0x4e>
jmp    11cd <transport_strcasestr+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1179 <transport_strcasestr+0x49>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transport_strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
mov    (%rsi),%al
test   %al,%al
je     1191 <transport_strcasestr+0x61>
mov    %rsi,%r14
add    $0x1,%r14
movzbl %al,%edi
call   1040 <tolower@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
xchg   %ax,%ax
movzbl 0x0(%rbp),%eax
test   %al,%al
je     1196 <transport_strcasestr+0x66>
mov    %rbp,%rbx
add    $0x1,%rbp
movzbl %al,%edi
call   1040 <tolower@plt>
cmp    %r15b,%al
jne    1160 <transport_strcasestr+0x30>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    1160 <transport_strcasestr+0x30>
jmp    1198 <transport_strcasestr+0x68>
mov    %rbp,%rbx
jmp    1198 <transport_strcasestr+0x68>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @transport_strcasestr(i8* %0, i8* nocapture %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 1
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call signext i8 @tolower(i8 zeroext %4)
%8 = tail call i64 @strlen(i8* %3)
br label %9
9: ; preds = %17, %6
%10 = phi i8* [ %0, %6 ], [ %11, %17 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %9
%15 = tail call signext i8 @tolower(i8 zeroext %12)
%16 = icmp eq i8 %15, %7
br i1 %16, label %18, label %17
17: ; preds = %14, %18
br label %9
18: ; preds = %14
%19 = tail call i64 @strncasecmp(i8* %11, i8* %3, i64 %8)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %17
21: ; preds = %18, %9, %2
%22 = phi i8* [ %0, %2 ], [ %10, %18 ], [ null, %9 ]
ret i8* %22
}