#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 */
char *malloc(int);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int strlen(char const *);
int xine_private_setenv(const char *name, const char *val) {
  int len;
  char *env;
  len = strlen(name) + strlen(val) + 2;
  env = malloc(len);
  if (env != NULL) {
    snprintf(env, len, "%s=%s", name, val);
    putenv(env);
    return 0;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<xine_private_setenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b9 <xine_private_setenv+0x79>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe61(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <putenv@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <xine_private_setenv+0x80>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xine_private_setenv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x2,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1194 <xine_private_setenv+0x54>
mov    %rax,%rbx
lea    0xe88(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <putenv@plt>
xor    %eax,%eax
jmp    1199 <xine_private_setenv+0x59>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s=%s\00"
define i32 @xine_private_setenv(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @snprintf(i8* %7, i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = tail call i32 @putenv(i8* %7)
br label %12
12: ; preds = %2, %9
%13 = phi i32 [ 0, %9 ], [ -1, %2 ]
ret i32 %13
}