#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int getArgValue(int argc, char **argv, char *key, char **value) {
  int i = 0;
  while (i < argc) {
    if (strcmp(key, argv[i]) == 0) {
      i += 1;
      if (i >= argc) {
        fprintf(stderr, "ERROR: Command line argument \"%s\" had no value.\n",
                key);
        return -1;
      }
      (*value) = argv[i];
      return 0;
    }
    i += 1;
  }
  return -2;
}


x86 assembly (clang, -O0):
<getArgValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <getArgValue+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c2 <getArgValue+0xa2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11a3 <getArgValue+0x83>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <getArgValue+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d7 <getArgValue+0xb7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113e <getArgValue+0x1e>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getArgValue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xfffffffe,%r15d
test   %edi,%edi
jle    11aa <getArgValue+0x8a>
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rcx,(%rsp)
mov    %edi,%r14d
neg    %r14
mov    $0x1,%ebx
nopl   (%rax)
mov    -0x8(%rbp,%rbx,8),%rsi
mov    %r13,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1176 <getArgValue+0x56>
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1150 <getArgValue+0x30>
jmp    11aa <getArgValue+0x8a>
cmp    %r12d,%ebx
jge    118c <getArgValue+0x6c>
mov    0x0(%rbp,%rbx,8),%rax
mov    (%rsp),%rcx
mov    %rax,(%rcx)
xor    %r15d,%r15d
jmp    11aa <getArgValue+0x8a>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    %r13,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Command line argument \22%s\22 had no value.\0A\00"
define i32 @getArgValue(i32 %0, i8** %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
store i32 0, i32* %10
br label %11
11: ; preds = %41, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %44
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = load i8**, i8*** %7
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %16, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %15
%25 = load i32, i32* %10
%26 = add nsw i32 %25, 1
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %8
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 -1, i32* %5
br label %45
34: ; preds = %24
%35 = load i8**, i8*** %7
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %9
store i8* %39, i8** %40
store i32 0, i32* %5
br label %45
41: ; preds = %15
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %11
44: ; preds = %11
store i32 -2, i32* %5
br label %45
45: ; preds = %44, %34, %30
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Command line argument \22%s\22 had no value.\0A\00"
define i32 @getArgValue(i32 %0, i8** nocapture %1, i8* %2, i8** nocapture writeonly %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %28
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %25
%9 = phi i64 [ 0, %6 ], [ %26, %25 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %2, i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %8
%15 = trunc i64 %9 to i32
%16 = add nuw nsw i32 %15, 1
%17 = icmp slt i32 %16, %0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %28
21: ; preds = %14
%22 = zext i32 %16 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
store i8* %24, i8** %3
br label %28
25: ; preds = %8
%26 = add nuw nsw i64 %9, 1
%27 = icmp eq i64 %26, %7
br i1 %27, label %28, label %8
28: ; preds = %25, %4, %21, %18
%29 = phi i32 [ -1, %18 ], [ 0, %21 ], [ -2, %4 ], [ -2, %25 ]
ret i32 %29
}