#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 *, char *);
char *find_key(char **argv, int argc, char *key) {
  for (; (argc > 0) && *argv; argc -= 2, argv += 2) {
    if (strcmp(key, argv[0]) == 0)
      return argv[1];
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jle    1140 <find_key+0x30>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1150 <find_key+0x40>
jmp    119a <find_key+0x8a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    117b <find_key+0x6b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <find_key+0x92>
jmp    1180 <find_key+0x70>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <find_key+0x13>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_key>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1154 <find_key+0x44>
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x2,%ebp
add    $0x8,%rbx
xor    %r14d,%r14d
nopl   (%rax)
mov    -0x8(%rbx),%rsi
test   %rsi,%rsi
je     115c <find_key+0x4c>
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1159 <find_key+0x49>
add    $0xfffffffe,%ebp
add    $0x10,%rbx
cmp    $0x2,%ebp
jg     1130 <find_key+0x20>
jmp    115c <find_key+0x4c>
xor    %r14d,%r14d
jmp    115c <find_key+0x4c>
mov    (%rbx),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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