#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 */
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *strdup(char *);
char *zoo_getname() {
  char buf[1024];
  char *zoo;
  zoo = getenv("ZOO");
  if (zoo) {
    snprintf(buf, 1024, "%s/%s", zoo, "active");
    return strdup(buf);
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<zoo_getname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1197 <zoo_getname+0x67>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    $0x400,%esi
lea    0xe8e(%rip),%rdx
lea    0xe8d(%rip),%r8
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    119f <zoo_getname+0x6f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zoo_getname>:
push   %rbx
sub    $0x400,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1174 <zoo_getname+0x44>
lea    0xeb4(%rip),%rdx
lea    0xeb3(%rip),%r8
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strdup@plt>
jmp    1176 <zoo_getname+0x46>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ZOO\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [7 x i8] c"active\00"
define i8* @zoo_getname() {
%1 = alloca i8*
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @snprintf(i8* %8, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %1
br label %14
13: ; preds = %0
store i8* null, i8** %1
br label %14
14: ; preds = %13, %7
%15 = load i8*, i8** %1
ret i8* %15
}

LLVM IR (-O2):
@.str = [4 x i8] c"ZOO\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [7 x i8] c"active\00"
define noalias i8* @zoo_getname() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @snprintf(i8* %2, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%7 = call i8* @strdup(i8* %2)
br label %8
8: ; preds = %0, %5
%9 = phi i8* [ %7, %5 ], [ null, %0 ]
ret i8* %9
}