#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 *, int);
char *get_argval(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;
    if (strncmp(token, "=", 1) != 0)
      continue;
    token += 1;
    val = token;
  }
  return val;
}


x86 assembly (clang, -O0):
<get_argval>:
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    120f <get_argval+0xef>
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_argval+0x6f>
jmp    1201 <get_argval+0xe1>
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bd <get_argval+0x9d>
jmp    1201 <get_argval+0xe1>
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11ed <get_argval+0xcd>
jmp    1201 <get_argval+0xe1>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114f <get_argval+0x2f>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_argval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,0x10(%rsp)
mov    %rdx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%ebp
jl     11d8 <get_argval+0xb8>
mov    %rax,%r15
mov    %ebp,%r12d
mov    $0x1,%r14d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xe9d(%rip),%r13
jmp    1179 <get_argval+0x59>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
cmp    %r14,%r12
je     11df <get_argval+0xbf>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <get_argval+0x50>
add    $0x2,%rbp
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <get_argval+0x50>
lea    (%r15,%rbp,1),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0x1(%rbp,%r15,1),%rax
mov    0x8(%rsp),%rcx
cmove  %rax,%rcx
mov    %rcx,0x8(%rsp)
jmp    1170 <get_argval+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"
@.str.1 = [2 x i8] c"=\00"
define i8* @get_argval(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 = %49, %3
%14 = load i32, i32* %9
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %52
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), i32 2)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %17
br label %49
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 = trunc i64 %32 to i32
%34 = call i64 @strncmp(i8* %30, i8* %31, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %27
br label %49
37: ; preds = %27
%38 = load i64, i64* %8
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 %38
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
br label %49
45: ; preds = %37
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %10
%48 = load i8*, i8** %10
store i8* %48, i8** %7
br label %49
49: ; preds = %45, %44, %36, %26
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %13
52: ; preds = %13
%53 = load i8*, i8** %7
ret i8* %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"--\00"
@.str.1 = [2 x i8] c"=\00"
define i8* @get_argval(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 %9
6: ; preds = %3
%7 = trunc i64 %4 to i32
%8 = zext i32 %0 to i64
br label %11
9: ; preds = %28, %3
%10 = phi i8* [ null, %3 ], [ %29, %28 ]
ret i8* %10
11: ; preds = %6, %28
%12 = phi i64 [ 1, %6 ], [ %30, %28 ]
%13 = phi i8* [ null, %6 ], [ %29, %28 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %12
%15 = load i8*, i8** %14
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %15, i64 2
%20 = tail call i64 @strncmp(i8* %19, i8* %2, i32 %7)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %19, i64 %4
%24 = tail call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%25 = icmp eq i64 %24, 0
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = select i1 %25, i8* %26, i8* %13
br label %28
28: ; preds = %22, %18, %11
%29 = phi i8* [ %13, %11 ], [ %13, %18 ], [ %27, %22 ]
%30 = add nuw nsw i64 %12, 1
%31 = icmp eq i64 %30, %8
br i1 %31, label %9, label %11
}