#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*/ die_oom();
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *xenviron_allocate_entry(const char *name, const char *value) {
  size_t name_length = strlen(name);
  size_t value_length = strlen(value);
  size_t entry_alloc = name_length + 1 + value_length + 1;
  char *entry = malloc(entry_alloc);
  if (entry == NULL)
    die_oom();
  memcpy(&entry[0], name, name_length);
  entry[name_length] = '=';
  memcpy(&entry[name_length + 1], value, value_length);
  entry[name_length + 1 + value_length] = '\0';
  return entry;
}


x86 assembly (clang, -O0):
<xenviron_allocate_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119d <xenviron_allocate_entry+0x5d>
mov    $0x0,%al
call   1030 <die_oom@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x3d,(%rax,%rcx,1)
mov    -0x30(%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    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
add    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xenviron_allocate_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
lea    0x1(%r13),%rbp
add    %r13,%rax
add    $0x1,%rax
mov    %rax,(%rsp)
lea    (%r12,%r13,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118f <xenviron_allocate_entry+0x4f>
xor    %eax,%eax
call   1030 <die_oom@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
movb   $0x3d,(%rbx,%r13,1)
mov    %rbx,%rdi
add    %rbp,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    (%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @xenviron_allocate_entry(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = add i64 %13, 1
%15 = load i64, i64* %6
%16 = add i64 %14, %15
%17 = add i64 %16, 1
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (...) @die_oom()
br label %24
24: ; preds = %22, %2
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8*, i8** %3
%28 = load i64, i64* %5
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
%30 = load i8*, i8** %8
%31 = load i64, i64* %5
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 61, i8* %32
%33 = load i8*, i8** %8
%34 = load i64, i64* %5
%35 = add i64 %34, 1
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8*, i8** %4
%38 = load i64, i64* %6
%39 = call i32 @memcpy(i8* %36, i8* %37, i64 %38)
%40 = load i8*, i8** %8
%41 = load i64, i64* %5
%42 = add i64 %41, 1
%43 = load i64, i64* %6
%44 = add i64 %42, %43
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %8
ret i8* %46
}

LLVM IR (-O2):
define i8* @xenviron_allocate_entry(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 1
%6 = add i64 %5, %4
%7 = add i64 %6, 1
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 (...) @die_oom()
br label %12
12: ; preds = %10, %2
%13 = tail call i32 @memcpy(i8* %8, i8* %0, i64 %3)
%14 = getelementptr inbounds i8, i8* %8, i64 %3
store i8 61, i8* %14
%15 = getelementptr inbounds i8, i8* %8, i64 %5
%16 = tail call i32 @memcpy(i8* %15, i8* %1, i64 %4)
%17 = getelementptr inbounds i8, i8* %8, i64 %6
store i8 0, i8* %17
ret i8* %8
}