// File: m1c0l[P]http-client-server/HttpRequest.cpp
// Function: HttpRequest::decodeFirstLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int HttpRequest::decodeFirstLine(string line) {
	stringstream ss;
	ss << line;
	string method, url, version;
	ss >> method >> url >> version;

	
	
	if (url.substr(0,7) == "http://"){
	  url = url.substr(7);
	}
	//size_t colonPos = url.find_first_of(":");
	size_t slashPos = url.find_first_of("/");
	/*
	string hostName = url;
	if (colonPos != string::npos) {
	  hostname = url.substr(0,colPos);
	}
	else if (slashPos != string::npos) {
	  hostname = url.substr(0,slashPos);
	}

	string port = "80";
	if (colonPos != string::npos && slashPos != string::npos) {
	  port = url.substr(colonPos + 1, slashPos - colonPos - 1);
	}
	else if (colonPos != string::npos) {
	  port = url.substr(colonPos + 1);
	}
	*/
	string filename = "/";
	if (slashPos != string::npos) {
	  filename = url.substr(slashPos);
	}
	setMethod(method);
	setUrl(filename);
	setVersion(version);
	if (method != "GET") {
		// only GET supported
		return 501;
	}        
	if (version == "HTTP/1.1") {

		// this HTTP version not implemented yet
		return 505;
	}
	else if (version != "HTTP/1.0") {
		// bad version string
	  return 400;}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rsi, -0x310(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x318(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x52d0
movq -0x310(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x5380
jmp 0x7ff6
leaq -0x1d0(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x55c0
leaq -0x1f0(%rbp), %rdi
callq 0x55c0
leaq -0x210(%rbp), %rdi
callq 0x55c0
movq -0x328(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x5540
movq %rax, -0x320(%rbp)
jmp 0x803d
movq -0x320(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x5540
movq %rax, -0x330(%rbp)
jmp 0x8059
movq -0x330(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x5540
jmp 0x806e
xorl %eax, %eax
movl %eax, %edx
leaq -0x230(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
movl $0x7, %ecx
callq 0x5440
jmp 0x808c
leaq 0xaf9e(%rip), %rsi      # 0x13031
leaq -0x230(%rbp), %rdi
callq 0x8650
movb %al, -0x331(%rbp)
jmp 0x80a7
leaq -0x230(%rbp), %rdi
callq 0x5280
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0x80c2
jmp 0x8155
leaq -0x250(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
movl $0x7, %edx
movq $-0x1, %rcx
callq 0x5440
jmp 0x80e3
leaq -0x1f0(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x5500
leaq -0x250(%rbp), %rdi
callq 0x5280
jmp 0x8155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x8484
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x8460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5280
jmp 0x8460
leaq 0xaedb(%rip), %rsi      # 0x13037
movq %rsi, -0x348(%rbp)
xorl %eax, %eax
movl %eax, %edx
leaq -0x1f0(%rbp), %rdi
callq 0x5220
movq %rax, -0x258(%rbp)
leaq -0x279(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x5690
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdx
leaq -0x278(%rbp), %rdi
callq 0x6200
jmp 0x81a9
leaq -0x279(%rbp), %rdi
callq 0x5480
cmpq $-0x1, -0x258(%rbp)
je 0x823d
movq -0x258(%rbp), %rdx
leaq -0x2a0(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
movq $-0x1, %rcx
callq 0x5440
jmp 0x81e2
leaq -0x278(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x5500
leaq -0x2a0(%rbp), %rdi
callq 0x5280
jmp 0x823d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x279(%rbp), %rdi
callq 0x5480
jmp 0x8460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x8454
leaq -0x2c0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x51a0
jmp 0x8252
movq -0x318(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x7ee0
jmp 0x8267
leaq -0x2c0(%rbp), %rdi
callq 0x5280
leaq -0x2e0(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x51a0
jmp 0x8288
movq -0x318(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x7f50
jmp 0x829d
leaq -0x2e0(%rbp), %rdi
callq 0x5280
leaq -0x300(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x51a0
jmp 0x82be
movq -0x318(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x58e0
jmp 0x82d3
leaq -0x300(%rbp), %rdi
callq 0x5280
leaq 0xad53(%rip), %rsi      # 0x13039
leaq -0x1d0(%rbp), %rdi
callq 0x8680
movb %al, -0x349(%rbp)
jmp 0x82fa
movb -0x349(%rbp), %al
testb $0x1, %al
jne 0x8306
jmp 0x8385
movl $0x1f5, -0x4(%rbp)      # imm = 0x1F5
movl $0x1, -0x304(%rbp)
jmp 0x840c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x5280
jmp 0x8454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x5280
jmp 0x8454
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x5280
jmp 0x8454
leaq 0xacb1(%rip), %rsi      # 0x1303d
leaq -0x210(%rbp), %rdi
callq 0x8650
movb %al, -0x34a(%rbp)
jmp 0x83a0
movb -0x34a(%rbp), %al
testb $0x1, %al
jne 0x83ac
jmp 0x83bf
movl $0x1f9, -0x4(%rbp)      # imm = 0x1F9
movl $0x1, -0x304(%rbp)
jmp 0x840c
leaq 0xac80(%rip), %rsi      # 0x13046
leaq -0x210(%rbp), %rdi
callq 0x8680
movb %al, -0x34b(%rbp)
jmp 0x83da
movb -0x34b(%rbp), %al
testb $0x1, %al
jne 0x83e6
jmp 0x83f9
movl $0x190, -0x4(%rbp)      # imm = 0x190
movl $0x1, -0x304(%rbp)
jmp 0x840c
jmp 0x83fb
movl $0x0, -0x4(%rbp)
movl $0x1, -0x304(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x5280
leaq -0x210(%rbp), %rdi
callq 0x5280
leaq -0x1f0(%rbp), %rdi
callq 0x5280
leaq -0x1d0(%rbp), %rdi
callq 0x5280
leaq -0x1a0(%rbp), %rdi
callq 0x5300
movl -0x4(%rbp), %eax
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x278(%rbp), %rdi
callq 0x5280
leaq -0x210(%rbp), %rdi
callq 0x5280
leaq -0x1f0(%rbp), %rdi
callq 0x5280
leaq -0x1d0(%rbp), %rdi
callq 0x5280
leaq -0x1a0(%rbp), %rdi
callq 0x5300
movq -0x1a8(%rbp), %rdi
callq 0x5680
nopl (%rax)