#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*/ memcpy(char *, char const *, size_t);
int strlen(char const *);
char *xmalloc(size_t);
char *alloc_env(const char *key, const char *value) {
  size_t keylen, vallen;
  char *combined;
  keylen = strlen(key);
  vallen = strlen(value) + 1;
  combined = xmalloc(keylen + vallen + 1);
  memcpy(combined, key, keylen);
  combined[keylen] = '=';
  memcpy(&combined[keylen + 1], value, vallen);
  return combined;
}


x86 assembly (clang, -O0):
<alloc_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x3d,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_env>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%r13
lea    (%r12,%r13,1),%rdi
add    $0x2,%rdi
add    $0x1,%r13
call   1040 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
movb   $0x3d,(%rbx,%r12,1)
lea    (%rbx,%r12,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @alloc_env(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
store i64 %14, i64* %6
%15 = load i64, i64* %5
%16 = load i64, i64* %6
%17 = add i64 %15, %16
%18 = add i64 %17, 1
%19 = call i8* @xmalloc(i64 %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %3
%22 = load i64, i64* %5
%23 = call i32 @memcpy(i8* %20, i8* %21, i64 %22)
%24 = load i8*, i8** %7
%25 = load i64, i64* %5
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 61, i8* %26
%27 = load i8*, i8** %7
%28 = load i64, i64* %5
%29 = add i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %4
%32 = load i64, i64* %6
%33 = call i32 @memcpy(i8* %30, i8* %31, i64 %32)
%34 = load i8*, i8** %7
ret i8* %34
}

LLVM IR (-O2):
define i8* @alloc_env(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = add nsw i64 %4, 1
%9 = add nsw i64 %8, %7
%10 = tail call i8* @xmalloc(i64 %9)
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i64 %4)
%12 = getelementptr inbounds i8, i8* %10, i64 %4
store i8 61, i8* %12
%13 = getelementptr inbounds i8, i8* %10, i64 %8
%14 = tail call i32 @memcpy(i8* %13, i8* %1, i64 %7)
ret i8* %10
}