#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 find_option(int, char **, char const *);
char *read_string(int argc, char **argv, const char *option,
                  char *default_value) {
  int iplace = find_option(argc, argv, option);
  if (iplace >= 0 && iplace < argc - 1)
    return argv[iplace + 1];
  return default_value;
}


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

x86 assembly (clang, -O2):
<read_string>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <find_option@plt>
test   %eax,%eax
js     1133 <read_string+0x23>
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jge    1133 <read_string+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* @read_string(i32 %0, i8** %1, i8* %2, i8* %3) {
%5 = alloca i8*
%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
%11 = load i32, i32* %6
%12 = load i8**, i8*** %7
%13 = load i8*, i8** %8
%14 = call i32 @find_option(i32 %11, i8** %12, i8* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %4
%18 = load i32, i32* %10
%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* %10
%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** %5
br label %31
29: ; preds = %17, %4
%30 = load i8*, i8** %9
store i8* %30, i8** %5
br label %31
31: ; preds = %29, %22
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @read_string(i32 %0, i8** %1, i8* %2, i8* readnone %3) {
%5 = tail call i32 @find_option(i32 %0, i8** %1, i8* %2)
%6 = icmp sgt i32 %5, -1
%7 = add nsw i32 %0, -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** %1, i64 %12
%14 = load i8*, i8** %13
br label %15
15: ; preds = %4, %10
%16 = phi i8* [ %14, %10 ], [ %3, %4 ]
ret i8* %16
}