// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0d0, %rsp           # imm = 0xE0D0
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x4(%rbp), %esi
leaq -0xe0d0(%rbp), %rdi
callq 0x44b0
leaq -0x20c0(%rbp), %rsi
leaq -0xe0d0(%rbp), %rdi
movl $0x2000, %edx           # imm = 0x2000
callq 0x4530
leaq -0x20c0(%rbp), %rdi
leaq -0x40c0(%rbp), %rdx
leaq -0x60c0(%rbp), %rcx
leaq -0x80c0(%rbp), %r8
leaq 0x1c6d(%rip), %rsi      # 0x52b1
movb $0x0, %al
callq 0x2230
leaq -0x40c0(%rbp), %rsi
leaq -0x60c0(%rbp), %rdx
leaq -0x80c0(%rbp), %rcx
leaq 0x1c53(%rip), %rdi      # 0x52ba
movb $0x0, %al
callq 0x2110
leaq -0x40c0(%rbp), %rdi
leaq 0x1c48(%rip), %rsi      # 0x52c4
callq 0x2040
cmpl $0x0, %eax
je 0x36af
movl -0x4(%rbp), %edi
leaq -0x40c0(%rbp), %rsi
leaq 0x1c31(%rip), %rdx      # 0x52c8
leaq 0x1c2e(%rip), %rcx      # 0x52cc
leaq 0x1c37(%rip), %r8       # 0x52dc
callq 0x2c80
jmp 0x3812
leaq -0xe0d0(%rbp), %rdi
callq 0x2ef0
leaq -0x60c0(%rbp), %rdi
leaq -0xa0c0(%rbp), %rsi
leaq -0xc0c0(%rbp), %rdx
callq 0x2f50
movl %eax, -0x24(%rbp)
leaq -0xa0c0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x21e0
cmpl $0x0, %eax
jge 0x3719
movl -0x4(%rbp), %edi
leaq -0xa0c0(%rbp), %rsi
leaq 0x1c07(%rip), %rdx      # 0x5308
leaq 0x1c04(%rip), %rcx      # 0x530c
leaq 0x1c07(%rip), %r8       # 0x5316
callq 0x2c80
jmp 0x3812
cmpl $0x0, -0x24(%rbp)
je 0x379d
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x3741
movl -0xa0(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0x376a
movl -0x4(%rbp), %edi
leaq -0xa0c0(%rbp), %rsi
leaq 0x1bea(%rip), %rdx      # 0x533c
leaq 0x1be7(%rip), %rcx      # 0x5340
leaq 0x1bea(%rip), %r8       # 0x534a
callq 0x2c80
jmp 0x3812
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movl -0x4(%rbp), %edi
leaq -0xa0c0(%rbp), %rsi
movq -0x88(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x32d0
jmp 0x3812
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x37bd
movl -0xa0(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x37e3
movl -0x4(%rbp), %edi
leaq -0xa0c0(%rbp), %rsi
leaq 0x1b6e(%rip), %rdx      # 0x533c
leaq 0x1b6b(%rip), %rcx      # 0x5340
leaq 0x1b94(%rip), %r8       # 0x5370
callq 0x2c80
jmp 0x3812
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movl -0x4(%rbp), %edi
leaq -0xa0c0(%rbp), %rsi
leaq -0xc0c0(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x3100
addq $0xe0d0, %rsp           # imm = 0xE0D0
popq %rbp
retq
nopl (%rax,%rax)