// File: /workspace/github_cpp_makefile_star2_O3/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
movb $0x1, 0x9c(%rdi)
movl $0x1, %ebp
movl %edx, (%rsp)
movq %rsi, %r12
movq %rdi, %r13
movl (%rdi), %r15d
movl %r15d, %ebx
negl %ebx
cmovsl %r15d, %ebx
cmpl $0xa, %ebx
jb 0x3973b
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x39734
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x39739
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x3973b
movl %ecx, %edx
imulq %rax, %rdx
addl $0x4, %ebp
shrq $0x2d, %rdx
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x39703
addl $-0x3, %ebp
jmp 0x3973b
addl $-0x2, %ebp
jmp 0x3973b
decl %ebp
shrl $0x1f, %r15d
leaq 0x58(%rsp), %rax
leaq 0x48(%rsp), %r14
movl $0x2d, %edx
movl %r15d, %esi
addl %ebp, %esi
movq %r14, %rdi
movq %rax, -0x10(%rax)
callq 0x22520
movq (%r14), %rdi
movl %ebp, %esi
movl %ebx, %edx
addq %r15, %rdi
callq 0x22a70
leaq 0x6233(%rip), %rcx      # 0x3f9a8
movl $0x9, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22460
leaq 0x98(%rsp), %rbp
movq %rax, %rcx
addq $0x10, %rcx
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x397b7
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x397c0
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 0x491a(%rip), %rsi      # 0x3e100
callq 0x233c0
leaq 0x78(%rsp), %rbx
movq %rax, %rcx
addq $0x10, %rcx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x39812
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x3981a
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 0x10(%r13), %rdx
movq 0x8(%r13), %rsi
callq 0x21440
leaq 0x18(%rsp), %r15
movq %rax, %rcx
addq $0x10, %rcx
movq %r15, -0x10(%r15)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x3986a
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x39873
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 0x611c(%rip), %rsi      # 0x3f9b2
callq 0x233c0
leaq 0xb8(%rsp), %rsi
movq %rax, %rcx
addq $0x10, %rcx
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x398cb
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x398d3
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 0x398fd
callq 0x22130
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3990c
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3991e
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39932
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 0x605c(%rip), %rsi      # 0x3f9b5
leaq 0x8(%rsp), %rdx
callq 0x216f0
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x39972
callq 0x22130
movq 0x60(%r13), %r15
leaq 0x50(%r13), %r14
movq %r13, 0xd0(%rsp)
cmpq %r14, %r15
je 0x39b10
leaq 0x48(%rsp), %r13
leaq 0xa8(%rsp), %r12
leaq 0x20(%r15), %rsi
leaq 0x8(%rsp), %rdi
callq 0x21f40
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
addq %rsi, %rdx
movq %r13, %rdi
callq 0x21600
leaq 0x5fee(%rip), %rsi      # 0x3f9ba
movq %r13, %rdi
callq 0x233c0
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x21440
movq %rbp, 0x88(%rsp)
movq %rax, %rcx
addq $0x10, %rcx
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x39a12
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x39a1b
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 0x5f6d(%rip), %rsi      # 0x3f9b2
callq 0x233c0
movq %rbx, 0x68(%rsp)
movq %rax, %rcx
addq $0x10, %rcx
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x39a6d
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x39a75
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 0x70(%rsp), %rdx
movq 0x68(%rsp), %rsi
movq %r12, %rdi
callq 0x21440
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39aae
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39ac0
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39ad4
callq 0x22130
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x39ae8
callq 0x22130
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x39afc
callq 0x22130
movq %r15, %rdi
callq 0x21be0
movq %rax, %r15
cmpq %r14, %rax
jne 0x39998
leaq 0x5e9b(%rip), %rsi      # 0x3f9b2
leaq 0xa8(%rsp), %rdi
callq 0x233c0
movq 0xd0(%rsp), %r15
movq 0xb0(%rsp), %rdx
movl 0x98(%r15), %edi
movq 0xa8(%rsp), %rsi
movl $0x4040, %ecx           # imm = 0x4040
callq 0x217e0
cmpb $0x0, (%rsp)
movq 0xc8(%rsp), %r14
je 0x39ba4
movq 0x90(%r15), %rbx
movq 0x10(%rbx), %rax
cmpq (%rbx), %rax
je 0x39ba4
movl 0x98(%r15), %ebp
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x23500
movl %ebp, 0x28(%rsp)
movq 0x8(%rbx), %r14
cmpq 0x10(%rbx), %r14
je 0x39bdc
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3ab7c
addq $0x8, 0x8(%rbx)
jmp 0x39ca0
callq 0x22b50
movl 0x98(%r15), %eax
movl %eax, 0x8(%rsp)
cmpq $0x0, 0x10(%r14)
je 0x39ce5
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq *0x18(%r14)
movl 0x98(%r15), %edi
callq 0x23460
jmp 0x39cb9
leaq 0x3da3(%rip), %rdx      # 0x3d986
movl $0x1, %esi
movq %rbx, %rdi
callq 0x22ec0
movq (%rbx), %r13
movq 0x8(%rbx), %r15
movq %rax, %rbp
movq %rax, (%rsp)
testq %rax, %rax
je 0x39c15
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x22680
movq %rax, %r12
jmp 0x39c18
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 0x3ab7c
movq %r12, %rbp
cmpq %r14, %r13
je 0x39c5c
movq %r12, %rbp
movq %r13, %rax
movq (%rax), %rcx
movq %rcx, (%rbp)
movq $0x0, (%rax)
addq $0x8, %rax
addq $0x8, %rbp
cmpq %r14, %rax
jne 0x39c41
addq $0x8, %rbp
cmpq %r14, %r15
je 0x39c80
movq (%r14), %rax
movq %rax, (%rbp)
movq $0x0, (%r14)
addq $0x8, %r14
addq $0x8, %rbp
cmpq %r15, %r14
jne 0x39c65
testq %r13, %r13
je 0x39c8d
movq %r13, %rdi
callq 0x22130
movq (%rsp), %rax
movq %r12, (%rbx)
movq %rbp, 0x8(%rbx)
leaq (%r12,%rax,8), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x39cb9
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x39cd3
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 0x39d03
cmpq $0x0, (%rbp)
je 0x39d0b
callq 0x213c0
movq %r12, %rdi
callq 0x22130
callq 0x22b40
movq %rax, %r14
callq 0x22ee0
jmp 0x39d26
jmp 0x39d48
jmp 0x39d48
jmp 0x39dbd
movq %rax, %r14
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x39e15
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
jmp 0x39e15
movq %rax, %rdi
callq 0x24985
movq 0x8(%rsp), %rdi
movq %rax, %r14
cmpq %r15, %rdi
je 0x39e15
callq 0x22130
jmp 0x39e15
jmp 0x39dbd
movq 0x8(%rsp), %rdi
movq %rax, %r14
cmpq %r15, %rdi
je 0x39d84
callq 0x22130
jmp 0x39d84
movq %rax, %r14
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39d98
callq 0x22130
jmp 0x39d98
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39daf
callq 0x22130
jmp 0x39daf
movq %rax, %r14
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
jmp 0x39e25
jmp 0x39dbd
movq %rax, %r14
jmp 0x39e15
movq %rax, %r14
jmp 0x39e0b
jmp 0x39dc9
movq %rax, %r14
jmp 0x39df7
movq %rax, %r14
jmp 0x39de5
movq 0x68(%rsp), %rdi
movq %rax, %r14
cmpq %rbx, %rdi
je 0x39de5
callq 0x22130
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x39df7
callq 0x22130
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x39e0b
callq 0x22130
leaq 0x8(%rsp), %rdi
callq 0x21220
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x39e2f
callq 0x22130
movq %r14, %rdi
callq 0x23160
nop