#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__ str_comparison_i(char const *, char *, size_t);
size_t strlen(char const *);
int find_in_array(const char **array, int length, char *str) {
  int i;
  int found_index = -1;
  size_t found_index_length = 0;
  size_t string_length;
  for (i = 0; i < length; ++i) {
    string_length = strlen(array[i]);
    if ((str_comparison_i(array[i], str, string_length) == 0) &&
        (string_length > found_index_length)) {
      found_index_length = string_length;
      found_index = i;
    }
  }
  return found_index;
}


x86 assembly (clang, -O0):
<find_in_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bc <find_in_array+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <str_comparison_i@plt>
cmp    $0x0,%rax
jne    11a9 <find_in_array+0x89>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11a9 <find_in_array+0x89>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11ae <find_in_array+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <find_in_array+0x29>
mov    -0x20(%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
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    119d <find_in_array+0x7d>
mov    %esi,%r13d
mov    $0xffffffff,%r14d
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    115f <find_in_array+0x3f>
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %r12,%r15
mov    %eax,%r14d
cmp    %rbp,%r13
je     11a2 <find_in_array+0x82>
mov    0x8(%rsp),%rax
mov    (%rax,%rbp,8),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1040 <str_comparison_i@plt>
test   %rax,%rax
sete   %cl
cmp    %r15,%r12
seta   %dl
mov    %ebp,%eax
test   %dl,%cl
jne    1150 <find_in_array+0x30>
mov    %r14d,%eax
mov    %r15,%r12
jmp    1150 <find_in_array+0x30>
mov    $0xffffffff,%eax
add    $0x18,%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) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 -1, i32* %8
store i64 0, i64* %9
store i32 0, i32* %7
br label %11
11: ; preds = %39, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %42
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %10
%22 = load i8**, i8*** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i8*, i8** %6
%28 = load i64, i64* %10
%29 = call i64 @str_comparison_i(i8* %26, i8* %27, i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %15
%32 = load i64, i64* %10
%33 = load i64, i64* %9
%34 = icmp ugt i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i64, i64* %10
store i64 %36, i64* %9
%37 = load i32, i32* %7
store i32 %37, i32* %8
br label %38
38: ; preds = %35, %31, %15
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %11
42: ; preds = %11
%43 = load i32, i32* %8
ret i32 %43
}

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