#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *findarg(char *option, char **argv, int *index) {
  if (option) {
    return option;
  }
  if (argv[*index + 1]) {
    (*index)++;
    return argv[*index];
  }
  fprintf(stderr, "%s ERROR: \"%s\" needs a parameter\n", argv[0],
          argv[*index]);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<findarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114c <findarg+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c3 <findarg+0xa3>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     118a <findarg+0x6a>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11c3 <findarg+0xa3>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe50(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findarg>:
push   %rax
test   %rdi,%rdi
jne    1139 <findarg+0x19>
movslq (%rdx),%rax
mov    0x8(%rsi,%rax,8),%rdi
test   %rdi,%rdi
je     113e <findarg+0x1e>
add    $0x1,%rax
mov    %eax,(%rdx)
mov    %rdi,%rax
pop    %rcx
ret
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%edi
mov    (%rsi),%rdx
mov    (%rsi,%rax,8),%rcx
lea    0xeab(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"%s ERROR: \22%s\22 needs a parameter\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @findarg(i8* readnone %0, i8** nocapture %1, i32* nocapture %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %5
store i32 %7, i32* %2
br label %22
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = sext i32 %6 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %3, %12
%23 = phi i8* [ %10, %12 ], [ %0, %3 ]
ret i8* %23
}