#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 /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ string_toupper(char *);
char *strstr(char *, char *);
char *mystrcasestr(char *str1, const char *str2) {
  char s1[500], s2[500];
  char *c;
  strcpy(s1, str1);
  strcpy(s2, str2);
  string_toupper(s1);
  string_toupper(s2);
  c = strstr(s1, s2);
  if (c == NULL) {
    return NULL;
  } else {
    return &str1[c - s1];
  }
}


x86 assembly (clang, -O0):
<mystrcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
call   1040 <string_toupper@plt>
lea    -0x410(%rbp),%rdi
call   1040 <string_toupper@plt>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11b0 <mystrcasestr+0x80>
movq   $0x0,-0x8(%rbp)
jmp    11cc <mystrcasestr+0x9c>
mov    -0x10(%rbp),%rax
mov    -0x418(%rbp),%rcx
lea    -0x210(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mystrcasestr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x200(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <string_toupper@plt>
mov    %r12,%rdi
call   1040 <string_toupper@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
sub    %r15,%rcx
add    %r14,%rcx
test   %rax,%rax
cmovne %rcx,%rax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mystrcasestr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [500 x i8]
%7 = alloca [500 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%16 = call i32 @string_toupper(i8* %15)
%17 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%18 = call i32 @string_toupper(i8* %17)
%19 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %2
store i8* null, i8** %3
br label %33
25: ; preds = %2
%26 = load i8*, i8** %4
%27 = load i8*, i8** %8
%28 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = getelementptr inbounds i8, i8* %26, i64 %31
store i8* %32, i8** %3
br label %33
33: ; preds = %25, %24
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
define i8* @mystrcasestr(i8* %0, i8* %1) {
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = call i32 @strcpy(i8* %6, i8* %1)
%9 = call i32 @string_toupper(i8* %5)
%10 = call i32 @string_toupper(i8* %6)
%11 = call i8* @strstr(i8* %5, i8* %6)
%12 = icmp eq i8* %11, null
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint [500 x i8]* %3 to i64
%15 = sub i64 %13, %14
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = select i1 %12, i8* null, i8* %16
ret i8* %17
}