#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__ malloc(int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *read_optional_parameter(int argc, char *argv[], char *parameter) {
  char *value = NULL;
  int i;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], parameter) && argc > i + 1 &&
        strncmp(argv[i + 1], "-", 1)) {
      int len = strlen(argv[i + 1]);
      value = (char *)malloc(len + 1);
      value[len] = '\0';
      strcpy(value, argv[i + 1]);
      break;
    }
  }
  return value;
}


x86 assembly (clang, -O0):
<read_optional_parameter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123f <read_optional_parameter+0xef>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    122c <read_optional_parameter+0xdc>
mov    -0x4(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    122c <read_optional_parameter+0xdc>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     122c <read_optional_parameter+0xdc>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
jmp    123f <read_optional_parameter+0xef>
jmp    1231 <read_optional_parameter+0xe1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1172 <read_optional_parameter+0x22>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_optional_parameter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11ff <read_optional_parameter+0xaf>
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%ebp
mov    $0x1,%r14d
sub    %rbp,%r14
mov    $0x2,%ebx
lea    0xe7f(%rip),%r12
jmp    11a2 <read_optional_parameter+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
je     11ff <read_optional_parameter+0xaf>
mov    -0x8(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1190 <read_optional_parameter+0x40>
cmp    %rbp,%rbx
jae    1190 <read_optional_parameter+0x40>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1190 <read_optional_parameter+0x40>
mov    0x0(%r13,%rbx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
movslq %r15d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    0x0(%r13,%rbx,8),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
jmp    1201 <read_optional_parameter+0xb1>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define i8* @read_optional_parameter(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i8* null, i8** %7
store i32 1, i32* %8
br label %10
10: ; preds = %62, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %65
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = load i8*, i8** %6
%21 = call i32 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %61, label %23
23: ; preds = %14
%24 = load i32, i32* %4
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
%27 = icmp sgt i32 %24, %26
br i1 %27, label %28, label %61
28: ; preds = %23
%29 = load i8**, i8*** %5
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %61
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %38, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %7
%54 = load i8**, i8*** %5
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %53, i8* %59)
br label %65
61: ; preds = %28, %23, %14
br label %62
62: ; preds = %61
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %10
65: ; preds = %37, %10
%66 = load i8*, i8** %7
ret i8* %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define i8* @read_optional_parameter(i32 %0, i8** nocapture %1, i8* nocapture %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %36
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %34
%9 = phi i64 [ 1, %5 ], [ %14, %34 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(1) %2)
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i64 %9, 1
%15 = icmp ult i64 %14, %6
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %34
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 %14
%19 = load i8*, i8** %18
%20 = tail call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %34, label %22
22: ; preds = %17
%23 = and i64 %14, 4294967295
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = tail call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = sext i32 %26 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %24
%33 = tail call i32 @strcpy(i8* %29, i8* %32)
br label %36
34: ; preds = %8, %17
%35 = icmp eq i64 %14, %7
br i1 %35, label %36, label %8
36: ; preds = %34, %3, %22
%37 = phi i8* [ %29, %22 ], [ null, %3 ], [ null, %34 ]
ret i8* %37
}