// File: /workspace/github_c_makefile_star2_O0/stefpant[P]TCPserver/webserver/functions.c
// Function: create_answer
char* create_answer(int *curlen,char *page,int err,int* pagebytes){
	time_t timer;
	char timebuffer[26];
	struct tm* tm_info;
	char* ans = malloc(200*sizeof(char));
	int flag=0;

	if( err == -1){
		strcpy(ans,"HTTP/1.1 400 Bad Request\r\n");
		flag=1;
	}
	else if(0 != access(page,F_OK)){
		strcpy(ans,"HTTP/1.1 404 Not Found\r\n");
		flag=2;
	}
	else if(0 != access(page,R_OK)){
		strcpy(ans,"HTTP/1.1 403 Forbidden\r\n");
		flag=3;
	}
	else
		strcpy(ans,"HTTP/1.1 200 OK\r\n");
	*curlen = 200;
	int bytes;
	//char* line = NULL;
	char* charbytes = NULL;

	strcat(ans,"Date: ");

	time(&timer);
	tm_info = localtime(&timer);
	strftime(timebuffer, 26, "%a, %d-%m-%Y %H:%M:%S", tm_info);

	strcat(ans,timebuffer);
	strcat(ans," GMT\r\n");
	strcat(ans,"Server: webserver/1.0.0 (Ubuntu64)\r\n");
	strcat(ans,"Content-Length: ");
	char* cppage = NULL;
	if( !flag )
		cppage = copy_page(page,&bytes);
	else if(flag == 1)
		bytes = 37;
	else if(flag == 2)
		bytes = 50;
	else
		bytes = 71;
	charbytes = myitoa(bytes);
	strcat(ans,charbytes);
	free(charbytes);
	strcat(ans,"\r\n");
	strcat(ans,"Content-Type: text/html\r\n");
	strcat(ans,"Connection: Closed\r\n\r\n");
	*curlen = strlen(ans);
	if(flag == 1){
		*curlen += 37;
		ans = (char *)realloc(ans,(*curlen)*sizeof(char));
		strcat(ans,"<html>Bad request received!</html>\r\n");
	}
	else if(flag == 2){
		*curlen += 52;
		ans = (char *)realloc(ans,(*curlen)*sizeof(char));
		strcat(ans,"<html>Sorry dude, couldn't find this file!</html>\r\n");
	}
	else if(flag == 3){
		*curlen += 73;
		ans = (char *)realloc(ans,(*curlen)*sizeof(char));
		strcat(ans,"<html>Trying to access this file but don't think I can make it!</html>\r\n");
	}
	else{

		*curlen += strlen(cppage) + 3;//for \0 and in the end \r\n
		ans = (char *)realloc(ans,(*curlen)*sizeof(char));
		strcat(ans,cppage);
		strcat(ans,"\r\n");
		free(cppage);
	}
	*pagebytes = bytes;
	return ans;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0xc8, %edi
callq 0x21e0
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x2c6e
movq -0x60(%rbp), %rdi
leaq 0x13d8(%rip), %rsi      # 0x4038
callq 0x2070
movl $0x1, -0x64(%rbp)
jmp 0x2cdd
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2290
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2c9a
movq -0x60(%rbp), %rdi
leaq 0x13c7(%rip), %rsi      # 0x4053
callq 0x2070
movl $0x2, -0x64(%rbp)
jmp 0x2cdb
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x2290
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2cc9
movq -0x60(%rbp), %rdi
leaq 0x13b1(%rip), %rsi      # 0x406c
callq 0x2070
movl $0x3, -0x64(%rbp)
jmp 0x2cd9
movq -0x60(%rbp), %rdi
leaq 0x13b1(%rip), %rsi      # 0x4085
callq 0x2070
jmp 0x2cdb
jmp 0x2cdd
movq -0x8(%rbp), %rax
movl $0xc8, (%rax)
movq $0x0, -0x70(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x139d(%rip), %rsi      # 0x4097
callq 0x22e0
leaq -0x28(%rbp), %rdi
callq 0x21b0
leaq -0x28(%rbp), %rdi
callq 0x2040
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rcx
movl $0x1a, %esi
leaq 0x1375(%rip), %rdx      # 0x409e
callq 0x2260
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x136e(%rip), %rsi      # 0x40b4
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x1365(%rip), %rsi      # 0x40bb
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x137a(%rip), %rsi      # 0x40e0
callq 0x22e0
movq $0x0, -0x78(%rbp)
cmpl $0x0, -0x64(%rbp)
jne 0x2d8c
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2b30
movq %rax, -0x78(%rbp)
jmp 0x2db5
cmpl $0x1, -0x64(%rbp)
jne 0x2d9b
movl $0x25, -0x68(%rbp)
jmp 0x2db3
cmpl $0x2, -0x64(%rbp)
jne 0x2daa
movl $0x32, -0x68(%rbp)
jmp 0x2db1
movl $0x47, -0x68(%rbp)
jmp 0x2db3
jmp 0x2db5
movl -0x68(%rbp), %edi
callq 0x2750
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x22e0
movq -0x70(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rdi
leaq 0x133d(%rip), %rsi      # 0x411f
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x12ff(%rip), %rsi      # 0x40f1
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x1309(%rip), %rsi      # 0x410b
callq 0x22e0
movq -0x60(%rbp), %rdi
callq 0x20d0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x1, -0x64(%rbp)
jne 0x2e56
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $0x25, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq (%rax), %rsi
shlq $0x0, %rsi
callq 0x2210
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x12d6(%rip), %rsi      # 0x4122
callq 0x22e0
jmp 0x2f2d
cmpl $0x2, -0x64(%rbp)
jne 0x2e94
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $0x34, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq (%rax), %rsi
shlq $0x0, %rsi
callq 0x2210
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x12bd(%rip), %rsi      # 0x4147
callq 0x22e0
jmp 0x2f2b
cmpl $0x3, -0x64(%rbp)
jne 0x2ecf
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $0x49, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq (%rax), %rsi
shlq $0x0, %rsi
callq 0x2210
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x12b3(%rip), %rsi      # 0x417b
callq 0x22e0
jmp 0x2f29
movq -0x78(%rbp), %rdi
callq 0x20d0
movq %rax, %rdx
addq $0x3, %rdx
movq -0x8(%rbp), %rax
movslq (%rax), %rcx
addq %rdx, %rcx
movl %ecx, (%rax)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq (%rax), %rsi
shlq $0x0, %rsi
callq 0x2210
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x22e0
movq -0x60(%rbp), %rdi
leaq 0x1204(%rip), %rsi      # 0x411f
callq 0x22e0
movq -0x78(%rbp), %rdi
callq 0x2030
jmp 0x2f2b
jmp 0x2f2d
movl -0x68(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)