#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*/ len(char const *);
scalar_t__ strn_cmp(char *, char const *, int /*<<< orphan*/);
int find_inenv(char **env, const char *str) {
  int i;
  i = 0;
  while (env[i]) {
    if ((strn_cmp(env[i], str, len(str))))
      return (i);
    i++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<find_inenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     119d <find_inenv+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <len@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strn_cmp@plt>
cmp    $0x0,%rax
je     118f <find_inenv+0x6f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <find_inenv+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <find_inenv+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_inenv>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%r12
test   %r12,%r12
je     1168 <find_inenv+0x48>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <len@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strn_cmp@plt>
test   %rax,%rax
jne    116a <find_inenv+0x4a>
mov    0x8(%r15,%rbx,8),%r12
add    $0x1,%rbx
test   %r12,%r12
jne    1140 <find_inenv+0x20>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @find_inenv(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %27, %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 %30
14: ; preds = %7
%15 = load i8**, i8*** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @len(i8* %21)
%23 = call i64 @strn_cmp(i8* %19, i8* %20, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %31
27: ; preds = %14
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %7
30: ; preds = %7
store i32 0, i32* %3
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* %3
ret i32 %32
}

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