#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 */
scalar_t__ StartsWithIgnoreCase(char const *, char const *);
scalar_t__ strlen(char const *);
const char *FindSubstringIgnoreCase(const char *s, const char *substring) {
  if (strlen(s) >= strlen(substring)) {
    for (; *s; ++s) {
      if (StartsWithIgnoreCase(s, substring)) {
        return s;
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<FindSubstringIgnoreCase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jl     11a7 <FindSubstringIgnoreCase+0x87>
jmp    115b <FindSubstringIgnoreCase+0x3b>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a2 <FindSubstringIgnoreCase+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <StartsWithIgnoreCase@plt>
cmp    $0x0,%rax
je     118c <FindSubstringIgnoreCase+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <FindSubstringIgnoreCase+0x8f>
jmp    1191 <FindSubstringIgnoreCase+0x71>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115b <FindSubstringIgnoreCase+0x3b>
jmp    11a7 <FindSubstringIgnoreCase+0x87>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindSubstringIgnoreCase>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r15
jl     116a <FindSubstringIgnoreCase+0x4a>
cmpb   $0x0,(%rbx)
je     116a <FindSubstringIgnoreCase+0x4a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <StartsWithIgnoreCase@plt>
test   %rax,%rax
jne    116c <FindSubstringIgnoreCase+0x4c>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <FindSubstringIgnoreCase+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @FindSubstringIgnoreCase(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
%10 = icmp sge i64 %7, %9
br i1 %10, label %11, label %28
11: ; preds = %2
br label %12
12: ; preds = %24, %11
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i64 @StartsWithIgnoreCase(i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %4
store i8* %22, i8** %3
br label %29
23: ; preds = %16
br label %24
24: ; preds = %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
br label %12
27: ; preds = %12
br label %28
28: ; preds = %27, %2
store i8* null, i8** %3
br label %29
29: ; preds = %28, %21
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
define i8* @FindSubstringIgnoreCase(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp slt i64 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %13
%10 = phi i8* [ %14, %13 ], [ %0, %6 ]
%11 = tail call i64 @StartsWithIgnoreCase(i8* %10, i8* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %13, %6, %2
%18 = phi i8* [ null, %2 ], [ null, %6 ], [ %10, %9 ], [ null, %13 ]
ret i8* %18
}