// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/http.c
// Function: http_request_headers_serialize
int http_request_headers_serialize(/*write stream*/stream_t* s, http_request_t* req)
{
	struct dliterator_t it;
	const char* name;
	const char* value;
	int have_connection = FALSE;
	int have_host = FALSE;

	if (stream_appendf(s,
		"%s %s HTTP/1.1\r\n",
		req->method,
		req->path) == -1) {
		loge("stream_appendf() error\n");
		return -1;
	}

	dliterator_reset(&it);

	while (http_request_header_next(req, &it, &name, &value)) {
		if (stream_appendf(s, "%s: %s\r\n", name, value) == -1) {
			loge("stream_appendf() error\n");
			return -1;
		}
		if (strcmp(name, "Connection") == 0) {
			have_connection = TRUE;
		}
		else if (strcmp(name, "Host") == 0) {
			have_host = TRUE;
		}
	}

	if (!have_host) {
		if (stream_appendf(s, "Host: %s\r\n", req->host) == -1) {
			loge("stream_appendf() error\n");
			return -1;
		}
	}

	if (!have_connection) {
		if (stream_appendf(s, "Connection: %s\r\n",
			req->keep_alive ? "keep-alive" : "close") == -1) {
			loge("stream_appendf() error\n");
			return -1;
		}
	}

	if (strcmp(req->method, "POST") == 0) {
		if (stream_appendf(s, "Content-Length: %d\r\n\r\n", req->data_len) == -1) {
			loge("stream_appendf() error\n");
			return -1;
		}
	}
	else {
		if (stream_appends(s, "\r\n", 2) == -1) {
			loge("stream_appendf() error\n");
			return -1;
		}
	}

	return s->size - s->pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x188ab(%rip), %rsi     # 0x37463
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x1ec06
jmp 0x1ebc6
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1ebf8
movl $0x3, %edi
leaq 0x1883e(%rip), %rsi     # 0x3741c
leaq 0x1888f(%rip), %rdx     # 0x37474
movl $0x1d1, %ecx            # imm = 0x1D1
leaq 0x188a2(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1ebfa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
leaq -0x28(%rbp), %rdi
callq 0x1eeb0
movq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x1ea70
cmpl $0x0, %eax
je 0x1eccf
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1886b(%rip), %rsi     # 0x374ab
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x1ec8e
jmp 0x1ec4e
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1ec80
movl $0x3, %edi
leaq 0x187b6(%rip), %rsi     # 0x3741c
leaq 0x18807(%rip), %rdx     # 0x37474
movl $0x1d9, %ecx            # imm = 0x1D9
leaq 0x1881a(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1ec82
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
movq -0x30(%rbp), %rdi
leaq 0x187bf(%rip), %rsi     # 0x37458
callq 0x3500
cmpl $0x0, %eax
jne 0x1ecac
movl $0x1, -0x3c(%rbp)
jmp 0x1ecca
movq -0x30(%rbp), %rdi
leaq 0x1879c(%rip), %rsi     # 0x37453
callq 0x3500
cmpl $0x0, %eax
jne 0x1ecc8
movl $0x1, -0x40(%rbp)
jmp 0x1ecca
jmp 0x1ec0f
cmpl $0x0, -0x40(%rbp)
jne 0x1ed38
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x187cc(%rip), %rsi     # 0x374b4
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x1ed36
jmp 0x1ecf6
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1ed28
movl $0x3, %edi
leaq 0x1870e(%rip), %rsi     # 0x3741c
leaq 0x1875f(%rip), %rdx     # 0x37474
movl $0x1e6, %ecx            # imm = 0x1E6
leaq 0x18772(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1ed2a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
jmp 0x1ed38
cmpl $0x0, -0x3c(%rbp)
jne 0x1edb5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x34(%rax), %ecx
leaq 0x18eac(%rip), %rdx     # 0x37bfc
leaq 0x17348(%rip), %rax     # 0x3609f
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x1875a(%rip), %rsi     # 0x374bf
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x1edb3
jmp 0x1ed73
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1eda5
movl $0x3, %edi
leaq 0x18691(%rip), %rsi     # 0x3741c
leaq 0x186e2(%rip), %rdx     # 0x37474
movl $0x1ee, %ecx            # imm = 0x1EE
leaq 0x186f5(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1eda7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
jmp 0x1edb5
movq -0x18(%rbp), %rax
movq (%rax), %rdi
leaq 0x16648(%rip), %rsi     # 0x3540b
callq 0x3500
cmpl $0x0, %eax
jne 0x1ee2c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x186f1(%rip), %rsi     # 0x374d0
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x1ee2a
jmp 0x1eded
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1ee1f
movl $0x3, %edi
leaq 0x18617(%rip), %rsi     # 0x3741c
leaq 0x18668(%rip), %rdx     # 0x37474
movl $0x1f5, %ecx            # imm = 0x1F5
leaq 0x1867b(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1ee21
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
jmp 0x1ee87
movq -0x10(%rbp), %rdi
leaq 0x186ad(%rip), %rsi     # 0x374e4
movl $0x2, %edx
callq 0x2e140
cmpl $-0x1, %eax
jne 0x1ee85
jmp 0x1ee48
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1ee7a
movl $0x3, %edi
leaq 0x185bc(%rip), %rsi     # 0x3741c
leaq 0x1860d(%rip), %rdx     # 0x37474
movl $0x1fb, %ecx            # imm = 0x1FB
leaq 0x18620(%rip), %r8      # 0x37493
movb $0x0, %al
callq 0x243b0
jmp 0x1ee7c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1ee98
jmp 0x1ee87
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)