// File: /workspace/github_c_makefile_star2_O1/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 0x3a07
leaq 0xc0b0(%rsp), %rbp
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3a32
leaq 0x105e(%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 0x1035(%rip), %rdi      # 0x42c7
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2110
leaq 0x1028(%rip), %rsi      # 0x42d1
movq %r13, %rdi
callq 0x2040
testl %eax, %eax
je 0x32d7
leaq 0x1019(%rip), %rdx      # 0x42d5
leaq 0x1016(%rip), %rcx      # 0x42d9
leaq 0x101f(%rip), %r8       # 0x42e9
leaq 0x60a0(%rsp), %rsi
jmp 0x33db
movq %r14, %r13
movq (%rsp), %r12
movq 0x8(%rsp), %r14
leaq 0x80a0(%rsp), %rdi
callq 0x2c99
leaq 0x40a0(%rsp), %rdi
leaq 0xa0(%rsp), %r15
leaq 0x20a0(%rsp), %rdx
movq %r15, %rsi
callq 0x2cf9
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x21c0
testl %eax, %eax
js 0x335d
movl 0x28(%rsp), %eax
testl %ebp, %ebp
je 0x3374
andl $0xf100, %eax           # imm = 0xF100
cmpl $0x8100, %eax           # imm = 0x8100
jne 0x33a7
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0x8(%r12)
movl 0x40(%rsp), %edx
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2fab
jmp 0x33e2
leaq 0xfb1(%rip), %rdx       # 0x4315
leaq 0xfae(%rip), %rcx       # 0x4319
leaq 0xfb1(%rip), %r8        # 0x4323
jmp 0x33d3
andl $0xf040, %eax           # imm = 0xF040
cmpl $0x8040, %eax           # imm = 0x8040
jne 0x33be
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0xc(%r12)
leaq 0xa0(%rsp), %rsi
leaq 0x20a0(%rsp), %rdx
movl %ebx, %edi
callq 0x2e51
jmp 0x33e2
leaq 0xf9b(%rip), %rdx       # 0x4349
leaq 0xf98(%rip), %rcx       # 0x434d
leaq 0xf9b(%rip), %r8        # 0x4357
jmp 0x33d3
leaq 0xf84(%rip), %rdx       # 0x4349
leaq 0xf81(%rip), %rcx       # 0x434d
leaq 0xfaa(%rip), %r8        # 0x437d
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2b00
addq $0xe0b8, %rsp           # imm = 0xE0B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq