#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*/ var;

/* Variables and functions */
int /*<<< orphan*/ _SC_ARG_MAX;
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unsetenv(char *);
void vars_unset(void) {
  int i = 0;
  char var[8];
  long max = sysconf(_SC_ARG_MAX);
  for (; i < max; i++) {
    snprintf(var, sizeof(var), "%d", i);
    if (!getenv(var))
      break;
    unsetenv(var);
  }
  unsetenv("#");
}


x86 assembly (clang, -O0):
<vars_unset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,-0x18(%rbp)
movslq -0x4(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11b5 <vars_unset+0x75>
lea    -0xc(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x8,%esi
lea    0xe7e(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xc(%rbp),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    119e <vars_unset+0x5e>
jmp    11b5 <vars_unset+0x75>
lea    -0xc(%rbp),%rdi
call   1060 <unsetenv@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1161 <vars_unset+0x21>
lea    0xe47(%rip),%rdi
call   1060 <unsetenv@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vars_unset>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
test   %rax,%rax
jle    119f <vars_unset+0x5f>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xe99(%rip),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x8,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <getenv@plt>
test   %eax,%eax
je     119f <vars_unset+0x5f>
mov    %r12,%rdi
call   1060 <unsetenv@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <vars_unset+0x30>
lea    0xe5d(%rip),%rdi
call   1060 <unsetenv@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_SC_ARG_MAX = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"#\00"
define void @vars_unset() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca i64
store i32 0, i32* %1
%4 = load i32, i32* @_SC_ARG_MAX
%5 = call i64 @sysconf(i32 %4)
store i64 %5, i64* %3
br label %6
6: ; preds = %22, %0
%7 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = load i64, i64* %3
%10 = icmp slt i64 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %6
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %1
%14 = call i32 @snprintf(i8* %12, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%16 = call i32 @getenv(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %11
br label %25
19: ; preds = %11
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%21 = call i32 @unsetenv(i8* %20)
br label %22
22: ; preds = %19
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
br label %6
25: ; preds = %18, %6
%26 = call i32 @unsetenv(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@_SC_ARG_MAX = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"#\00"
define void @vars_unset() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @_SC_ARG_MAX
%4 = tail call i64 @sysconf(i32 %3)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %0, %12
%7 = phi i64 [ %14, %12 ], [ 0, %0 ]
%8 = trunc i64 %7 to i32
%9 = call i32 @snprintf(i8* %2, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @getenv(i8* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = call i32 @unsetenv(i8* %2)
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, %4
br i1 %15, label %16, label %6
16: ; preds = %12, %6, %0
%17 = call i32 @unsetenv(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}