#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 */
int argv_count(char **);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int strlen(char const *);
scalar_t__ strncasecmp(char *, char const *, int);
int argv_find(char **argv, const char *what) {
  int cnt = argv_count(argv), len, i;
  assert(what != NULL);
  for (i = 0, len = strlen(what); i < cnt; 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    -0x10(%rbp),%rdi
call   1060 <argv_count@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cd <argv_find+0x8d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11ba <argv_find+0x7a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <argv_find+0x94>
jmp    11bf <argv_find+0x7f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <argv_find+0x41>
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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
call   1060 <argv_count@plt>
mov    %eax,%r12d
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1040 <assert@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    $0xffffffff,%eax
test   %r12d,%r12d
jle    11b6 <argv_find+0x76>
mov    %r12d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     11b4 <argv_find+0x74>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <argv_find+0x50>
mov    $0xffffffff,%eax
jmp    11b6 <argv_find+0x76>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8**, i8*** %4
%10 = call i32 @argv_count(i8** %9)
store i32 %10, i32* %6
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* %8
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %34, %2
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i8**, i8*** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = call i64 @strncasecmp(i8* %26, i8* %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = load i32, i32* %8
store i32 %32, i32* %3
br label %38
33: ; preds = %21
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %17
37: ; preds = %17
store i32 -1, i32* %3
br label %38
38: ; preds = %37, %31
%39 = load i32, i32* %3
ret i32 %39
}

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