#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__ strcasecmp(char *, char *);
int find_arg(int argc, char *argv[], char *key) {
  int i;
  for (i = 0; i < argc && strcasecmp(argv[i], key); i++)
    ;
  return i < argc ? i : -1;
}


x86 assembly (clang, -O0):
<find_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    115a <find_arg+0x4a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    116a <find_arg+0x5a>
jmp    117d <find_arg+0x6d>
jmp    116f <find_arg+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <find_arg+0x1a>
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1194 <find_arg+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <find_arg+0x91>
mov    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <find_arg+0x91>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %edi,%edi
jle    114f <find_arg+0x3f>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     114c <find_arg+0x3c>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1130 <find_arg+0x20>
jmp    114f <find_arg+0x3f>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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