#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*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
long sysconf(int /*<<< orphan*/);
void vars_set(char **argv) {
  int i = 0;
  char var[8];
  long max = sysconf(_SC_ARG_MAX);
  for (argv++; *argv && i < max; argv++, i++) {
    snprintf(var, sizeof(var), "%d", i);
    setenv(var, *argv, 1);
  }
  setenv("#", var, 1);
}


x86 assembly (clang, -O0):
<vars_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x21(%rbp)
je     1182 <vars_set+0x52>
movslq -0xc(%rbp),%rax
cmp    -0x20(%rbp),%rax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1192 <vars_set+0x62>
jmp    11d9 <vars_set+0xa9>
lea    -0x14(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
lea    0xe5b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <vars_set+0x31>
lea    -0x14(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vars_set>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmpq   $0x0,0x8(%r15)
je     11a5 <vars_set+0x75>
mov    %rax,%r14
test   %rax,%rax
jle    11a5 <vars_set+0x75>
xor    %ebx,%ebx
lea    0xe9a(%rip),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x8,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1040 <snprintf@plt>
mov    0x8(%r15,%rbx,8),%rsi
mov    %r13,%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmpq   $0x0,0x10(%r15,%rbx,8)
je     11a5 <vars_set+0x75>
add    $0x1,%rbx
cmp    %rbx,%r14
jg     1170 <vars_set+0x40>
lea    0xe57(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
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_set(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca i64
store i8** %0, i8*** %2
store i32 0, i32* %3
%6 = load i32, i32* @_SC_ARG_MAX
%7 = call i64 @sysconf(i32 %6)
store i64 %7, i64* %5
%8 = load i8**, i8*** %2
%9 = getelementptr inbounds i8*, i8** %8, i32 1
store i8** %9, i8*** %2
br label %10
10: ; preds = %29, %1
%11 = load i8**, i8*** %2
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = load i64, i64* %5
%18 = icmp slt i64 %16, %17
br label %19
19: ; preds = %14, %10
%20 = phi i1 [ false, %10 ], [ %18, %14 ]
br i1 %20, label %21, label %34
21: ; preds = %19
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @snprintf(i8* %22, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%26 = load i8**, i8*** %2
%27 = load i8*, i8** %26
%28 = call i32 @setenv(i8* %25, i8* %27, i32 1)
br label %29
29: ; preds = %21
%30 = load i8**, i8*** %2
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %2
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %10
34: ; preds = %19
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%36 = call i32 @setenv(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32 1)
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_set(i8** nocapture %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @_SC_ARG_MAX
%5 = tail call i64 @sysconf(i32 %4)
%6 = getelementptr inbounds i8*, i8** %0, i64 1
%7 = load i8*, i8** %6
%8 = icmp ne i8* %7, null
%9 = icmp sgt i64 %5, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %24
11: ; preds = %1, %11
%12 = phi i64 [ %18, %11 ], [ 0, %1 ]
%13 = phi i8** [ %19, %11 ], [ %6, %1 ]
%14 = trunc i64 %12 to i32
%15 = call i32 @snprintf(i8* %3, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %13
%17 = call i32 @setenv(i8* %3, i8* %16, i32 1)
%18 = add nuw nsw i64 %12, 1
%19 = getelementptr inbounds i8*, i8** %13, i64 1
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
%22 = icmp sgt i64 %5, %18
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %11, label %24
24: ; preds = %11, %1
%25 = call i32 @setenv(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 1)
ret void
}