#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[], int latest_el) {
  int 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    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1158 <find_str_idx+0x48>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <find_str_idx+0x78>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1170 <find_str_idx+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <find_str_idx+0x78>
jmp    1175 <find_str_idx+0x65>
jmp    117a <find_str_idx+0x6a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <find_str_idx+0x1a>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_str_idx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     115d <find_str_idx+0x4d>
mov    %ebx,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rbx,%r12
je     1161 <find_str_idx+0x51>
mov    0x8(%r14,%rbx,8),%rsi
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1140 <find_str_idx+0x30>
jmp    1166 <find_str_idx+0x56>
xor    %ebx,%ebx
jmp    1166 <find_str_idx+0x56>
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, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %27, %3
%10 = load i8*, i8** %5
%11 = load i8**, i8*** %6
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %10, i8* %15)
%17 = icmp eq i64 0, %16
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = load i32, i32* %8
store i32 %19, i32* %4
br label %30
20: ; preds = %9
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = icmp eq i32 %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 i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %9
30: ; preds = %24, %18
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @find_str_idx(i8* %0, i8** nocapture %1, i32 %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 %20, label %7
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %12
%10 = phi i64 [ 0, %7 ], [ %13, %12 ]
%11 = icmp eq i64 %10, %8
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = add nuw nsw 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 %18, label %9
18: ; preds = %12
%19 = trunc i64 %13 to i32
br label %20
20: ; preds = %9, %18, %3
%21 = phi i32 [ 0, %3 ], [ %19, %18 ], [ -1, %9 ]
ret i32 %21
}