#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 snck_string {
  int dummy;
};
struct snck_ctxt {
  int dummy;
};

/* Variables and functions */
char *getenv(char *);
char snck_string_copy(struct snck_ctxt const *const, struct snck_string *const,
                      char *);
char *snck_string_get(struct snck_ctxt const *const,
                      struct snck_string const *const);
int /*<<< orphan*/ snck_string_put(struct snck_ctxt const *const, char *);
char snck_env_get(struct snck_ctxt const *const p_ctxt,
                  struct snck_string const *const p_name,
                  struct snck_string *const p_value) {
  char b_result;
  char *p_name0;
  p_name0 = snck_string_get(p_ctxt, p_name);
  if (p_name0) {
    char *p_value0;
    p_value0 = getenv(p_name0);
    if (p_value0) {
      b_result = snck_string_copy(p_ctxt, p_value, p_value0);
    } else {
      b_result = 0;
    }
    snck_string_put(p_ctxt, p_name0);
  } else {
    b_result = 0;
  }
  return b_result;
}


x86 assembly (clang, -O0):
<snck_env_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <snck_string_get@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b7 <snck_env_get+0x77>
mov    -0x28(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a1 <snck_env_get+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <snck_string_copy@plt>
mov    %al,-0x19(%rbp)
jmp    11a5 <snck_env_get+0x65>
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <snck_string_put@plt>
jmp    11bb <snck_env_get+0x7b>
movb   $0x0,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snck_env_get>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r14
call   1060 <snck_string_get@plt>
test   %rax,%rax
je     1179 <snck_env_get+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <snck_env_get+0x3d>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1050 <snck_string_copy@plt>
mov    %eax,%ebp
jmp    117f <snck_env_get+0x3f>
xor    %ebp,%ebp
jmp    118a <snck_env_get+0x4a>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <snck_string_put@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.snck_ctxt = type { i32 }
%struct.snck_string = type { i32 }
define signext i8 @snck_env_get(%struct.snck_ctxt* %0, %struct.snck_string* %1, %struct.snck_string* %2) {
%4 = alloca %struct.snck_ctxt*
%5 = alloca %struct.snck_string*
%6 = alloca %struct.snck_string*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
store %struct.snck_ctxt* %0, %struct.snck_ctxt** %4
store %struct.snck_string* %1, %struct.snck_string** %5
store %struct.snck_string* %2, %struct.snck_string** %6
%10 = load %struct.snck_ctxt*, %struct.snck_ctxt** %4
%11 = load %struct.snck_string*, %struct.snck_string** %5
%12 = call i8* @snck_string_get(%struct.snck_ctxt* %10, %struct.snck_string* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %30
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = call i8* @getenv(i8* %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load %struct.snck_ctxt*, %struct.snck_ctxt** %4
%22 = load %struct.snck_string*, %struct.snck_string** %6
%23 = load i8*, i8** %9
%24 = call signext i8 @snck_string_copy(%struct.snck_ctxt* %21, %struct.snck_string* %22, i8* %23)
store i8 %24, i8* %7
br label %26
25: ; preds = %15
store i8 0, i8* %7
br label %26
26: ; preds = %25, %20
%27 = load %struct.snck_ctxt*, %struct.snck_ctxt** %4
%28 = load i8*, i8** %8
%29 = call i32 @snck_string_put(%struct.snck_ctxt* %27, i8* %28)
br label %31
30: ; preds = %3
store i8 0, i8* %7
br label %31
31: ; preds = %30, %26
%32 = load i8, i8* %7
ret i8 %32
}

LLVM IR (-O2):
%struct.snck_ctxt = type { i32 }
%struct.snck_string = type { i32 }
define signext i8 @snck_env_get(%struct.snck_ctxt* %0, %struct.snck_string* %1, %struct.snck_string* %2) {
%4 = tail call i8* @snck_string_get(%struct.snck_ctxt* %0, %struct.snck_string* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i8* @getenv(i8* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call signext i8 @snck_string_copy(%struct.snck_ctxt* %0, %struct.snck_string* %2, i8* %7)
br label %11
11: ; preds = %6, %9
%12 = phi i8 [ %10, %9 ], [ 0, %6 ]
%13 = tail call i32 @snck_string_put(%struct.snck_ctxt* %0, i8* %4)
br label %14
14: ; preds = %3, %11
%15 = phi i8 [ %12, %11 ], [ 0, %3 ]
ret i8 %15
}