// File: sanaa-khan[P]mini-linux-shell/gbsh.cpp
// Function: setEnvVar(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>)
void setEnvVar(vector<string> tokens) {

	char cwd[100];
	getcwd(cwd, 100);

	setenv("SHELL", cwd, 1);

	string name, value;

	if (tokens.size() == 1) {
		cout << "\033[1;31m" << "Error: ";
		cout << "\033[0;38m" << "Name of environment variable not given.\n";
		return;
	}

	name = tokens[1];

	if (tokens.size() == 2)
		value = "";

	else if (tokens.size() == 3)
		value = tokens[2];

	else {
		cout << "\033[1;31m" << "Error: ";
		cout << "\033[0;38m" << "Too many arguments provided.\n";
		return;
	}

	char* var = getenv(name.c_str());

	if (var != NULL)
		cout << "'" << name << "' is already defined.\n";

	else
		setenv(name.c_str(), value.c_str(), 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x64, %esi
callq 0x20d0
leaq -0x70(%rbp), %rsi
leaq 0x306e(%rip), %rdi      # 0x704d
movl $0x1, %edx
callq 0x22b0
leaq -0x90(%rbp), %rdi
callq 0x2260
leaq -0xb0(%rbp), %rdi
callq 0x2260
movq -0xd0(%rbp), %rdi
callq 0x5780
cmpq $0x1, %rax
jne 0x40b7
movq 0x5faa(%rip), %rdi      # 0x9fc8
leaq 0x3040(%rip), %rsi      # 0x7065
callq 0x21b0
movq %rax, -0xd8(%rbp)
jmp 0x4033
movq -0xd8(%rbp), %rdi
leaq 0x302c(%rip), %rsi      # 0x706d
callq 0x21b0
jmp 0x4048
movq 0x5f79(%rip), %rdi      # 0x9fc8
leaq 0x301f(%rip), %rsi      # 0x7075
callq 0x21b0
movq %rax, -0xe0(%rbp)
jmp 0x4064
movq -0xe0(%rbp), %rdi
leaq 0x3076(%rip), %rsi      # 0x70e8
callq 0x21b0
jmp 0x4079
movl $0x1, -0xc0(%rbp)
jmp 0x425c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x427d
movq -0xd0(%rbp), %rdi
movl $0x1, %esi
callq 0x5760
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x2040
jmp 0x40d9
movq -0xd0(%rbp), %rdi
callq 0x5780
cmpq $0x2, %rax
jne 0x4105
leaq 0x2fbe(%rip), %rsi      # 0x70b0
leaq -0xb0(%rbp), %rdi
callq 0x2240
jmp 0x4100
jmp 0x41ae
movq -0xd0(%rbp), %rdi
callq 0x5780
cmpq $0x3, %rax
jne 0x413b
movq -0xd0(%rbp), %rdi
movl $0x2, %esi
callq 0x5760
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x2040
jmp 0x4139
jmp 0x41ac
movq 0x5e86(%rip), %rdi      # 0x9fc8
leaq 0x2f1c(%rip), %rsi      # 0x7065
callq 0x21b0
movq %rax, -0xe8(%rbp)
jmp 0x4157
movq -0xe8(%rbp), %rdi
leaq 0x2f08(%rip), %rsi      # 0x706d
callq 0x21b0
jmp 0x416c
movq 0x5e55(%rip), %rdi      # 0x9fc8
leaq 0x2efb(%rip), %rsi      # 0x7075
callq 0x21b0
movq %rax, -0xf0(%rbp)
jmp 0x4188
movq -0xf0(%rbp), %rdi
leaq 0x2f7b(%rip), %rsi      # 0x7111
callq 0x21b0
jmp 0x419d
movl $0x1, -0xc0(%rbp)
jmp 0x425c
jmp 0x41ae
leaq -0x90(%rbp), %rdi
callq 0x20b0
movq %rax, %rdi
callq 0x2210
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
je 0x4222
movq 0x5dee(%rip), %rdi      # 0x9fc8
leaq 0x2f4e(%rip), %rsi      # 0x712f
callq 0x21b0
movq %rax, -0xf8(%rbp)
jmp 0x41ef
movq -0xf8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2180
movq %rax, -0x100(%rbp)
jmp 0x420b
movq -0x100(%rbp), %rdi
leaq 0x2f18(%rip), %rsi      # 0x7131
callq 0x21b0
jmp 0x4220
jmp 0x4252
leaq -0x90(%rbp), %rdi
callq 0x20b0
movq %rax, -0x108(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x20b0
movq -0x108(%rbp), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x22b0
movl $0x0, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0x90(%rbp), %rdi
callq 0x2100
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0x2320
nopl (%rax)