void unsetenv(name) char *name;
{
  extern char **environ;
  register char **p;
  int offset;
  while (__findenv(name, &offset))
    for (p = &environ[offset];; ++p)
      if (!(*p = *(p + 1)))
        break;
}


x86 assembly (clang, -O0):
<unsetenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1030 <__findenv@plt>
cmp    $0x0,%eax
je     1186 <unsetenv+0x76>
mov    0x2ead(%rip),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    116b <unsetenv+0x5b>
jmp    1181 <unsetenv+0x71>
jmp    1170 <unsetenv+0x60>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    114d <unsetenv+0x3d>
jmp    111c <unsetenv+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetenv>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1030 <__findenv@plt>
test   %eax,%eax
je     1171 <unsetenv+0x61>
mov    0x2eb5(%rip),%r15
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rax
movslq 0xc(%rsp),%rcx
lea    (%rax,%rcx,8),%rax
add    $0x8,%rax
mov    (%rax),%rcx
mov    %rcx,-0x8(%rax)
add    $0x8,%rax
test   %rcx,%rcx
jne    1150 <unsetenv+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <__findenv@plt>
test   %eax,%eax
jne    1140 <unsetenv+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@environ = external global i8**
define void @unsetenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %25, %1
%6 = load i8*, i8** %2
%7 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @__findenv to i32 (i8*, i32*, ...)*)(i8* %6, i32* %4)
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %5
%10 = load i8**, i8*** @environ
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
store i8** %13, i8*** %3
br label %14
14: ; preds = %22, %9
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
store i8* %17, i8** %18
%19 = icmp ne i8* %17, null
br i1 %19, label %21, label %20
20: ; preds = %14
br label %25
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %3
br label %14
25: ; preds = %20
br label %5
26: ; preds = %5
ret void
}

LLVM IR (-O2):
@environ = external global i8**
define void @unsetenv(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @__findenv to i32 (i8*, i32*, ...)*)(i8* %0, i32* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %19, label %9
6: ; preds = %14
%7 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @__findenv to i32 (i8*, i32*, ...)*)(i8* %0, i32* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %1, %6
%10 = load i8**, i8*** @environ
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
br label %14
14: ; preds = %14, %9
%15 = phi i8** [ %13, %9 ], [ %16, %14 ]
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %15
%18 = icmp eq i8* %17, null
br i1 %18, label %6, label %14
19: ; preds = %6, %1
ret void
}