#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*/ getenv(char const *);
char *malloc(int);
int putenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
extern int unsetenv(const char *name) {
  int len, rc;
  char *tmp;
  if (!getenv(name))
    return 0;
  len = strlen(name);
  tmp = malloc(len + 3);
  strcpy(tmp, name);
  strcat(tmp, "=x");
  if ((rc = putenv(tmp)) != 0)
    return rc;
  tmp[0] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<unsetenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    118a <unsetenv+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <unsetenv+0x90>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1060 <putenv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11e2 <unsetenv+0x82>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <unsetenv+0x90>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <getenv@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     11b3 <unsetenv+0x53>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x3(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1060 <putenv@plt>
test   %eax,%eax
jne    11b3 <unsetenv+0x53>
movb   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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