#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*/ __ESBMC_assert(int /*<<< orphan*/, char *);
int /*<<< orphan*/ __ESBMC_assume(int);
int /*<<< orphan*/ __ESBMC_is_zero_string(char const *);
scalar_t__ malloc(size_t);
char *getenv_strabs(const char *name) {
__ESBMC_HIDE:;
  __ESBMC_assert(__ESBMC_is_zero_string(name),
                 "zero-termination of argument of getenv");
  _Bool found;
  if (!found)
    return 0;
  char *buffer;
  size_t buf_size;
  __ESBMC_assume(buf_size >= 1);
  buffer = (char *)malloc(buf_size);
  buffer[buf_size - 1] = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<getenv_strabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <__ESBMC_is_zero_string@plt>
mov    %eax,%edi
lea    0xea2(%rip),%rsi
call   1030 <__ESBMC_assert@plt>
testb  $0x1,-0x11(%rbp)
jne    117a <getenv_strabs+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <getenv_strabs+0x71>
cmpq   $0x1,-0x28(%rbp)
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <__ESBMC_assume@plt>
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv_strabs>:
push   %rax
call   1040 <__ESBMC_is_zero_string@plt>
lea    0xed3(%rip),%rsi
mov    %eax,%edi
call   1030 <__ESBMC_assert@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"zero-termination of argument of getenv\00"
define i8* @getenv_strabs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
br label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @__ESBMC_is_zero_string(i8* %8)
%10 = call i32 @__ESBMC_assert(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%11 = load i8, i8* %4
%12 = trunc i8 %11 to i1
br i1 %12, label %14, label %13
13: ; preds = %7
store i8* null, i8** %2
br label %27
14: ; preds = %7
%15 = load i64, i64* %6
%16 = icmp uge i64 %15, 1
%17 = zext i1 %16 to i32
%18 = call i32 @__ESBMC_assume(i32 %17)
%19 = load i64, i64* %6
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = sub i64 %23, 1
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %5
store i8* %26, i8** %2
br label %27
27: ; preds = %14, %13
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [39 x i8] c"zero-termination of argument of getenv\00"
define noalias i8* @getenv_strabs(i8* %0) {
%2 = tail call i32 @__ESBMC_is_zero_string(i8* %0)
%3 = tail call i32 @__ESBMC_assert(i32 %2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
ret i8* null
}