#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 *);
scalar_t__ strncasecmp(char *, char *, int);
scalar_t__ toupper(char const);
char *Strcasestr(const char *s1, const char *s2) {
  const char *p1;
  int len;
  if (*s2 == 0)
    return (char *)s1;
  len = strlen((char *)s2);
  for (p1 = s1; *p1; p1++)
    if (toupper(*p1) == toupper(*s2))
      if (strncasecmp((char *)p1, (char *)s2, len) == 0)
        return (char *)p1;
  return 0;
}


x86 assembly (clang, -O0):
<Strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115d <Strcasestr+0x2d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <Strcasestr+0xc4>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ec <Strcasestr+0xbc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    11d6 <Strcasestr+0xa6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11d1 <Strcasestr+0xa1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <Strcasestr+0xc4>
jmp    11d6 <Strcasestr+0xa6>
jmp    11db <Strcasestr+0xab>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1171 <Strcasestr+0x41>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rsi)
je     119c <Strcasestr+0x6c>
mov    %rsi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    (%rbx),%al
jmp    1168 <Strcasestr+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     119a <Strcasestr+0x6a>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %rax,%rbp
movsbl (%r14),%edi
call   1030 <toupper@plt>
cmp    %rax,%rbp
jne    1160 <Strcasestr+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    1160 <Strcasestr+0x30>
jmp    119c <Strcasestr+0x6c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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