#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*/ *getenv(char *);
char *make_env_entry(char *, int /*<<< orphan*/ *);
char **malloc(int);
char **create_env(char **env) {
  int n = 0;
  while (env[n] != NULL) {
    n++;
  }
  char **new_env = malloc((n + 3) * sizeof(char *));
  for (int i = 0; i < n; i++) {
    new_env[i] = env[i];
  }
  if (getenv("CC_LD_PRELOAD") != NULL) {
    new_env[n++] = make_env_entry("LD_PRELOAD", getenv("CC_LD_PRELOAD"));
  }
  if (getenv("CC_EASYSANDBOX_HEAPSIZE") != NULL) {
    new_env[n++] = make_env_entry("EASYSANDBOX_HEAPSIZE",
                                  getenv("CC_EASYSANDBOX_HEAPSIZE"));
  }
  new_env[n] = NULL;
  return new_env;
}


x86 assembly (clang, -O0):
<create_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1164 <create_env+0x34>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <create_env+0x13>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b4 <create_env+0x84>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <create_env+0x52>
lea    0xe45(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11fe <create_env+0xce>
lea    0xe2f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe23(%rip),%rdi
call   1040 <make_env_entry@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
lea    0xe09(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1248 <create_env+0x118>
lea    0xdf3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xde7(%rip),%rdi
call   1040 <make_env_entry@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_env>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0xffffffffffffffff,%rbx
mov    $0x10,%edi
nopw   0x0(%rax,%rax,1)
add    $0x8,%edi
cmpq   $0x0,0x8(%r15,%rbx,8)
lea    0x1(%rbx),%rbx
jne    1160 <create_env+0x20>
mov    %ebx,%r12d
call   1060 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     1191 <create_env+0x51>
lea    0x0(,%r12,8),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
lea    0xe68(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b8 <create_env+0x78>
lea    0xe5a(%rip),%rdi
mov    %rax,%rsi
call   1040 <make_env_entry@plt>
add    $0x1,%ebx
mov    %rax,(%r14,%r12,8)
lea    0xe4f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11e2 <create_env+0xa2>
lea    0xe41(%rip),%rdi
mov    %rax,%rsi
call   1040 <make_env_entry@plt>
movslq %ebx,%rcx
add    $0x1,%ebx
mov    %rax,(%r14,%rcx,8)
movslq %ebx,%rax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"CC_LD_PRELOAD\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@.str.2 = [24 x i8] c"CC_EASYSANDBOX_HEAPSIZE\00"
@.str.3 = [21 x i8] c"EASYSANDBOX_HEAPSIZE\00"
define i8** @create_env(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %3
br label %6
6: ; preds = %13, %1
%7 = load i8**, i8*** %2
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %7, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %6
16: ; preds = %6
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 3
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i8** @malloc(i32 %21)
store i8** %22, i8*** %4
store i32 0, i32* %5
br label %23
23: ; preds = %37, %16
%24 = load i32, i32* %5
%25 = load i32, i32* %3
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i8**, i8*** %2
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
br label %37
37: ; preds = %27
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %23
40: ; preds = %23
%41 = call i32* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = call i32* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%45 = call i8* @make_env_entry(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %44)
%46 = load i8**, i8*** %4
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
store i8* %45, i8** %50
br label %51
51: ; preds = %43, %40
%52 = call i32* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp ne i32* %52, null
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = call i32* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%56 = call i8* @make_env_entry(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %55)
%57 = load i8**, i8*** %4
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
store i8* %56, i8** %61
br label %62
62: ; preds = %54, %51
%63 = load i8**, i8*** %4
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
store i8* null, i8** %66
%67 = load i8**, i8*** %4
ret i8** %67
}

LLVM IR (-O2):
@.str = [14 x i8] c"CC_LD_PRELOAD\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@.str.2 = [24 x i8] c"CC_EASYSANDBOX_HEAPSIZE\00"
@.str.3 = [21 x i8] c"EASYSANDBOX_HEAPSIZE\00"
define noalias i8** @create_env(i8** nocapture %0) {
%2 = bitcast i8** %0 to i8*
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ %8, %3 ], [ 0, %1 ]
%5 = getelementptr inbounds i8*, i8** %0, i64 %4
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = trunc i64 %4 to i32
%11 = and i64 %4, 4294967295
%12 = shl i32 %10, 3
%13 = add i32 %12, 24
%14 = tail call i8** @malloc(i32 %13)
%15 = icmp eq i32 %10, 0
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = bitcast i8** %14 to i8*
%18 = shl nuw nsw i64 %11, 3
br label %19
19: ; preds = %16, %9
%20 = tail call i32* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = tail call i8* @make_env_entry(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%24 = add nuw nsw i32 %10, 1
%25 = getelementptr inbounds i8*, i8** %14, i64 %11
store i8* %23, i8** %25
br label %26
26: ; preds = %22, %19
%27 = phi i32 [ %24, %22 ], [ %10, %19 ]
%28 = tail call i32* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = tail call i8* @make_env_entry(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %28)
%32 = add nsw i32 %27, 1
%33 = sext i32 %27 to i64
%34 = getelementptr inbounds i8*, i8** %14, i64 %33
store i8* %31, i8** %34
br label %35
35: ; preds = %30, %26
%36 = phi i32 [ %32, %30 ], [ %27, %26 ]
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %14, i64 %37
store i8* null, i8** %38
ret i8** %14
}