// File: iamlouk[P]asbi/src/procenv.cc
// Function: all_env_vars(int, asbi::Context*, std::shared_ptr<asbi::Env>)
static Value all_env_vars(int n, Context* ctx, std::shared_ptr<Env>) {
	if (n != 0)
		throw std::runtime_error("env:all usage error");

	auto vars = new MapContainer(ctx);
	for (int i = 0; environ[i] != NULL; ++i) {
		const char* str = environ[i];
		const char* pos = std::strchr(str, '=');
		if (pos == NULL)
			throw std::runtime_error("unexpected environment variable format");

		std::size_t len = std::abs(str - pos);
		std::string name(str, len);
		std::string value(str + len + 1);
		vars->set(Value::string(name, ctx), Value::string(value, ctx));
	}
	return Value::map(vars);
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movl %edi, 0x124(%rsp)
movq %rsi, 0x118(%rsp)
movq %rdx, 0x110(%rsp)
cmpl $0x0, 0x124(%rsp)
je 0x2d4c6
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x60(%rsp)
leaq 0xc0b3(%rip), %rsi      # 0x39537
callq 0x6160
jmp 0x2d48b
movq 0x60(%rsp), %rdi
movq 0x1eb59(%rip), %rsi     # 0x4bff0
movq 0x1eb02(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x60(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
callq 0x6320
jmp 0x2d824
movl $0x68, %edi
callq 0x6460
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq 0x118(%rsp), %rsi
callq 0x212d0
jmp 0x2d4ea
movq 0x58(%rsp), %rax
movq %rax, 0xf8(%rsp)
movl $0x0, 0xf4(%rsp)
movq 0x1eabf(%rip), %rax     # 0x4bfc8
movq (%rax), %rax
movslq 0xf4(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x2d7f1
movq 0x1eaa2(%rip), %rax     # 0x4bfc8
movq (%rax), %rax
movslq 0xf4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movl $0x3d, %esi
callq 0x6130
movq %rax, 0xe0(%rsp)
cmpq $0x0, 0xe0(%rsp)
jne 0x2d5ec
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x50(%rsp)
leaq 0xbfc9(%rip), %rsi      # 0x3954b
callq 0x6160
jmp 0x2d589
movq 0x50(%rsp), %rdi
movq 0x1ea5b(%rip), %rsi     # 0x4bff0
movq 0x1ea04(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x58(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
movl $0x68, %esi
callq 0x6470
jmp 0x2d824
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
callq 0x6320
jmp 0x2d824
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %rax
subq %rax, %rdi
callq 0x2e7f0
movq %rax, 0xd8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x67b0
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
leaq 0xb8(%rsp), %rdi
callq 0x6510
jmp 0x2d656
leaq 0xb7(%rsp), %rdi
callq 0x64c0
movq 0xe8(%rsp), %rax
movq 0xd8(%rsp), %rcx
leaq 0x1(%rax,%rcx), %rax
movq %rax, 0x28(%rsp)
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x67b0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x90(%rsp), %rdi
callq 0x7c20
jmp 0x2d6a8
leaq 0x8f(%rsp), %rdi
callq 0x64c0
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x118(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x21970
movq %rdx, 0x18(%rsp)
movl %eax, 0x24(%rsp)
jmp 0x2d6e2
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
movq 0x118(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x21970
movq %rdx, (%rsp)
movl %eax, 0xc(%rsp)
jmp 0x2d716
movq 0x10(%rsp), %rdi
movq (%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movl 0x78(%rsp), %esi
movq 0x80(%rsp), %rdx
movl 0x68(%rsp), %ecx
movq 0x70(%rsp), %r8
callq 0x21550
jmp 0x2d748
leaq 0x90(%rsp), %rdi
callq 0x6290
leaq 0xb8(%rsp), %rdi
callq 0x6290
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x2d502
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xb7(%rsp), %rdi
callq 0x64c0
jmp 0x2d824
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x8f(%rsp), %rdi
callq 0x64c0
jmp 0x2d7e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x6290
leaq 0xb8(%rsp), %rdi
callq 0x6290
jmp 0x2d824
movq 0xf8(%rsp), %rdi
callq 0x7be0
movl %eax, 0x128(%rsp)
movq %rdx, 0x130(%rsp)
movl 0x128(%rsp), %eax
movq 0x130(%rsp), %rdx
addq $0x138, %rsp            # imm = 0x138
retq
movq 0x108(%rsp), %rdi
callq 0x67a0
nopw %cs:(%rax,%rax)