#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 */
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
int l_putenv_r_thread_safe(char const *, char const *);
int pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int l_putenv_r(const char *key, const char *value) {
  int err;
  sigset_t newmask, oldmask;
  sigfillset(&newmask);
  err = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
  if (err)
    return err;
  err = l_putenv_r_thread_safe(key, value);
  if (err)
    return err;
  pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<l_putenv_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <sigfillset@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <pthread_sigmask@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1177 <l_putenv_r+0x47>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <l_putenv_r+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <l_putenv_r_thread_safe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119c <l_putenv_r+0x6c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <l_putenv_r+0x89>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <pthread_sigmask@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_putenv_r>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <sigfillset@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <pthread_sigmask@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1190 <l_putenv_r+0x60>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <l_putenv_r_thread_safe@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1190 <l_putenv_r+0x60>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <pthread_sigmask@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @l_putenv_r(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i32 @sigfillset(i32* %7)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @pthread_sigmask(i32 %10, i32* %7, i32* %8)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %27
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @l_putenv_r_thread_safe(i8* %17, i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %27
24: ; preds = %16
%25 = load i32, i32* @SIG_SETMASK
%26 = call i32 @pthread_sigmask(i32 %25, i32* %8, i32* null)
store i32 0, i32* %3
br label %27
27: ; preds = %24, %22, %14
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @l_putenv_r(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @sigfillset(i32* %3)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @pthread_sigmask(i32 %8, i32* %3, i32* %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = call i32 @l_putenv_r_thread_safe(i8* %0, i8* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @SIG_SETMASK
%16 = call i32 @pthread_sigmask(i32 %15, i32* %4, i32* null)
br label %17
17: ; preds = %11, %2, %14
%18 = phi i32 [ 0, %14 ], [ %9, %2 ], [ %12, %11 ]
ret i32 %18
}