#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*/ save_var(char *, char *);
char *strchr(char *, char);
void setup_vars(char **argv, char **envp) {
  char *equals;
  int i = 0;
  while (*envp != NULL) {
    equals = strchr(*envp, '=');
    *equals = '\0';
    save_var(*envp, equals + 1);
    *equals = '=';
    envp++;
  }
  while (*argv != NULL && i < 10) {
    char var_name[2] = {0};
    var_name[0] = '0' + i;
    save_var(var_name, *argv);
    argv++;
    i++;
  }
  save_var("?", "0");
}


x86 assembly (clang, -O0):
<setup_vars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     119d <setup_vars+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1050 <save_var@plt>
mov    -0x18(%rbp),%rax
movb   $0x3d,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <setup_vars+0x17>
jmp    11a2 <setup_vars+0x72>
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x1f(%rbp)
je     11bf <setup_vars+0x8f>
cmpl   $0xa,-0x1c(%rbp)
setl   %al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
test   $0x1,%al
jne    11cf <setup_vars+0x9f>
jmp    1212 <setup_vars+0xe2>
lea    -0x1e(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x1e(%rbp)
lea    -0x1e(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1050 <save_var@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <setup_vars+0x72>
lea    0xde7(%rip),%rdi
lea    0xde2(%rip),%rsi
call   1050 <save_var@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_vars>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    (%rsi),%rdi
test   %rdi,%rdi
je     116d <setup_vars+0x4d>
mov    %rsi,%rbx
add    $0x8,%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    -0x8(%rbx),%rdi
lea    0x1(%rax),%rsi
call   1040 <save_var@plt>
movb   $0x3d,(%r15)
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1140 <setup_vars+0x20>
mov    (%r14),%rsi
test   %rsi,%rsi
je     11ac <setup_vars+0x8c>
xor    %ebx,%ebx
lea    0xe(%rsp),%r15
nopl   0x0(%rax)
movw   $0x0,0xe(%rsp)
lea    0x30(%rbx),%eax
mov    %al,0xe(%rsp)
mov    %r15,%rdi
call   1040 <save_var@plt>
mov    0x8(%r14,%rbx,8),%rsi
test   %rsi,%rsi
je     11ac <setup_vars+0x8c>
lea    0x1(%rbx),%rax
cmp    $0x9,%ebx
mov    %rax,%rbx
jb     1180 <setup_vars+0x60>
lea    0xe4d(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1040 <save_var@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"?\00"
@.str.1 = [2 x i8] c"0\00"
define void @setup_vars(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [2 x i8]
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i32 0, i32* %6
br label %8
8: ; preds = %12, %2
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %13
%15 = call i8* @strchr(i8* %14, i8 signext 61)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
store i8 0, i8* %16
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @save_var(i8* %18, i8* %20)
%22 = load i8*, i8** %5
store i8 61, i8* %22
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %4
br label %8
25: ; preds = %8
br label %26
26: ; preds = %35, %25
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 10
br label %33
33: ; preds = %30, %26
%34 = phi i1 [ false, %26 ], [ %32, %30 ]
br i1 %34, label %35, label %49
35: ; preds = %33
%36 = bitcast [2 x i8]* %7 to i8*
%37 = load i32, i32* %6
%38 = add nsw i32 48, %37
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 %39, i8* %40
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%42 = load i8**, i8*** %3
%43 = load i8*, i8** %42
%44 = call i32 @save_var(i8* %41, i8* %43)
%45 = load i8**, i8*** %3
%46 = getelementptr inbounds i8*, i8** %45, i32 1
store i8** %46, i8*** %3
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %26
49: ; preds = %33
%50 = call i32 @save_var(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"?\00"
@.str.1 = [2 x i8] c"0\00"
define void @setup_vars(i8** nocapture %0, i8** nocapture %1) {
%3 = alloca i16
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %11, %2
%7 = load i8*, i8** %0
%8 = icmp eq i8* %7, null
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = bitcast i16* %3 to i8*
br label %21
11: ; preds = %2, %11
%12 = phi i8* [ %19, %11 ], [ %4, %2 ]
%13 = phi i8** [ %18, %11 ], [ %1, %2 ]
%14 = tail call i8* @strchr(i8* %12, i8 signext 61)
store i8 0, i8* %14
%15 = load i8*, i8** %13
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = tail call i32 @save_var(i8* %15, i8* %16)
store i8 61, i8* %14
%18 = getelementptr inbounds i8*, i8** %13, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %6, label %11
21: ; preds = %9, %21
%22 = phi i8* [ %7, %9 ], [ %30, %21 ]
%23 = phi i32 [ 0, %9 ], [ %29, %21 ]
%24 = phi i8** [ %0, %9 ], [ %28, %21 ]
store i16 0, i16* %3
%25 = trunc i32 %23 to i8
%26 = add nuw nsw i8 %25, 48
store i8 %26, i8* %10
%27 = call i32 @save_var(i8* %10, i8* %22)
%28 = getelementptr inbounds i8*, i8** %24, i64 1
%29 = add nuw nsw i32 %23, 1
%30 = load i8*, i8** %28
%31 = icmp ne i8* %30, null
%32 = icmp ult i32 %23, 9
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %21, label %34
34: ; preds = %21, %6
%35 = call i32 @save_var(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}