// File: /workspace/github_c_makefile_star2_O3/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 0x3a23
leaq 0xc0b0(%rsp), %rbp
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3a4e
leaq 0x1042(%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 0x1019(%rip), %rdi      # 0x42c7
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2110
leaq 0x100c(%rip), %rsi      # 0x42d1
movq %r13, %rdi
callq 0x2040
testl %eax, %eax
je 0x32f3
leaq 0xffd(%rip), %rdx       # 0x42d5
leaq 0xffa(%rip), %rcx       # 0x42d9
leaq 0x1003(%rip), %r8       # 0x42e9
leaq 0x60a0(%rsp), %rsi
jmp 0x33f7
movq %r14, %r13
movq (%rsp), %r12
movq 0x8(%rsp), %r14
leaq 0x80a0(%rsp), %rdi
callq 0x2cb5
leaq 0x40a0(%rsp), %rdi
leaq 0xa0(%rsp), %r15
leaq 0x20a0(%rsp), %rdx
movq %r15, %rsi
callq 0x2d15
movl %eax, %ebp
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x21c0
testl %eax, %eax
js 0x3379
movl 0x28(%rsp), %eax
testl %ebp, %ebp
je 0x3390
andl $0xf100, %eax           # imm = 0xF100
cmpl $0x8100, %eax           # imm = 0x8100
jne 0x33c3
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0x8(%r12)
movl 0x40(%rsp), %edx
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2fc7
jmp 0x33fe
leaq 0xf95(%rip), %rdx       # 0x4315
leaq 0xf92(%rip), %rcx       # 0x4319
leaq 0xf95(%rip), %r8        # 0x4323
jmp 0x33ef
andl $0xf040, %eax           # imm = 0xF040
cmpl $0x8040, %eax           # imm = 0x8040
jne 0x33da
movq %r14, %r8
movq %r12, %r9
movq %r13, %rcx
incl 0xc(%r12)
leaq 0xa0(%rsp), %rsi
leaq 0x20a0(%rsp), %rdx
movl %ebx, %edi
callq 0x2e6d
jmp 0x33fe
leaq 0xf7f(%rip), %rdx       # 0x4349
leaq 0xf7c(%rip), %rcx       # 0x434d
leaq 0xf7f(%rip), %r8        # 0x4357
jmp 0x33ef
leaq 0xf68(%rip), %rdx       # 0x4349
leaq 0xf65(%rip), %rcx       # 0x434d
leaq 0xf8e(%rip), %r8        # 0x437d
leaq 0xa0(%rsp), %rsi
movl %ebx, %edi
callq 0x2b1c
addq $0xe0b8, %rsp           # imm = 0xE0B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq