#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int snprintf(char *, size_t, char *, char const *, char const *);
int strlen(char const *);
char *xmalloc(size_t);
char *make_env_var(const char *name, const char *value) {
  size_t len = strlen(name) + strlen(value) + 2;
  char *ret = xmalloc(len);
  if (len != 1 + snprintf(ret, len, "%s=%s", name, value))
    errx(EXIT_FAILURE, "failed to copy environment");
  return ret;
}


x86 assembly (clang, -O0):
<make_env_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe5f(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
je     11d0 <make_env_var+0x90>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_env_var>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    (%rbx,%r12,1),%eax
add    $0x2,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   1060 <xmalloc@plt>
mov    %rax,%r13
lea    0xe81(%rip),%rdx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
lea    (%rbx,%r12,1),%ecx
add    $0x1,%ecx
cmp    %eax,%ecx
je     11b0 <make_env_var+0x70>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1040 <errx@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s=%s\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"failed to copy environment\00"
define i8* @make_env_var(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i8* @xmalloc(i64 %14)
store i8* %15, i8** %6
%16 = load i64, i64* %5
%17 = load i8*, i8** %6
%18 = load i64, i64* %5
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i32 @snprintf(i8* %17, i64 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = add nsw i32 1, %21
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %16, %23
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @errx(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %2
%29 = load i8*, i8** %6
ret i8* %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s=%s\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"failed to copy environment\00"
define i8* @make_env_var(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = add nsw i32 %5, 2
%7 = sext i32 %6 to i64
%8 = tail call i8* @xmalloc(i64 %7)
%9 = tail call i32 @snprintf(i8* %8, i64 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = add nsw i32 %5, 1
%11 = icmp eq i32 %10, %9
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @errx(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
ret i8* %8
}