// File: /workspace/github_cpp_makefile_star2_O1/alfanick[P]rest-cpp/src/rest/response.cpp
// Function: REST::Response::stream(std::function<void (int)>, bool)
void Response::stream(std::function<void(int)> streamer, bool async) {
  is_streamed = true;

  std::string content = "HTTP/1.1 " + std::to_string(status) + " " + status_message + "\r\n";
  headers.emplace("Date", Utils::rfc1123_datetime(time(0)));

  // add headers
  for (auto header : headers)
    content += header.first + ": " + header.second + "\r\n";

  content += "\r\n";

  // send every byte
  ::send(handle, content.c_str(), content.size(), MSG_DONTWAIT | MSG_NOSIGNAL);

  if (async && streamers.capacity() > 0) {
    int h = handle;
    streamers.emplace_back([streamer, h]() {
      signal(SIGPIPE, SIG_IGN);
      try {
        // std::this_thread::yield();
        streamer(h);
        close(h);
      } catch (...) {
      }
    });
  } else {
    std::this_thread::yield();
    streamer(handle);
    close(handle);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edx, (%rsp)
movq %rsi, %r12
movq %rdi, %r13
movb $0x1, 0x9c(%rdi)
movl (%rdi), %r15d
movl %r15d, %ebx
negl %ebx
cmovsl %r15d, %ebx
movl $0x1, %ebp
cmpl $0xa, %ebx
jb 0x39915
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x3990e
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x39913
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x39915
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x398dd
addl $-0x3, %ebp
jmp 0x39915
addl $-0x2, %ebp
jmp 0x39915
decl %ebp
shrl $0x1f, %r15d
movl %r15d, %esi
addl %ebp, %esi
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movl $0x2d, %edx
callq 0x22520
movq (%r14), %rdi
addq %r15, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x22a70
leaq 0x7059(%rip), %rcx      # 0x409a8
movl $0x9, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22460
leaq 0x98(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x39991
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x3999a
vmovups (%rcx), %xmm0
vmovups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x88(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5740(%rip), %rsi      # 0x3f100
callq 0x233d0
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x399ec
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x399f4
vmovups (%rcx), %xmm0
vmovups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x68(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
callq 0x21440
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x39a44
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x39a4d
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x6f42(%rip), %rsi      # 0x409b2
callq 0x233d0
leaq 0xb8(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x39aa5
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x39aad
vmovups (%rcx), %xmm0
vmovups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0xb0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x39ad7
callq 0x22130
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39ae6
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39af8
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39b0c
callq 0x22130
xorl %edi, %edi
callq 0x22090
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x220f0
movq %r12, 0xc8(%rsp)
leaq 0x48(%r13), %rdi
leaq 0x6e82(%rip), %rsi      # 0x409b5
leaq 0x8(%rsp), %rdx
callq 0x216f0
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x39b4c
callq 0x22130
movq 0x60(%r13), %r15
movq %r13, 0xd0(%rsp)
leaq 0x50(%r13), %r14
cmpq %r14, %r15
je 0x39cea
leaq 0x48(%rsp), %r13
leaq 0xa8(%rsp), %r12
leaq 0x20(%r15), %rsi
leaq 0x8(%rsp), %rdi
callq 0x21f40
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x21600
movq %r13, %rdi
leaq 0x6e11(%rip), %rsi      # 0x409ba
callq 0x233d0
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r13, %rdi
callq 0x21440
movq %rbp, 0x88(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x39bec
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x39bf5
vmovups (%rcx), %xmm0
vmovups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x90(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x88(%rsp), %rdi
leaq 0x6d93(%rip), %rsi      # 0x409b2
callq 0x233d0
movq %rbx, 0x68(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x39c47
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x39c4f
vmovups (%rcx), %xmm0
vmovups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x70(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq %r12, %rdi
callq 0x21440
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39c88
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39c9a
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39cae
callq 0x22130
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x39cc2
callq 0x22130
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x39cd6
callq 0x22130
movq %r15, %rdi
callq 0x21be0
movq %rax, %r15
cmpq %r14, %rax
jne 0x39b72
leaq 0x6cc1(%rip), %rsi      # 0x409b2
leaq 0xa8(%rsp), %rdi
callq 0x233d0
movq 0xd0(%rsp), %r15
movl 0x98(%r15), %edi
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
movl $0x4040, %ecx           # imm = 0x4040
callq 0x217e0
cmpb $0x0, (%rsp)
movq 0xc8(%rsp), %r14
je 0x39d7e
movq 0x90(%r15), %rbx
movq 0x10(%rbx), %rax
cmpq (%rbx), %rax
je 0x39d7e
movl 0x98(%r15), %ebp
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x23520
movl %ebp, 0x28(%rsp)
movq 0x8(%rbx), %r14
cmpq 0x10(%rbx), %r14
je 0x39db6
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3ad5a
addq $0x8, 0x8(%rbx)
jmp 0x39e7e
callq 0x22b50
movl 0x98(%r15), %eax
movl %eax, 0x8(%rsp)
cmpq $0x0, 0x10(%r14)
je 0x39ec3
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq *0x18(%r14)
movl 0x98(%r15), %edi
callq 0x23470
jmp 0x39e97
leaq 0x4bc9(%rip), %rdx      # 0x3e986
movl $0x1, %esi
movq %rbx, %rdi
callq 0x22ec0
movq %rax, %rbp
movq (%rbx), %r13
movq 0x8(%rbx), %r15
testq %rax, %rax
movq %rax, (%rsp)
je 0x39def
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x22680
movq %rax, %r12
jmp 0x39df2
xorl %r12d, %r12d
movq %r14, %rax
subq %r13, %rax
sarq $0x3, %rax
leaq (%r12,%rax,8), %rbp
leaq 0x8(%rsp), %rsi
movq %rbp, %rdi
callq 0x3ad5a
movq %r12, %rbp
cmpq %r14, %r13
je 0x39e38
xorl %eax, %eax
movq %r12, %rbp
movq %r13, %rcx
movq %rax, (%rbp)
movq (%rcx), %rdx
movq %rdx, (%rbp)
movq %rax, (%rcx)
addq $0x8, %rcx
addq $0x8, %rbp
cmpq %r14, %rcx
jne 0x39e1d
addq $0x8, %rbp
cmpq %r14, %r15
je 0x39e5e
xorl %eax, %eax
movq %rax, (%rbp)
movq (%r14), %rcx
movq %rcx, (%rbp)
movq %rax, (%r14)
addq $0x8, %r14
addq $0x8, %rbp
cmpq %r15, %r14
jne 0x39e43
testq %r13, %r13
je 0x39e6b
movq %r13, %rdi
callq 0x22130
movq %r12, (%rbx)
movq %rbp, 0x8(%rbx)
movq (%rsp), %rax
leaq (%r12,%rax,8), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x39e97
leaq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x39eb1
callq 0x22130
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x21570
movq %rax, %rdi
callq 0x21630
testq %r12, %r12
jne 0x39ee1
cmpq $0x0, (%rbp)
je 0x39ee9
callq 0x213c0
movq %r12, %rdi
callq 0x22130
callq 0x22b40
movq %rax, %r14
callq 0x22ee0
jmp 0x39f04
jmp 0x39f26
jmp 0x39f26
jmp 0x39f9b
movq %rax, %r14
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x39ff3
leaq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x39ff3
movq %rax, %rdi
callq 0x249b5
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x39ff3
callq 0x22130
jmp 0x39ff3
jmp 0x39f9b
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x39f62
callq 0x22130
jmp 0x39f62
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39f76
callq 0x22130
jmp 0x39f76
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39f8d
callq 0x22130
jmp 0x39f8d
movq %rax, %r14
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
jmp 0x3a003
jmp 0x39f9b
movq %rax, %r14
jmp 0x39ff3
movq %rax, %r14
jmp 0x39fe9
jmp 0x39fa7
movq %rax, %r14
jmp 0x39fd5
movq %rax, %r14
jmp 0x39fc3
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39fc3
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39fd5
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39fe9
callq 0x22130
leaq 0x8(%rsp), %rdi
callq 0x21220
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x3a00d
callq 0x22130
movq %r14, %rdi
callq 0x23170
nop