#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__ astrcmpi_n(char const *, char const *, size_t);
size_t strlen(char const *);
char *astrstri(const char *str, const char *find) {
  size_t len;
  if (!str || !find)
    return NULL;
  len = strlen(find);
  do {
    if (astrcmpi_n(str, find, len) == 0)
      return (char *)str;
  } while (*str++);
  return NULL;
}


x86 assembly (clang, -O0):
<astrstri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <astrstri+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1153 <astrstri+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11ad <astrstri+0x8d>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <astrcmpi_n@plt>
cmp    $0x0,%rax
jne    1188 <astrstri+0x68>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <astrstri+0x8d>
jmp    118d <astrstri+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
jne    1160 <astrstri+0x40>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrstri>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     1171 <astrstri+0x51>
mov    %rsi,%r15
test   %rsi,%rsi
je     1171 <astrstri+0x51>
mov    %rdi,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <astrcmpi_n@plt>
test   %rax,%rax
je     116e <astrstri+0x4e>
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <astrstri+0x30>
jmp    1171 <astrstri+0x51>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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