#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 const *, char const *const);
int find_str_idx(const char *str, const char *const set[], size_t latest_el) {
  size_t i;
  for (i = 0;; ++i) {
    if (0 == strcmp(str, set[i])) {
      return i;
    } else if (i == latest_el) {
      return -1;
    }
  }
}


x86 assembly (clang, -O0):
<find_str_idx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    115b <find_str_idx+0x4b>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1190 <find_str_idx+0x80>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1175 <find_str_idx+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <find_str_idx+0x80>
jmp    117a <find_str_idx+0x6a>
jmp    117f <find_str_idx+0x6f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112c <find_str_idx+0x1c>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_str_idx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rsi),%rsi
call   1030 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1152 <find_str_idx+0x42>
cmp    %rbx,%r14
je     114d <find_str_idx+0x3d>
mov    0x8(%r15,%rbx,8),%rsi
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1130 <find_str_idx+0x20>
jmp    1152 <find_str_idx+0x42>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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