// File: /workspace/github_c_makefile_star2_O3/wtarreau[P]httpterm/httpterm.c
// Function: srv_return_page
static inline void srv_return_page(struct session *t) {
    int hlen;
    struct server *srv;

    srv = t->srv;

    if (t->req_code < 0)
	t->req_code = srv->resp_code;

    if (t->req_cache < 0)
	t->req_cache = srv->resp_cache;

    if (srv->resp_size < 0)
	srv->resp_size = 0;

    if (t->req_size < 0)
	t->req_size = srv->resp_size;

    if (t->req_time < 0)
	t->req_time = srv->resp_time;

    if (srv->resp_data) {
	t->rep->data = srv->resp_data;
	t->rep->l = srv->resp_size;
	t->rep->r = srv->resp_data + t->rep->l;
	t->rep->h = t->rep->lr = t->rep->w = t->rep->data;
	t->to_write = 0;
    }
    else {
	hlen  = 0;

	//hlen += snprintf(t->rep->data + hlen, BUFSIZE - hlen, "HTTP/1.1 %03d\r\n", t->req_code);
	memcpy(t->rep->data + hlen, "HTTP/1.1 000\r\n", 14);
	if (!(t->ka & 4)) // HTTP/1.0
	    t->rep->data[hlen+ 7] = '0';
	t->rep->data[hlen+ 9] = ((t->req_code / 100) % 10) + '0';
	t->rep->data[hlen+10] = ((t->req_code /  10) % 10) + '0';
	t->rep->data[hlen+11] = ((t->req_code /   1) % 10) + '0';
	hlen += 14;

	if ((t->ka & 5) == 1) { // HTTP/1.0 + KA
	    memcpy(t->rep->data + hlen, "Connection: keep-alive\r\n", 24);
	    hlen += 24;
	} else if ((t->ka & 5) == 4) { // HTTP/1.1 + close
	    memcpy(t->rep->data + hlen, "Connection: close\r\n", 19);
	    hlen += 19;
	}

	if (t->req_chunked) {
	    memcpy(t->rep->data + hlen, "Transfer-Encoding: chunked\r\n", 28);
	    hlen += 28;
	}
	else if (t->req_bodylen || (t->ka & 1)) {
	    memcpy(t->rep->data + hlen, "Content-length: ", 16); hlen += 16;
	    hlen += ulltoa((t->req_bodylen > 0) ? t->req_bodylen : t->req_size, t->rep->data + hlen, BUFSIZE - hlen);
	    memcpy(t->rep->data + hlen, "\r\n", 2); hlen += 2;
	}

	if (!t->req_cache) {
	    memcpy(t->rep->data + hlen, "Cache-Control: no-cache\r\n", 25);
	    hlen += 25;
	}

	if (t->etag) {
	    memcpy(t->rep->data + hlen, "Etag: ", 6); hlen += 6;
	    hlen += ulltox(t->etag, t->rep->data + hlen, BUFSIZE - hlen);
	    memcpy(t->rep->data + hlen, "\r\n", 2); hlen += 2;
	}

	if (t->req_verbose) {
	    memcpy(t->rep->data + hlen, "X-req: size=", 12); hlen += 12;
	    hlen += ulltoa(t->req->total, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, ", time=", 7); hlen += 7;
	    hlen += ulltoa(t->logs.t_request, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, "\r\nX-rsp: id=", 12); hlen += 12;
	    hlen += strlcpy2(t->rep->data + hlen, srv->id, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, ", code=", 7); hlen += 7;
	    hlen += ulltoa(t->req_code, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, ", cache=", 8); hlen += 8;
	    t->rep->data[hlen++] = '0' + !!t->req_cache;

	    if (t->req_chunked) {
		memcpy(t->rep->data + hlen, ", chunked", 9); hlen += 9;
	    }

	    memcpy(t->rep->data + hlen, ", size=", 7); hlen += 7;
	    hlen += ulltoa(t->req_size, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, ", time=", 7); hlen += 7;
	    hlen += ulltoa(t->req_time, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, " ms (", 5); hlen += 5;
	    hlen += ulltoa(t->logs.t_queue - t->logs.t_request, t->rep->data + hlen, BUFSIZE - hlen);

	    memcpy(t->rep->data + hlen, " real)\r\n", 8); hlen += 8;
	}
	/* final CRLF */
	memcpy(t->rep->data + hlen, "\r\n", 2); hlen += 2;

	//hlen += snprintf(t->rep->data + hlen, BUFSIZE - hlen,
	//		 "X-req: size=%ld, time=%ld ms\r\n"
	//		 "X-rsp: id=%s, code=%d, cache=%d,%s size=%lld, time=%d ms (%ld real)\r\n"
	//		 "\r\n",
	//		 (long)t->req->total, t->logs.t_request,
	//		 srv->id, t->req_code, t->req_cache,
	//		 t->req_chunked ? " chunked," : "",
	//		 t->req_size, t->req_time,
	//		 t->logs.t_queue - t->logs.t_request);
	t->to_write = t->req_size;
	t->rep->l = hlen;
	t->rep->r = t->rep->h = t->rep->lr = t->rep->w = t->rep->data;
	t->rep->r += hlen;
    }

    if (event_cli_write(t->cli_fd) < 0)
	my_fd_set(t->cli_fd, StaticWriteEvent);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xf0(%rdi), %r15
cmpl $0x0, 0x148(%rdi)
jns 0x58a4
movl 0x2c(%r15), %eax
movl %eax, 0x148(%rbx)
cmpl $0x0, 0x14c(%rbx)
jns 0x58b7
movl 0x34(%r15), %eax
movl %eax, 0x14c(%rbx)
movl 0x30(%r15), %eax
testl %eax, %eax
jns 0x58c9
movl $0x0, 0x30(%r15)
xorl %eax, %eax
cmpq $0x0, 0x128(%rbx)
movl %eax, %ecx
jns 0x58dc
movq %rcx, 0x128(%rbx)
cmpl $0x0, 0x150(%rbx)
jns 0x58ef
movl 0x28(%r15), %edx
movl %edx, 0x150(%rbx)
movq 0x38(%r15), %rdx
movq 0x60(%rbx), %rsi
testq %rdx, %rdx
je 0x5922
movq %rdx, 0x30(%rsi)
movl %eax, (%rsi)
addq %rdx, %rcx
movq %rcx, 0x8(%rsi)
movq %rdx, 0x10(%rsi)
movq %rdx, 0x20(%rsi)
movq %rdx, 0x18(%rsi)
movq $0x0, 0x68(%rbx)
jmp 0x5ec6
movq 0x30(%rsi), %rax
movabsq $0xa0d30303020312e, %rcx # imm = 0xA0D30303020312E
movq %rcx, 0x6(%rax)
movabsq $0x312e312f50545448, %rcx # imm = 0x312E312F50545448
movq %rcx, (%rax)
testb $0x4, 0x54(%rbx)
jne 0x5953
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movb $0x30, 0x7(%rax)
movslq 0x148(%rbx), %rax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addb $0x30, %al
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
movb %al, 0x9(%rcx)
movslq 0x148(%rbx), %rax
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addb $0x30, %al
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
movb %al, 0xa(%rcx)
movslq 0x148(%rbx), %rax
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
addb $0x30, %al
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
movb %al, 0xb(%rcx)
movl 0x54(%rbx), %eax
andl $0x5, %eax
cmpl $0x4, %eax
je 0x5a4b
movl $0xe, %r12d
cmpl $0x1, %eax
jne 0x5a6b
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movups 0x56eb(%rip), %xmm0     # 0xb11c
movups %xmm0, 0xe(%rax)
movabsq $0xa0d6576696c612d, %rcx # imm = 0xA0D6576696C612D
movq %rcx, 0x1e(%rax)
movl $0x26, %r12d
jmp 0x5a6b
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movups 0x56db(%rip), %xmm0     # 0xb135
movups %xmm0, 0xe(%rax)
movl $0xa0d6573, 0x1d(%rax)  # imm = 0xA0D6573
movl $0x21, %r12d
cmpl $0x0, 0x15c(%rbx)
je 0x5a9c
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movl %r12d, %ecx
movups 0x56cf(%rip), %xmm0     # 0xb155
movups %xmm0, 0xc(%rax,%rcx)
movups 0x56b7(%rip), %xmm0     # 0xb149
movups %xmm0, (%rax,%rcx)
addl $0x1c, %r12d
jmp 0x5b0d
cmpq $0x0, 0x140(%rbx)
jne 0x5aac
testb $0x1, 0x54(%rbx)
je 0x5b0d
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movl %r12d, %ecx
movups 0x56a8(%rip), %xmm0     # 0xb166
movups %xmm0, (%rax,%rcx)
orl $0x10, %r12d
movq 0x140(%rbx), %rdi
testq %rdi, %rdi
jg 0x5ad9
movq 0x128(%rbx), %rdi
movq 0x60(%rbx), %rax
movl %r12d, %esi
addq 0x30(%rax), %rsi
movl $0x1000, %edx           # imm = 0x1000
subl %r12d, %edx
callq 0x253c
leal (%rax,%r12), %ecx
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdx
movslq %ecx, %rcx
movw $0xa0d, (%rdx,%rcx)     # imm = 0xA0D
addl %eax, %r12d
addl $0x2, %r12d
cmpl $0x0, 0x14c(%rbx)
jne 0x5b3e
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movslq %r12d, %r12
movups 0x4f20(%rip), %xmm0     # 0xaa48
movups %xmm0, 0x9(%rax,%r12)
movups 0x4f0a(%rip), %xmm0     # 0xaa3f
movups %xmm0, (%rax,%r12)
addl $0x19, %r12d
cmpl $0x0, 0x11c(%rbx)
je 0x5ba8
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movslq %r12d, %r14
movw $0x203a, 0x4(%rax,%r14) # imm = 0x203A
movl $0x67617445, (%rax,%r14) # imm = 0x67617445
movl 0x11c(%rbx), %edi
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
leaq (%r14,%rax), %rsi
addq $0x6, %rsi
movl $0xffa, %eax            # imm = 0xFFA
subl %r14d, %eax
movslq %eax, %rdx
callq 0x27b8
leal (%r14,%rax), %ecx
addl $0x6, %ecx
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdx
movslq %ecx, %rcx
movw $0xa0d, (%rdx,%rcx)     # imm = 0xA0D
leal (%r14,%rax), %r12d
addl $0x8, %r12d
cmpl $0x0, 0x170(%rbx)
je 0x5e86
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movslq %r12d, %rbp
movabsq $0x73203a7165722d58, %rcx # imm = 0x73203A7165722D58
movq %rcx, (%rax,%rbp)
movl $0x3d657a69, 0x8(%rax,%rbp) # imm = 0x3D657A69
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rcx
movq 0x28(%rax), %rdi
movq 0x30(%rcx), %rax
leaq (%rax,%rbp), %rsi
addq $0xc, %rsi
movl $0xff4, %eax            # imm = 0xFF4
subl %ebp, %eax
movslq %eax, %rdx
callq 0x253c
movl %eax, %r14d
movl %ebp, %r13d
addl %eax, %r13d
leal (%r14,%rbp), %eax
addl $0xc, %eax
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
cltq
movl $0x3d656d69, 0x3(%rcx,%rax) # imm = 0x3D656D69
movl $0x6974202c, (%rcx,%rax) # imm = 0x6974202C
movq 0x60(%rbx), %rcx
movq 0x108(%rbx), %rdi
movq 0x30(%rcx), %rcx
leaq (%rax,%rcx), %rsi
addq $0x7, %rsi
movl $0xfed, %eax            # imm = 0xFED
subl %r13d, %eax
movslq %eax, %rdx
callq 0x253c
leal (%rax,%r13), %r8d
addl $0x13, %r8d
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
movslq %r8d, %r9
movabsq $0x3a7073722d580a0d, %rdx # imm = 0x3A7073722D580A0D
movq %rdx, (%rcx,%r9)
movl $0x3d646920, 0x8(%rcx,%r9) # imm = 0x3D646920
leal 0x1f(%rax,%r13), %ecx
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdi
movslq %ecx, %rdx
addq %rdi, %rdx
movq %rdx, %rsi
cmpl $0xff3, %r9d            # imm = 0xFF3
je 0x5ccc
movq %rdx, %rsi
cmpl $0xff4, %r8d            # imm = 0xFF4
je 0x5cd7
movq 0x8(%r15), %rdi
addl %r14d, %eax
addl %r12d, %eax
movl $0xfe0, %r8d            # imm = 0xFE0
subl %eax, %r8d
xorl %esi, %esi
movb (%rdi,%rsi), %al
movb %al, (%rdx,%rsi)
testb %al, %al
je 0x5cc9
incq %rsi
cmpl %esi, %r8d
jne 0x5cb7
addq %rdx, %rsi
movb $0x0, (%rsi)
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rdi
subl %edx, %esi
leal (%rcx,%rsi), %eax
movslq %eax, %r14
movl $0x3d65646f, 0x3(%rdi,%r14) # imm = 0x3D65646F
movl $0x6f63202c, (%rdi,%r14) # imm = 0x6F63202C
leal 0x7(%rcx,%rsi), %eax
movslq 0x148(%rbx), %rdi
movq 0x60(%rbx), %rcx
movslq %eax, %rsi
addq 0x30(%rcx), %rsi
movl $0xff9, %ebp            # imm = 0xFF9
movl $0xff9, %eax            # imm = 0xFF9
subl %r14d, %eax
movslq %eax, %rdx
callq 0x253c
leal (%rax,%r14), %ecx
addl $0x7, %ecx
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdx
movslq %ecx, %rsi
movabsq $0x3d6568636163202c, %rdi # imm = 0x3D6568636163202C
movq %rdi, (%rdx,%rsi)
cmpl $0x0, 0x14c(%rbx)
sete %dl
xorb $0x31, %dl
movq 0x60(%rbx), %rdi
movq 0x30(%rdi), %rdi
addl %r14d, %eax
addl $0x10, %eax
movb %dl, 0x8(%rdi,%rsi)
cmpl $0x0, 0x15c(%rbx)
je 0x5d85
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdx
cltq
movabsq $0x656b6e756863202c, %rsi # imm = 0x656B6E756863202C
movq %rsi, (%rdx,%rax)
movb $0x64, 0x8(%rdx,%rax)
addl $0x12, %ecx
movl %ecx, %eax
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
movslq %eax, %r14
movl $0x3d657a69, 0x3(%rcx,%r14) # imm = 0x3D657A69
movl $0x6973202c, (%rcx,%r14) # imm = 0x6973202C
movq 0x60(%rbx), %rax
movq 0x128(%rbx), %rdi
movq 0x30(%rax), %rax
leaq (%r14,%rax), %rsi
addq $0x7, %rsi
subl %r14d, %ebp
movslq %ebp, %rdx
callq 0x253c
leal (%r14,%rax), %r15d
addl %r14d, %eax
addl $0x7, %eax
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
cltq
movl $0x3d656d69, 0x3(%rcx,%rax) # imm = 0x3D656D69
movl $0x6974202c, (%rcx,%rax) # imm = 0x6974202C
movslq 0x150(%rbx), %rdi
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
leaq (%rax,%rcx), %rsi
addq $0x7, %rsi
movl $0xff2, %eax            # imm = 0xFF2
subl %r15d, %eax
movslq %eax, %rdx
callq 0x253c
leal (%rax,%r15), %r14d
addl $0x7, %r14d
leal 0xe(%rax,%r15), %eax
movq 0x60(%rbx), %rcx
movq 0x30(%rcx), %rcx
cltq
movb $0x28, 0x4(%rcx,%rax)
movl $0x20736d20, (%rcx,%rax) # imm = 0x20736D20
movq 0x60(%rbx), %rcx
movq 0x110(%rbx), %rdi
subq 0x108(%rbx), %rdi
movq 0x30(%rcx), %rcx
leaq (%rax,%rcx), %rsi
addq $0x5, %rsi
movl $0xff4, %eax            # imm = 0xFF4
subl %r14d, %eax
movslq %eax, %rdx
callq 0x253c
leal (%rax,%r14), %ecx
addl $0xc, %ecx
movq 0x60(%rbx), %rdx
movq 0x30(%rdx), %rdx
movslq %ecx, %rcx
movabsq $0xa0d296c61657220, %rsi # imm = 0xA0D296C61657220
movq %rsi, (%rdx,%rcx)
leal (%rax,%r14), %r12d
addl $0x14, %r12d
movq 0x60(%rbx), %rax
movq 0x30(%rax), %rax
movslq %r12d, %rcx
movw $0xa0d, (%rax,%rcx)     # imm = 0xA0D
leal 0x2(%rcx), %eax
movq 0x60(%rbx), %rdx
movq 0x128(%rbx), %rsi
movq %rsi, 0x68(%rbx)
movl %eax, (%rdx)
movq 0x30(%rdx), %rax
movq %rax, 0x10(%rdx)
movq %rax, 0x20(%rdx)
movq %rax, 0x18(%rdx)
addq %rcx, %rax
addq $0x2, %rax
movq %rax, 0x8(%rdx)
movl 0x48(%rbx), %edi
callq 0x35e8
testl %eax, %eax
jns 0x5eec
movl 0x48(%rbx), %ecx
movq 0x27544(%rip), %rax     # 0x2d420
movl $0x1, %edx
shll %cl, %edx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl %edx, (%rax,%rcx,4)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq