// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/http_request.c
// Function: parse_request_head
void parse_request_head(char *http_request_line, struct http_request *http_request)
{
    char *p, *head, *m, *u;
    size_t head_len;
    int host_len, port_len, uri_len;
    host_len = port_len = uri_len = 0;

    p = strstr(http_request_line, "\r\n"); // 查找"\r\n"
    if (p == NULL) {
        return;
    }

    head_len = p - http_request_line;
    head = (char *)malloc(sizeof(char) * head_len + 1);
    if (head == NULL)
        free(head);
    memset(head, 0, sizeof(char) * head_len + 1);
    memcpy(head, http_request_line, head_len);

    http_request->method = (char *)malloc(sizeof(char) * 8);
    http_request->U = (char *)malloc(sizeof(char) * head_len);
    http_request->version = (char *)malloc(10);
    if (http_request->method == NULL)
        perror("malloc");
    if (http_request->U == NULL)
        perror("malloc");
    if (http_request->version == NULL)
        perror("malloc");
    memset(http_request->method, 0, 8);
    memset(http_request->U, 0, sizeof(char) * head_len);
    memset(http_request->version, 0, 10);

    m = strchr(head, ' ');
    http_request->method_len = m - head;
    memmove(http_request->method, head, http_request->method_len);

    u = strchr(m + 1, ' ');
    memmove(http_request->U, m + 1, u - (m + 1));
    http_request->U_len = u - (m + 1);

    memmove(http_request->version, u + 1, 8);
    http_request->version_len = 8;

    // 获取Host、Port长度
    get_http_host_port_len(http_request_line, &host_len, &port_len);

    // URI LENGTH
    char *_p0 = strstr(http_request->U, "http://");
    if (_p0) {                  // 标准头
        char *_p1 = strchr(http_request->U + 7, '/');
        char *_p2 = strchr(http_request->U + 7, '\0');
        if (_p1) {
            uri_len = _p2 - _p1;
        }
    } else {                    // 非标准头
        char *_p1 = strchr(http_request->U, '/');
        char *_p2 = strchr(http_request->U, '\0');
        if (_p1) {
            uri_len = _p2 - _p1;
        } else {
            uri_len = 1;        // 没有uri时
        }
    }

    http_request->host = (char *)malloc(sizeof(char) * host_len + 1);
    if (http_request->host == NULL)
        perror("malloc");
    http_request->port = (char *)malloc(sizeof(char) * port_len + 1);
    if (http_request->port == NULL)
        perror("malloc");
    http_request->url = (char *)malloc(sizeof(char) * http_request->U_len + 1);
    if (http_request->url == NULL)
        perror("malloc");
    http_request->uri = (char *)malloc(sizeof(char) * uri_len + 1);
    if (http_request->uri == NULL)
        perror("malloc");
    http_request->H = (char *)malloc(sizeof(char) * host_len + port_len + 1);
    if (http_request->H == NULL)
        perror("malloc");

    memset(http_request->host, 0, host_len + 1);
    memset(http_request->port, 0, port_len + 1);
    memset(http_request->url, 0, http_request->U_len + 1);
    memset(http_request->uri, 0, uri_len + 1);
    memset(http_request->H, 0, host_len + port_len + 1);
    if (extract_host(http_request_line, http_request->host, http_request->port) == -1)
        return;
    http_request->host_len = (int)strlen(http_request->host);
    http_request->port_len = (int)strlen(http_request->port);
    memcpy(http_request->H, http_request->host, http_request->host_len);
    strncat(http_request->H, ":", 2);
    strncat(http_request->H, http_request->port, http_request->port_len);
    memcpy(http_request->url, http_request->U, http_request->U_len);
    http_request->url_len = http_request->U_len;
    if (get_http_path(http_request->url, http_request->url_len, http_request->uri) == NULL)
        return;

    http_request->uri_len = uri_len;
    http_request->H_len = http_request->host_len + http_request->port_len + 1;

/* 
   // 调试
   printf("%s %d\n", http_request->method, http_request->method_len);
   printf("%s %d\n", http_request->U, http_request->U_len);
   printf("%s %d\n", http_request->version, http_request->version_len);
   printf("%s %d\n", http_request->host, http_request->host_len);
   printf("%s %d\n", http_request->port, http_request->port_len);
   printf("%s %d\n", http_request->H, http_request->H_len);
   printf("%s %d\n", http_request->url, http_request->url_len);
   printf("%s %d\n", http_request->uri, http_request->uri_len);
*/

    free(head);
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x68b2(%rip), %rsi      # 0xc432
callq 0x2570
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5b95
jmp 0x60cb
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
shlq $0x0, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5bc9
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rdx
shlq $0x0, %rdx
addq $0x1, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x2300
movl $0x8, %edi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
shlq $0x0, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0xa, %edi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x5c48
leaq 0x67f2(%rip), %rdi      # 0xc435
callq 0x2480
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x5c5f
leaq 0x67db(%rip), %rdi      # 0xc435
callq 0x2480
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x5c76
leaq 0x67c4(%rip), %rdi      # 0xc435
callq 0x2480
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21c0
movq -0x20(%rbp), %rdi
movl $0x20, %esi
callq 0x2170
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rdx
callq 0x2450
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
movl $0x20, %esi
callq 0x2170
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x1, %rsi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
addq $0x1, %rax
subq %rax, %rdx
callq 0x2450
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl $0x8, 0x48(%rax)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x5870
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x66b7(%rip), %rsi      # 0xc43c
callq 0x2570
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x5ddd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x7, %rdi
movl $0x2f, %esi
callq 0x2170
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x7, %rdi
xorl %esi, %esi
callq 0x2170
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x5ddb
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x44(%rbp)
jmp 0x5e26
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x2f, %esi
callq 0x2170
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x2170
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x5e1d
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x44(%rbp)
jmp 0x5e24
movl $0x1, -0x44(%rbp)
jmp 0x5e26
movslq -0x3c(%rbp), %rdi
shlq $0x0, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5e59
leaq 0x65e1(%rip), %rdi      # 0xc435
callq 0x2480
movslq -0x40(%rbp), %rdi
shlq $0x0, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x5e8c
leaq 0x65ae(%rip), %rdi      # 0xc435
callq 0x2480
movq -0x10(%rbp), %rax
movslq 0x44(%rax), %rdi
shlq $0x0, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x5ec3
leaq 0x6577(%rip), %rdi      # 0xc435
callq 0x2480
movslq -0x44(%rbp), %rdi
shlq $0x0, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x5ef6
leaq 0x6544(%rip), %rdi      # 0xc435
callq 0x2480
movslq -0x3c(%rbp), %rdi
shlq $0x0, %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x5f30
leaq 0x650a(%rip), %rdi      # 0xc435
callq 0x2480
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x40(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x4fd0
cmpl $-0x1, %eax
jne 0x5fd2
jmp 0x60cb
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2130
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2130
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x4c(%rax), %rdx
callq 0x2300
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
leaq 0x622b(%rip), %rsi      # 0xc255
movl $0x2, %edx
callq 0x21f0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rdx
callq 0x21f0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x44(%rax), %rdx
callq 0x2300
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
callq 0x57b0
cmpq $0x0, %rax
jne 0x60a0
jmp 0x60cb
movl -0x44(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x50(%rax), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x20(%rbp), %rdi
callq 0x2030
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)