// File: /workspace/github_c_makefile_star2_O2/somethingnew2-0[P]CS537-P4/request.c
// Function: requestHandle
void requestHandle(int fd, long arrival, long dispatch, thread *worker)
{

   int is_static;
   struct stat sbuf;
   char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
   char filename[MAXLINE], cgiargs[MAXLINE];
   rio_t rio;

   Rio_readinitb(&rio, fd);
   Rio_readlineb(&rio, buf, MAXLINE);
   sscanf(buf, "%s %s %s", method, uri, version);

   printf("%s %s %s\n", method, uri, version);

   if (strcasecmp(method, "GET")) {
      requestError(fd, method, "501", "Not Implemented", "CS537 Server does not implement this method");
      return;
   }
   requestReadhdrs(&rio);

   is_static = requestParseURI(uri, filename, cgiargs);
   if (stat(filename, &sbuf) < 0) {
      requestError(fd, filename, "404", "Not found", "CS537 Server could not find this file");
      return;
   }

   if (is_static) {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not read this file");
         return;
      }
	  worker->statics++;
      requestServeStatic(fd, filename, sbuf.st_size, arrival, dispatch, worker);
   } else {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not run this CGI program");
         return;
      }
 	  worker->dynamics++;
      requestServeDynamic(fd, filename, cgiargs, arrival, dispatch, worker);
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe0b8, %rsp           # imm = 0xE0B8
movq %rcx, (%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movl %edi, %ebx
leaq 0x80a0(%rsp), %r13
movq %r13, %rdi
movl %ebx, %esi
callq 0x3945
leaq 0xc0b0(%rsp), %rbp
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movq %rbp, %rsi
callq 0x396d
leaq 0x1116(%rip), %rsi      # 0x42be
leaq 0x60a0(%rsp), %r13
leaq 0x40a0(%rsp), %r15
leaq 0xa0b0(%rsp), %r12
movq %rbp, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2210
leaq 0x10ed(%rip), %rdi      # 0x42c7
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2110
leaq 0x10e0(%rip), %rsi      # 0x42d1
movq %r13, %rdi
callq 0x2040
testl %eax, %eax
je 0x321f
leaq 0x10d1(%rip), %rdx      # 0x42d5
leaq 0x10ce(%rip), %rcx      # 0x42d9
leaq 0x10d7(%rip), %r8       # 0x42e9
leaq 0x60a0(%rsp), %rsi
jmp 0x3323
movq %r14, %r13
movq (%rsp), %r12
movq 0x8(%rsp), %r14
leaq 0x80a0(%rsp), %rdi
callq 0x2c05
leaq 0x40a0(%rsp), %rdi
leaq 0xa0(%rsp), %r15
leaq 0x20a0(%rsp), %rdx
movq %r15, %rsi
callq 0x2c55
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x21c0
testl %eax, %eax
js 0x32a5
movl 0x28(%rsp), %eax
testl %ebp, %ebp
je 0x32bc
andl $0xf100, %eax           # imm = 0xF100
cmpl $0x8100, %eax           # imm = 0x8100
jne 0x32ef
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0x8(%r12)
movl 0x40(%rsp), %edx
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2efd
jmp 0x332a
leaq 0x1069(%rip), %rdx      # 0x4315
leaq 0x1066(%rip), %rcx      # 0x4319
leaq 0x1069(%rip), %r8       # 0x4323
jmp 0x331b
andl $0xf040, %eax           # imm = 0xF040
cmpl $0x8040, %eax           # imm = 0x8040
jne 0x3306
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0xc(%r12)
leaq 0xa0(%rsp), %rsi
leaq 0x20a0(%rsp), %rdx
movl %ebx, %edi
callq 0x2da9
jmp 0x332a
leaq 0x1053(%rip), %rdx      # 0x4349
leaq 0x1050(%rip), %rcx      # 0x434d
leaq 0x1053(%rip), %r8       # 0x4357
jmp 0x331b
leaq 0x103c(%rip), %rdx      # 0x4349
leaq 0x1039(%rip), %rcx      # 0x434d
leaq 0x1062(%rip), %r8       # 0x437d
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2a6c
addq $0xe0b8, %rsp           # imm = 0xE0B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq