#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char *, char const *, size_t);
char *get_arg(int argc, char **argv, const char *key) {
  char *val = NULL;
  size_t keylen = strlen(key);
  for (int i = 1; i < argc; i++) {
    char *token = argv[i];
    if (strncmp(token, "--", 2) != 0)
      continue;
    token += 2;
    if (strncmp(token, key, keylen) != 0)
      continue;
    token += keylen;
    val = argv[i];
  }
  return val;
}


x86 assembly (clang, -O0):
<get_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e5 <get_arg+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     118f <get_arg+0x6f>
jmp    11d7 <get_arg+0xb7>
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bb <get_arg+0x9b>
jmp    11d7 <get_arg+0xb7>
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <get_arg+0x2f>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %rax,0x10(%rsp)
cmp    $0x2,%ebp
jl     11b6 <get_arg+0x96>
mov    %ebp,%r12d
mov    $0x1,%r15d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xea1(%rip),%r13
jmp    1179 <get_arg+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%r12
je     11bd <get_arg+0x9d>
mov    (%rbx,%r15,8),%rbp
mov    $0x2,%edx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <get_arg+0x50>
add    $0x2,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    0x10(%rsp),%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <get_arg+0x50>
mov    (%rbx,%r15,8),%rax
mov    %rax,0x8(%rsp)
jmp    1170 <get_arg+0x50>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"--\00"
define i8* @get_arg(i32 %0, i8** nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = zext i32 %0 to i64
br label %10
8: ; preds = %23, %3
%9 = phi i8* [ null, %3 ], [ %24, %23 ]
ret i8* %9
10: ; preds = %6, %23
%11 = phi i64 [ 1, %6 ], [ %25, %23 ]
%12 = phi i8* [ null, %6 ], [ %24, %23 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %11
%14 = load i8*, i8** %13
%15 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %14, i64 2
%19 = tail call i64 @strncmp(i8* %18, i8* %2, i64 %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i8*, i8** %13
br label %23
23: ; preds = %17, %10, %21
%24 = phi i8* [ %22, %21 ], [ %12, %10 ], [ %12, %17 ]
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %7
br i1 %26, label %8, label %10
}