// File: /workspace/github_c_makefile_star2_O0/vincenthsu[P]nweb/nweb23.c
// Function: logger
void logger(int type, char *s1, char *s2, int socket_fd)
{
	int fd ;
	char logbuffer[BUFSIZE*2];

	switch (type) {
	case ERROR: (void)sprintf(logbuffer,"ERROR: %s:%s Errno=%d exiting pid=%d",s1, s2, errno,getpid()); 
		break;
	case FORBIDDEN: 
		(void)write(socket_fd, "HTTP/1.1 403 Forbidden\nContent-Length: 185\nConnection: close\nContent-Type: text/html\n\n<html><head>\n<title>403 Forbidden</title>\n</head><body>\n<h1>Forbidden</h1>\nThe requested URL, file type or operation is not allowed on this simple static file webserver.\n</body></html>\n",271);
		(void)sprintf(logbuffer,"FORBIDDEN: %s:%s",s1, s2); 
		break;
	case NOTFOUND: 
		(void)write(socket_fd, "HTTP/1.1 404 Not Found\nContent-Length: 136\nConnection: close\nContent-Type: text/html\n\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\nThe requested URL was not found on this server.\n</body></html>\n",224);
		(void)sprintf(logbuffer,"NOT FOUND: %s:%s",s1, s2); 
		break;
	case LOG: (void)sprintf(logbuffer," INFO: %s:%s:%d",s1, s2,socket_fd); break;
	}	
	/* No checks here, nothing can be done with a failure anyway */
	if((fd = open("nweb.log", O_CREAT| O_WRONLY | O_APPEND,0644)) >= 0) {
		(void)write(fd,logbuffer,strlen(logbuffer)); 
		(void)write(fd,"\n",1);      
		(void)close(fd);
	}
	if(type == ERROR || type == NOTFOUND || type == FORBIDDEN) exit(3);
}

// Assembly:
subq $0x3f98, %rsp           # imm = 0x3F98
movl %edi, 0x3f94(%rsp)
movq %rsi, 0x3f88(%rsp)
movq %rdx, 0x3f80(%rsp)
movl %ecx, 0x3f7c(%rsp)
movl 0x3f94(%rsp), %eax
movl %eax, 0x2c(%rsp)
subl $0x2a, %eax
je 0x1337
jmp 0x1307
movl 0x2c(%rsp), %eax
subl $0x2c, %eax
je 0x140f
jmp 0x1316
movl 0x2c(%rsp), %eax
subl $0x193, %eax            # imm = 0x193
je 0x1395
jmp 0x1323
movl 0x2c(%rsp), %eax
subl $0x194, %eax            # imm = 0x194
je 0x13d2
jmp 0x143a
leaq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x3f88(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x3f80(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x1030
movl (%rax), %eax
movl %eax, 0x28(%rsp)
callq 0x1070
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0x28(%rsp), %r8d
movl %eax, %r9d
leaq 0xcd9(%rip), %rsi       # 0x2062
movb $0x0, %al
callq 0x1170
jmp 0x143a
movl 0x3f7c(%rsp), %edi
leaq 0xce4(%rip), %rsi       # 0x2087
movl $0x10f, %edx            # imm = 0x10F
callq 0x1060
leaq 0x30(%rsp), %rdi
movq 0x3f88(%rsp), %rdx
movq 0x3f80(%rsp), %rcx
leaq 0xdce(%rip), %rsi       # 0x2197
movb $0x0, %al
callq 0x1170
jmp 0x143a
movl 0x3f7c(%rsp), %edi
leaq 0xdc8(%rip), %rsi       # 0x21a8
movl $0xe0, %edx
callq 0x1060
leaq 0x30(%rsp), %rdi
movq 0x3f88(%rsp), %rdx
movq 0x3f80(%rsp), %rcx
leaq 0xe83(%rip), %rsi       # 0x2289
movb $0x0, %al
callq 0x1170
jmp 0x143a
leaq 0x30(%rsp), %rdi
movq 0x3f88(%rsp), %rdx
movq 0x3f80(%rsp), %rcx
movl 0x3f7c(%rsp), %r8d
leaq 0xe67(%rip), %rsi       # 0x229a
movb $0x0, %al
callq 0x1170
leaq 0xe69(%rip), %rdi       # 0x22aa
movl $0x441, %esi            # imm = 0x441
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x1140
movl %eax, 0x3f78(%rsp)
cmpl $0x0, %eax
jl 0x14b2
movl 0x3f78(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x1080
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0x1060
movl 0x3f78(%rsp), %edi
leaq 0xf37(%rip), %rsi       # 0x23d3
movl $0x1, %edx
callq 0x1060
movl 0x3f78(%rsp), %edi
callq 0x10e0
cmpl $0x2a, 0x3f94(%rsp)
je 0x14d6
cmpl $0x194, 0x3f94(%rsp) # imm = 0x194
je 0x14d6
cmpl $0x193, 0x3f94(%rsp) # imm = 0x193
jne 0x14e0
movl $0x3, %edi
callq 0x1180
addq $0x3f98, %rsp           # imm = 0x3F98
retq
nopl (%rax,%rax)