#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 /*<<< orphan*/ __softboundmpx_store_null_return_metadata();
int /*<<< orphan*/ __softboundmpx_store_return_metadata(char *, char *);
char *getenv(char const *);
int strlen(char *);
__attribute__((__weak__, __always___)) char *
softboundmpx_getenv(const char *name) {
  char *ret_ptr = getenv(name);
  if (ret_ptr != NULL) {
    __softboundmpx_store_return_metadata(ret_ptr,
                                         ret_ptr + strlen(ret_ptr) + 1);
  } else {
    __softboundmpx_store_null_return_metadata();
  }
  return ret_ptr;
}


x86 assembly (clang, -O0):
<softboundmpx_getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1198 <softboundmpx_getenv+0x58>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0x1,%rsi
call   1050 <__softboundmpx_store_return_metadata@plt>
jmp    119f <softboundmpx_getenv+0x5f>
mov    $0x0,%al
call   1060 <__softboundmpx_store_null_return_metadata@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<softboundmpx_getenv>:
push   %rbx
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116a <softboundmpx_getenv+0x2a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1050 <__softboundmpx_store_return_metadata@plt>
jmp    1171 <softboundmpx_getenv+0x31>
xor    %eax,%eax
call   1060 <__softboundmpx_store_null_return_metadata@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define weak i8* @softboundmpx_getenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @getenv(i8* %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i32 @__softboundmpx_store_return_metadata(i8* %9, i8* %15)
br label %19
17: ; preds = %1
%18 = call i32 (...) @__softboundmpx_store_null_return_metadata()
br label %19
19: ; preds = %17, %8
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
define weak i8* @softboundmpx_getenv(i8* %0) {
%2 = tail call i8* @getenv(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %2)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = tail call i32 @__softboundmpx_store_return_metadata(i8* %2, i8* %8)
br label %12
10: ; preds = %1
%11 = tail call i32 (...) @__softboundmpx_store_null_return_metadata()
br label %12
12: ; preds = %10, %4
ret i8* %2
}