#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 */
unsigned int strlen(char *);
scalar_t__ strncmp(char *, char *, unsigned int);
int env__find(char **env, char *name) {
  int i = 0;
  char *pair;
  unsigned int name_length = strlen(name);
  while ((pair = env[i++]) != NULL) {
    if (strncmp(name, pair, name_length) == 0) {
      return i - 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<env__find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1194 <env__find+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118f <env__find+0x6f>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    119b <env__find+0x7b>
jmp    1143 <env__find+0x23>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env__find>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    $0xffffffff,%ebp
nopl   (%rax)
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1161 <env__find+0x41>
mov    %r14,%rdi
mov    %r15d,%edx
call   1030 <strncmp@plt>
add    $0x1,%ebp
add    $0x8,%rbx
test   %rax,%rax
jne    1140 <env__find+0x20>
jmp    1166 <env__find+0x46>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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