#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 *const, char const *, size_t);
char *find_env_by_key(const char *key, char *const *arge) {
  size_t keylen;
  keylen = strlen(key);
  for (; *arge != NULL; ++arge) {
    if (strncmp(*arge, key, keylen) != 0) {
      continue;
    }
    return *arge + keylen;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_env_by_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1193 <find_env_by_key+0x73>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     116e <find_env_by_key+0x4e>
jmp    1182 <find_env_by_key+0x62>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <find_env_by_key+0x7b>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <find_env_by_key+0x1d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_env_by_key>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     115c <find_env_by_key+0x3c>
mov    %rax,%r14
add    $0x8,%rbx
nop
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1161 <find_env_by_key+0x41>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1140 <find_env_by_key+0x20>
xor    %r14d,%r14d
jmp    1165 <find_env_by_key+0x45>
add    -0x8(%rbx),%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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