// File: mbourand[P]webserv/srcs/Headers/PreferenceHeader.cpp
// Function: PreferenceHeader::getPreferences[abi:cxx11]() const
std::multimap<float, std::string, std::greater<float> > PreferenceHeader::getPreferences() const
{
	std::multimap<float, std::string, std::greater<float> > language_preferences;
	std::list<std::string> language_tokens = ft::split(_value, ',');

	if (language_tokens.empty())
		return std::multimap<float, std::string, std::greater<float> >();

	for (std::list<std::string>::const_iterator it = language_tokens.begin(); it != language_tokens.end(); it++)
	{
		std::list<std::string> splitted = ft::split(*it, ';');
		if (splitted.size() == 0 || splitted.size() > 2)
			return std::multimap<float, std::string, std::greater<float> >();

		if (splitted.size() == 1)
		{
			if (splitted.front().find_first_not_of(' ') == std::string::npos)
				return std::multimap<float, std::string, std::greater<float> >();

			language_preferences.insert(std::make_pair(1.f, splitted.front().substr(splitted.front().find_first_not_of(' '))));
		}
		else if (splitted.size() == 2)
		{
			if (splitted.front().find_first_not_of(' ') == std::string::npos || splitted.back().find_first_not_of(' ') == std::string::npos)
				return std::multimap<float, std::string, std::greater<float> >();
			if (splitted.back().substr(0, 2) != "q=")
				return std::multimap<float, std::string, std::greater<float> >();


			float preference = 0.0f;
			try { preference = ft::toFloat(splitted.back().substr(2)); }
			catch (std::exception& e) { return std::multimap<float, std::string, std::greater<float> >(); }

			language_preferences.insert(std::make_pair(preference, splitted.front().substr(splitted.front().find_first_not_of(' '))));
		}
	}

	return language_preferences;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x1c8(%rbp)
movq %rdi, %rax
movq %rax, -0x1c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xcbf0
movq -0x1b8(%rbp), %rsi
addq $0x8, %rsi
movb $0x2c, -0x59(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x59(%rbp), %rdx
callq 0x2fa40
jmp 0xc5d6
leaq -0x58(%rbp), %rdi
callq 0xcc10
testb $0x1, %al
jne 0xc5e5
jmp 0xc621
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93b0
movq -0x1c8(%rbp), %rdi
callq 0xcbf0
movl $0x1, -0x70(%rbp)
jmp 0xcbb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcbdb
leaq -0x58(%rbp), %rdi
callq 0xcc30
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xcc60
leaq -0x58(%rbp), %rdi
callq 0xccb0
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xcc60
leaq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xcc80
testb $0x1, %al
jne 0xc677
jmp 0xcb99
leaq -0x78(%rbp), %rdi
callq 0xcce0
movq %rax, %rsi
movb $0x3b, -0xa9(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xa9(%rbp), %rdx
callq 0x2fa40
jmp 0xc69f
leaq -0xa8(%rbp), %rdi
callq 0xcd10
cmpq $0x0, %rax
je 0xc6c3
leaq -0xa8(%rbp), %rdi
callq 0xcd10
cmpq $0x2, %rax
jbe 0xc6ff
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93b0
movq -0x1c8(%rbp), %rdi
callq 0xcbf0
movl $0x1, -0x70(%rbp)
jmp 0xcb5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcbd2
leaq -0xa8(%rbp), %rdi
callq 0xcd10
cmpq $0x1, %rax
jne 0xc86b
leaq -0xa8(%rbp), %rdi
callq 0xcd40
movq %rax, %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x9600
cmpq $-0x1, %rax
jne 0xc763
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93b0
movq -0x1c8(%rbp), %rdi
callq 0xcbf0
movl $0x1, -0x70(%rbp)
jmp 0xcb5d
movl $0x3f800000, -0xdc(%rbp) # imm = 0x3F800000
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0xcd40
movq -0x1d8(%rbp), %rdi
movq %rax, -0x1d0(%rbp)
callq 0xcd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x20, %esi
callq 0x9600
movq -0x1d0(%rbp), %rsi
movq %rax, %rdx
leaq -0x100(%rbp), %rdi
movq $-0x1, %rcx
callq 0x96b0
jmp 0xc7c3
leaq -0xd8(%rbp), %rdi
leaq -0xdc(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0xcda0
jmp 0xc7df
leaq -0x40(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xcd70
movq %rax, -0x1e0(%rbp)
jmp 0xc7f8
movq -0x1e0(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xcde0
leaq -0x100(%rbp), %rdi
callq 0x9c98
jmp 0xcb56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcb8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc85a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xcde0
leaq -0x100(%rbp), %rdi
callq 0x9c98
jmp 0xcb8b
leaq -0xa8(%rbp), %rdi
callq 0xcd10
cmpq $0x2, %rax
jne 0xcb54
leaq -0xa8(%rbp), %rdi
callq 0xcd40
movq %rax, %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x9600
cmpq $-0x1, %rax
je 0xc8c7
leaq -0xa8(%rbp), %rdi
callq 0xce00
movq %rax, %rdi
movl $0x20, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x9600
cmpq $-0x1, %rax
jne 0xc8f2
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93b0
movq -0x1c8(%rbp), %rdi
callq 0xcbf0
movl $0x1, -0x70(%rbp)
jmp 0xcb5d
leaq -0xa8(%rbp), %rdi
callq 0xce00
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x128(%rbp), %rdi
movl $0x2, %ecx
callq 0x96b0
jmp 0xc918
leaq 0x5d8e0(%rip), %rsi     # 0x6a1ff
leaq -0x128(%rbp), %rdi
callq 0xce40
movb %al, -0x1e1(%rbp)
jmp 0xc933
leaq -0x128(%rbp), %rdi
callq 0x9c98
movb -0x1e1(%rbp), %al
testb $0x1, %al
jne 0xc94b
jmp 0xc993
movq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x93b0
movq -0x1c8(%rbp), %rdi
callq 0xcbf0
movl $0x1, -0x70(%rbp)
jmp 0xcb5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x9c98
jmp 0xcb8b
movl $0x0, -0x12c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xce00
movq %rax, %rsi
leaq -0x150(%rbp), %rdi
movl $0x2, %edx
movq $-0x1, %rcx
callq 0x96b0
jmp 0xc9c6
leaq -0x150(%rbp), %rdi
callq 0x2f3f0
movss %xmm0, -0x1e8(%rbp)
jmp 0xc9dc
movss -0x1e8(%rbp), %xmm0
movss %xmm0, -0x12c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x9c98
jmp 0xca6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xca20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x9c98
movl -0x6c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xcb8b
movq -0x68(%rbp), %rdi
callq 0x92a0
movq -0x1c8(%rbp), %rdi
movq %rax, -0x158(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
callq 0xcbf0
movl $0x1, -0x70(%rbp)
callq 0x9a40
jmp 0xca68
jmp 0xcb5d
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0xcd40
movq -0x1f8(%rbp), %rdi
movq %rax, -0x1f0(%rbp)
callq 0xcd40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x20, %esi
callq 0x9600
movq -0x1f0(%rbp), %rsi
movq %rax, %rdx
leaq -0x1a0(%rbp), %rdi
movq $-0x1, %rcx
callq 0x96b0
jmp 0xcac3
leaq -0x180(%rbp), %rdi
leaq -0x12c(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0xce70
jmp 0xcadf
leaq -0x40(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0xcd70
movq %rax, -0x200(%rbp)
jmp 0xcaf8
movq -0x200(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xcde0
leaq -0x1a0(%rbp), %rdi
callq 0x9c98
jmp 0xcb54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xcb46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xcde0
leaq -0x1a0(%rbp), %rdi
callq 0x9c98
jmp 0xcb8b
jmp 0xcb56
movl $0x0, -0x70(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xceb0
movl -0x70(%rbp), %eax
testl %eax, %eax
jne 0xcbb0
jmp 0xcb72
jmp 0xcb74
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
callq 0xced0
movq %rax, -0x1b0(%rbp)
jmp 0xc63b
leaq -0xa8(%rbp), %rdi
callq 0xceb0
jmp 0xcbd2
movq -0x1c8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xcf00
movl $0x1, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xceb0
leaq -0x40(%rbp), %rdi
callq 0xcf30
movq -0x1c0(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0xceb0
leaq -0x40(%rbp), %rdi
callq 0xcf30
movq -0x68(%rbp), %rdi
callq 0x9af0
nopl (%rax)