#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 const *);
int setenv(char const *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int appendenv(const char *opt, const char *new) {
  char buf[1024];
  char *old = getenv(opt);
  buf[1023] = 0;
  if (old)
    snprintf(buf, 1023, "%s %s", old, new);
  else
    snprintf(buf, 1023, "%s", new);
  return setenv(opt, buf, 1);
}


x86 assembly (clang, -O0):
<appendenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x418(%rbp)
movb   $0x0,-0x11(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     118f <appendenv+0x5f>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x3ff,%esi
lea    0xe7d(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    11ad <appendenv+0x7d>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xe5d(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendenv>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <getenv@plt>
movb   $0x0,0x3ff(%rsp)
test   %rax,%rax
je     1170 <appendenv+0x40>
lea    0xea7(%rip),%rdx
mov    %rsp,%rdi
mov    $0x3ff,%esi
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    1189 <appendenv+0x59>
lea    0xe8c(%rip),%rdx
mov    %rsp,%rdi
mov    $0x3ff,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @appendenv(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @getenv(i8* %7)
store i8* %8, i8** %6
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 1023
store i8 0, i8* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i8*, i8** %4
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %13, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
br label %21
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %18, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %17, %12
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = call i32 @setenv(i8* %22, i8* %23, i32 1)
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @appendenv(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @getenv(i8* %0)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %6
%7 = icmp eq i8* %5, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %1)
br label %12
10: ; preds = %2
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %12
12: ; preds = %10, %8
%13 = call i32 @setenv(i8* %0, i8* %4, i32 1)
ret i32 %13
}