#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*/ strcmp(char const *, char *const);
char *const *find_arg(char *const *argv, const char *arg) {
  int i = 0;
  for (i = 0; argv[i]; i++) {
    if (!strcmp(arg, argv[i]))
      return &argv[i];
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     118a <find_arg+0x7a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1177 <find_arg+0x67>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1192 <find_arg+0x82>
jmp    117c <find_arg+0x6c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <find_arg+0x1e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_arg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    (%rdi),%rsi
test   %rsi,%rsi
je     114c <find_arg+0x3c>
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1151 <find_arg+0x41>
mov    0x8(%r12,%rbx,8),%rsi
add    $0x1,%rbx
test   %rsi,%rsi
jne    1130 <find_arg+0x20>
jmp    1157 <find_arg+0x47>
xor    %r14d,%r14d
jmp    1157 <find_arg+0x47>
mov    %ebx,%eax
lea    (%r12,%rax,8),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @find_arg(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %6
br label %7
7: ; preds = %29, %2
%8 = load i8**, i8*** %4
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %32
14: ; preds = %7
%15 = load i8*, i8** %5
%16 = load i8**, i8*** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %15, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %14
%24 = load i8**, i8*** %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
store i8** %27, i8*** %3
br label %33
28: ; preds = %14
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %7
32: ; preds = %7
store i8** null, i8*** %3
br label %33
33: ; preds = %32, %23
%34 = load i8**, i8*** %3
ret i8** %34
}

LLVM IR (-O2):
define i8** @find_arg(i8** %0, i8* nocapture %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2, %10
%6 = phi i64 [ %11, %10 ], [ 0, %2 ]
%7 = phi i8* [ %13, %10 ], [ %3, %2 ]
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = add nuw i64 %6, 1
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %5
15: ; preds = %5
%16 = and i64 %6, 4294967295
%17 = getelementptr inbounds i8*, i8** %0, i64 %16
br label %18
18: ; preds = %10, %2, %15
%19 = phi i8** [ %17, %15 ], [ null, %2 ], [ null, %10 ]
ret i8** %19
}