#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__ strcasestr(char const *, char const *);
int find_in_array(const char *needle, int i, const char **ary, int sz) {
  for (; i < sz; i++)
    if (strcasestr(ary[i], needle))
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<find_in_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    116f <find_in_array+0x5f>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcasestr@plt>
cmp    $0x0,%rax
je     115c <find_in_array+0x4c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <find_in_array+0x66>
jmp    1161 <find_in_array+0x51>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <find_in_array+0x16>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_in_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    %ecx,%esi
jge    1163 <find_in_array+0x53>
mov    %esi,%r15d
mov    %rdi,%r12
movslq %esi,%rax
movslq %ecx,%rbp
lea    (%rdx,%rax,8),%r13
sub    %rax,%rbp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcasestr@plt>
test   %rax,%rax
jne    115d <find_in_array+0x4d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <find_in_array+0x30>
jmp    1163 <find_in_array+0x53>
add    %ebx,%r15d
mov    %r15d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @find_in_array(i8* %0, i32 %1, i8** nocapture %2, i32 %3) {
%5 = icmp slt i32 %1, %3
br i1 %5, label %6, label %20
6: ; preds = %4
%7 = sext i32 %1 to i64
%8 = sext i32 %3 to i64
br label %9
9: ; preds = %6, %15
%10 = phi i64 [ %7, %6 ], [ %16, %15 ]
%11 = getelementptr inbounds i8*, i8** %2, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i64 @strcasestr(i8* %12, i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = add nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %20, label %9
18: ; preds = %9
%19 = trunc i64 %10 to i32
br label %20
20: ; preds = %15, %18, %4
%21 = phi i32 [ -1, %4 ], [ %19, %18 ], [ -1, %15 ]
ret i32 %21
}