#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*/ putenv(char *);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ unsetenv(char *);
void mputenv(char *ss) {
  int ll = strlen(ss);
  ss = strdup(ss);
  if (ll > 0 && ss[ll - 1] == '=') {
    ss[ll - 1] = '\000';
    unsetenv(ss);
  } else {
    putenv(ss);
  }
}


x86 assembly (clang, -O0):
<mputenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11a8 <mputenv+0x68>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    11a8 <mputenv+0x68>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1050 <unsetenv@plt>
jmp    11b1 <mputenv+0x71>
mov    -0x8(%rbp),%rdi
call   1040 <putenv@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mputenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <strdup@plt>
test   %ebx,%ebx
jle    1176 <mputenv+0x36>
add    $0xffffffff,%ebx
cmpb   $0x3d,(%rax,%rbx,1)
jne    1176 <mputenv+0x36>
movb   $0x0,(%rax,%rbx,1)
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <unsetenv@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <putenv@plt>

LLVM IR (-O0):
define void @mputenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
%6 = load i8*, i8** %2
%7 = call i8* @strdup(i8* %6)
store i8* %7, i8** %2
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 61
br i1 %18, label %19, label %27
19: ; preds = %10
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %2
%26 = call i32 @unsetenv(i8* %25)
br label %30
27: ; preds = %10, %1
%28 = load i8*, i8** %2
%29 = call i32 @putenv(i8* %28)
br label %30
30: ; preds = %27, %19
ret void
}

LLVM IR (-O2):
define void @mputenv(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @strdup(i8* %0)
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = add nsw i32 %2, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %3, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 61
br i1 %10, label %11, label %13
11: ; preds = %5
store i8 0, i8* %8
%12 = tail call i32 @unsetenv(i8* %3)
br label %15
13: ; preds = %5, %1
%14 = tail call i32 @putenv(i8* %3)
br label %15
15: ; preds = %13, %11
ret void
}