void putenv_with_prefix(prefix, name, value) char *prefix;
char *name;
char *value;
{
  char *s;
  if (!value)
    return;
  s = malloc(strlen(prefix) + strlen(name) + strlen(value) + 3);
  if (!s)
    nomem();
  sprintf(s, "%s_%s=%s", prefix, name, value);
  putenv(s);
}


x86 assembly (clang, -O0):
<putenv_with_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <putenv_with_prefix+0x24>
jmp    11f0 <putenv_with_prefix+0xa0>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <putenv_with_prefix+0x77>
mov    $0x0,%al
call   1050 <nomem@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <putenv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putenv_with_prefix>:
test   %rdx,%rdx
je     11ce <putenv_with_prefix+0x7e>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
add    %r13,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a1 <putenv_with_prefix+0x51>
xor    %eax,%eax
call   1050 <nomem@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <putenv@plt>
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s_%s=%s\00"
define void @putenv_with_prefix(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %3
br label %34
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add i64 %13, %15
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = add i64 %16, %18
%20 = add i64 %19, 3
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %11
%25 = call i32 (...) @nomem()
br label %26
26: ; preds = %24, %11
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i8*, i8** %6
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29, i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 (i8*, ...) bitcast (i32 (...)* @putenv to i32 (i8*, ...)*)(i8* %32)
br label %34
34: ; preds = %26, %10
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s_%s=%s\00"
define void @putenv_with_prefix(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i64 @strlen(i8* %2)
%9 = add i64 %6, 3
%10 = add i64 %9, %7
%11 = add i64 %10, %8
%12 = tail call i8* @malloc(i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 (...) @nomem()
br label %16
16: ; preds = %14, %5
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @putenv to i32 (i8*, ...)*)(i8* %12)
br label %19
19: ; preds = %3, %16
ret void
}