#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 env__find(char **, char *);
char *malloc(unsigned int);
unsigned int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
char *env_get(char **env, char *name) {
  int index;
  char *pair;
  char *result;
  unsigned int name_length, value_length;
  name_length = strlen(name);
  if ((index = env__find(env, name)) == -1)
    return NULL;
  pair = env[index];
  value_length = strlen(pair) - name_length;
  result = malloc(value_length);
  strncpy(result, pair + name_length + 1, value_length);
  return result;
}


x86 assembly (clang, -O0):
<env_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <env__find@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1182 <env_get+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11cf <env_get+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
sub    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x38(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_get>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <env__find@plt>
cmp    $0xffffffff,%eax
je     119c <env_get+0x5c>
cltq
mov    (%rbx,%rax,8),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
sub    %r14d,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%eax
lea    (%r15,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    119e <env_get+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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