#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 */
scalar_t__ __findenv(char const *, int *);
void unsetenv(const 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
call   1030 <__findenv@plt>
cmp    $0x0,%rax
je     1185 <unsetenv+0x75>
mov    0x2eae(%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    116a <unsetenv+0x5a>
jmp    1180 <unsetenv+0x70>
jmp    116f <unsetenv+0x5f>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <unsetenv+0x3c>
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
call   1030 <__findenv@plt>
test   %rax,%rax
je     1170 <unsetenv+0x60>
mov    0x2eb6(%rip),%r15
lea    0xc(%rsp),%r14
nopw   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
call   1030 <__findenv@plt>
test   %rax,%rax
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 i64 @__findenv(i8* %6, i32* %4)
%8 = icmp ne i64 %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 i64 @__findenv(i8* %0, i32* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %19, label %9
6: ; preds = %14
%7 = call i64 @__findenv(i8* %0, i32* %2)
%8 = icmp eq i64 %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
}