#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 /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
char *eval_arg(int argc, char *argv[], const char *arg, char *def) {
  int index = -1;
  for (int i = 1; i < argc; i++) {
    if (strncmp(argv[i], arg, strlen(arg)) == 0) {
      index = i;
      break;
    }
  }
  if (index != -1 && index + 1 < argc)
    return argv[index + 1];
  return def;
}


x86 assembly (clang, -O0):
<eval_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <eval_arg+0x89>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1196 <eval_arg+0x76>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11a9 <eval_arg+0x89>
jmp    119b <eval_arg+0x7b>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1145 <eval_arg+0x25>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11dc <eval_arg+0xbc>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    11dc <eval_arg+0xbc>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <eval_arg+0xc4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_arg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rax
cmp    $0x2,%edi
jl     1194 <eval_arg+0x74>
mov    %rdx,%r13
mov    %rsi,%r12
mov    %edi,%r15d
mov    %rax,(%rsp)
mov    %edi,%eax
mov    $0x1,%r14d
sub    %rax,%r14
mov    $0x2,%ebp
mov    -0x8(%r12,%rbp,8),%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1187 <eval_arg+0x67>
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x2,%rax
jne    1150 <eval_arg+0x30>
mov    (%rsp),%rax
jmp    1194 <eval_arg+0x74>
cmp    %r15d,%ebp
mov    (%rsp),%rax
jge    1194 <eval_arg+0x74>
mov    (%r12,%rbp,8),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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