#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 basic_index_of_arg(char const *, int, char **);
char *basic_string_from_args(const char *key, int argc, char *argv[],
                             char *default_value) {
  int idx = basic_index_of_arg(key, argc, argv);
  char *result;
  if (idx >= 0 && idx < argc - 1)
    result = argv[idx + 1];
  else
    result = default_value;
  return (result);
}


x86 assembly (clang, -O0):
<basic_string_from_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <basic_index_of_arg@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     116f <basic_string_from_args+0x5f>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    116f <basic_string_from_args+0x5f>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    1177 <basic_string_from_args+0x67>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_string_from_args>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
call   1030 <basic_index_of_arg@plt>
test   %eax,%eax
js     1133 <basic_string_from_args+0x23>
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jge    1133 <basic_string_from_args+0x23>
mov    %eax,%eax
mov    0x8(%rbx,%rax,8),%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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