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

	auto map = ctx->pop();
	auto fn  = ctx->pop();
	if (map.type != type_t::Map || fn.type != type_t::Lambda)
		throw std::runtime_error("map macro usage error");

	auto res = new MapContainer(ctx);
	ctx->push(Value::map(res));

	auto &vecdata = map._map->vecdata;
	for (unsigned int i = 0; i < vecdata.size(); ++i) {
		auto key = Value::number(i);
		ctx->push(vecdata[i]);
		ctx->push(key);
		res->set(key, fn.call(ctx, 2, env));
	}

	for (auto [key, value]: map._map->data) {
		ctx->push(value);
		ctx->push(key);
		res->set(key, fn.call(ctx, 2, env));
	}

	return ctx->pop(); // res muss auf stack liegen weil GC
}

// Assembly:
subq $0x218, %rsp            # imm = 0x218
movq %rdx, 0x88(%rsp)
movl %edi, 0x204(%rsp)
movq %rsi, 0x1f8(%rsp)
movq %rdx, 0x1f0(%rsp)
cmpl $0x2, 0x204(%rsp)
je 0x2ba87
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x80(%rsp)
leaq 0xda12(%rip), %rsi      # 0x39451
callq 0x6160
jmp 0x2ba46
movq 0x80(%rsp), %rdi
movq 0x2059b(%rip), %rsi     # 0x4bff0
movq 0x20544(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x80(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
callq 0x6320
jmp 0x2bfcb
movq 0x1f8(%rsp), %rdi
callq 0x26b50
movl %eax, 0x1d0(%rsp)
movq %rdx, 0x1d8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x26b50
movl %eax, 0x1c0(%rsp)
movq %rdx, 0x1c8(%rsp)
cmpl $0x6, 0x1d0(%rsp)
jne 0x2bad3
cmpl $0x5, 0x1c0(%rsp)
je 0x2bb31
movl $0x10, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x78(%rsp)
leaq 0xd962(%rip), %rsi      # 0x39451
callq 0x6160
jmp 0x2baf6
movq 0x78(%rsp), %rdi
movq 0x204ee(%rip), %rsi     # 0x4bff0
movq 0x20497(%rip), %rdx     # 0x4bfa0
callq 0x6780
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
callq 0x6320
jmp 0x2bfcb
movl $0x68, %edi
callq 0x6460
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x70(%rsp)
movq 0x1f8(%rsp), %rsi
callq 0x212d0
jmp 0x2bb55
movq 0x70(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x7be0
movq 0x68(%rsp), %rdi
movl %eax, 0x1a8(%rsp)
movq %rdx, 0x1b0(%rsp)
movl 0x1a8(%rsp), %esi
movq 0x1b0(%rsp), %rdx
callq 0x26b20
movq 0x1d8(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x1a0(%rsp)
movl $0x0, 0x19c(%rsp)
movl 0x19c(%rsp), %eax
movq %rax, 0x60(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x1d030
movq %rax, %rcx
movq 0x60(%rsp), %rax
cmpq %rcx, %rax
jae 0x2bd9e
movl 0x19c(%rsp), %eax
cvtsi2sd %rax, %xmm0
callq 0x1d090
movl %eax, 0x188(%rsp)
movq %rdx, 0x190(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1a0(%rsp), %rdi
movl 0x19c(%rsp), %eax
movl %eax, %esi
callq 0x22c80
movq 0x30(%rsp), %rdi
movups (%rax), %xmm0
movaps %xmm0, 0x170(%rsp)
movl 0x170(%rsp), %esi
movq 0x178(%rsp), %rdx
callq 0x26b20
movq 0x1f8(%rsp), %rdi
movups 0x188(%rsp), %xmm0
movaps %xmm0, 0x160(%rsp)
movl 0x160(%rsp), %esi
movq 0x168(%rsp), %rdx
callq 0x26b20
movq 0x88(%rsp), %rsi
movq 0x1b8(%rsp), %rax
movq %rax, 0x38(%rsp)
movups 0x188(%rsp), %xmm0
movaps %xmm0, 0x150(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x130(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x7d80
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rcx
leaq 0x1c0(%rsp), %rdi
movl $0x2, %edx
callq 0x219c0
movq %rdx, 0x50(%rsp)
movl %eax, 0x5c(%rsp)
jmp 0x2bceb
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl %ecx, 0x140(%rsp)
movq %rax, 0x148(%rsp)
movl 0x150(%rsp), %esi
movq 0x158(%rsp), %rdx
movl 0x140(%rsp), %ecx
movq 0x148(%rsp), %r8
callq 0x21550
jmp 0x2bd2d
leaq 0x130(%rsp), %rdi
callq 0x7db0
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x2bbc3
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
movl $0x68, %esi
callq 0x6470
jmp 0x2bfcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x7db0
jmp 0x2bfcb
movq 0x1d8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rdi
callq 0x22fc0
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
callq 0x22d20
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x22ae0
testb $0x1, %al
jne 0x2bdfa
jmp 0x2bf98
leaq 0x120(%rsp), %rdi
callq 0x22ff0
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
leaq 0xf0(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x22b20
movq (%rsp), %rdi
movq %rax, 0xe8(%rsp)
callq 0x22b30
movq %rax, 0xe0(%rsp)
movq 0x1f8(%rsp), %rdi
movq 0xe0(%rsp), %rax
movups (%rax), %xmm0
movaps %xmm0, 0xd0(%rsp)
movl 0xd0(%rsp), %esi
movq 0xd8(%rsp), %rdx
callq 0x26b20
movq 0x1f8(%rsp), %rdi
movq 0xe8(%rsp), %rax
movups (%rax), %xmm0
movaps %xmm0, 0xc0(%rsp)
movl 0xc0(%rsp), %esi
movq 0xc8(%rsp), %rdx
callq 0x26b20
movq 0x88(%rsp), %rsi
movq 0x1b8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xe8(%rsp), %rax
movups (%rax), %xmm0
movaps %xmm0, 0xb0(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7d80
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
leaq 0x1c0(%rsp), %rdi
movl $0x2, %edx
callq 0x219c0
movq %rdx, 0x20(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x2bf14
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl %ecx, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
movl 0xb0(%rsp), %esi
movq 0xb8(%rsp), %rdx
movl 0xa0(%rsp), %ecx
movq 0xa8(%rsp), %r8
callq 0x21550
jmp 0x2bf56
leaq 0x90(%rsp), %rdi
callq 0x7db0
leaq 0x120(%rsp), %rdi
callq 0x23010
jmp 0x2bddc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x7db0
jmp 0x2bfcb
movq 0x1f8(%rsp), %rdi
callq 0x26b50
movl %eax, 0x208(%rsp)
movq %rdx, 0x210(%rsp)
movl 0x208(%rsp), %eax
movq 0x210(%rsp), %rdx
addq $0x218, %rsp            # imm = 0x218
retq
movq 0x1e8(%rsp), %rdi
callq 0x67a0
nopl (%rax,%rax)