#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__ strcmp(char *, char *);
int findStringIndex(char *string, char **collection, int size) {
  int r = -1;
  for (int i = 0; (i < size) && (r == -1); i++) {
    if (strcmp(string, collection[i]) == 0)
      r = i;
  }
  return r;
}


x86 assembly (clang, -O0):
<findStringIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    114c <findStringIndex+0x3c>
cmpl   $0xffffffff,-0x18(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115c <findStringIndex+0x4c>
jmp    1194 <findStringIndex+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1181 <findStringIndex+0x71>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1186 <findStringIndex+0x76>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <findStringIndex+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findStringIndex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1153 <findStringIndex+0x43>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rsi
mov    %r15,%rdi
call   1030 <strcmp@plt>
neg    %rax
sbb    %eax,%eax
or     %ebx,%eax
add    $0x1,%rbx
cmp    %r12,%rbx
jae    1158 <findStringIndex+0x48>
cmp    $0xffffffff,%eax
je     1130 <findStringIndex+0x20>
jmp    1158 <findStringIndex+0x48>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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