#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 */
size_t strlen(char const *);
scalar_t__ strncasecmp(char *, char const *, size_t const);
int argv_find(char **argv, const char *what) {
  const size_t len = strlen(what);
  for (size_t i = 0; argv[i]; i++)
    if (strncasecmp(argv[i], what, len) == 0)
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<argv_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     119d <argv_find+0x7d>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1187 <argv_find+0x67>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11a4 <argv_find+0x84>
jmp    118c <argv_find+0x6c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1145 <argv_find+0x25>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argv_find>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    (%r15),%rdi
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1173 <argv_find+0x53>
mov    %rax,%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     1170 <argv_find+0x50>
mov    0x8(%r15,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1150 <argv_find+0x30>
jmp    1173 <argv_find+0x53>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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