#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 *);
char *strstr(char *, char *);
char tolower(char);
char *SearchKw(char *str, char *kw) {
  char *s1, *s2;
  char lc[10];
  strcpy(lc, kw);
  s1 = lc;
  while (*s1) {
    *s1 = tolower(*s1);
    s1++;
  }
  s1 = strstr(str, kw);
  s2 = strstr(str, lc);
  return (s2 != NULL && ((s1 == NULL) || (s2 < s1))) ? s2 : s1;
}


x86 assembly (clang, -O0):
<SearchKw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2a(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1187 <SearchKw+0x57>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <SearchKw+0x25>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11da <SearchKw+0xaa>
cmpq   $0x0,-0x18(%rbp)
je     11cd <SearchKw+0x9d>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11da <SearchKw+0xaa>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11e2 <SearchKw+0xb2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SearchKw>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x6(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x6(%rsp),%al
test   %al,%al
je     1176 <SearchKw+0x46>
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <SearchKw+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
lea    0x6(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11a0 <SearchKw+0x70>
test   %rbx,%rbx
je     11a3 <SearchKw+0x73>
cmp    %rbx,%rax
jb     11a3 <SearchKw+0x73>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @SearchKw(i8* %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %1)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %13, %8 ], [ %6, %2 ]
%10 = phi i8* [ %12, %8 ], [ %4, %2 ]
%11 = call signext i8 @tolower(i8 signext %9)
store i8 %11, i8* %10
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %2
%16 = call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%17 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = icmp eq i8* %16, null
%21 = icmp ult i8* %17, %16
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %24, label %23
23: ; preds = %19, %15
br label %24
24: ; preds = %19, %23
%25 = phi i8* [ %16, %23 ], [ %17, %19 ]
ret i8* %25
}