#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 */
struct env {
  int dummy;
};

/* Variables and functions */
scalar_t__ env_find(struct env *, char const *, unsigned int *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ env_load(struct env *, unsigned int, int /*<<< orphan*/ *,
                            int /*<<< orphan*/ *, char **, int /*<<< orphan*/ *,
                            int /*<<< orphan*/ *);
const char *env_get(struct env *env, const char *name) {
  unsigned ofs;
  char *val;
  if (env_find(env, name, &ofs, NULL)) {
    if (!env_load(env, ofs, NULL, NULL, &val, NULL, NULL))
      return val;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<env_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <env_find@plt>
cmp    $0x0,%rax
je     118d <env_get+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x28(%rbp),%r8
mov    %r9,%rdx
mov    %r9,%rcx
movq   $0x0,(%rsp)
call   1030 <env_load@plt>
cmp    $0x0,%eax
jne    1188 <env_get+0x68>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <env_get+0x75>
jmp    118d <env_get+0x6d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_get>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0xc(%rsp),%rdx
xor    %ecx,%ecx
call   1040 <env_find@plt>
test   %rax,%rax
je     116a <env_get+0x4a>
mov    0xc(%rsp),%esi
movq   $0x0,(%rsp)
xor    %r14d,%r14d
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1030 <env_load@plt>
test   %eax,%eax
jne    116a <env_get+0x4a>
mov    0x10(%rsp),%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.env = type { i32 }
define i8* @env_get(%struct.env* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.env*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store %struct.env* %0, %struct.env** %4
store i8* %1, i8** %5
%8 = load %struct.env*, %struct.env** %4
%9 = load i8*, i8** %5
%10 = call i64 @env_find(%struct.env* %8, i8* %9, i32* %6, i32* null)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load %struct.env*, %struct.env** %4
%14 = load i32, i32* %6
%15 = call i32 @env_load(%struct.env* %13, i32 %14, i32* null, i32* null, i8** %7, i32* null, i32* null)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = load i8*, i8** %7
store i8* %18, i8** %3
br label %21
19: ; preds = %12
br label %20
20: ; preds = %19, %2
store i8* null, i8** %3
br label %21
21: ; preds = %20, %17
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
%struct.env = type { i32 }
define i8* @env_get(%struct.env* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = call i64 @env_find(%struct.env* %0, i8* %1, i32* %3, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @env_load(%struct.env* %0, i32 %10, i32* null, i32* null, i8** %4, i32* null, i32* null)
%12 = icmp eq i32 %11, 0
%13 = load i8*, i8** %4
%14 = select i1 %12, i8* %13, i8* null
br label %15
15: ; preds = %9, %2
%16 = phi i8* [ null, %2 ], [ %14, %9 ]
ret i8* %16
}