// File: /workspace/github_c_makefile_star2_O1/agl[P]obstcp/libobstcp.c
// Function: obstcp_server_read
int EXPORTED
obstcp_server_read(struct obstcp_server_ctx *ctx,
                   struct iovec *outiov, unsigned *outlen, size_t *consumed,
                   struct obstcp_cursor *in) {
  *consumed = 0;

  if (ctx->state == SRV_ST_READING) {
    if (!cursor_has(in, 2)) {
      *outlen = 0;
      return 0;
    }

    uint8_t lenbuf[2];
    const uint8_t *lenbytes = cursor_read(lenbuf, in, 2);
    const uint16_t len = ntohs(*((uint16_t *) lenbytes));

    if (len > 384) {
      *outlen = 0;
      errno = EPROTO;
      return -1;
    }

    if (!cursor_has(in, len)) {
      *outlen = 0;
      return 0;
    }

    uint8_t bannerbuf[384];
    const uint8_t *banner = cursor_read(bannerbuf, in, len);
    const uint8_t *theirpublic = NULL, *nonce = NULL, *secret;
    uint8_t shared[32];
    uint32_t keyid = 0;

    if (!client_banner_parse(banner, len, &keyid, &theirpublic, &nonce)) {
      errno = EPROTO;
      return -1;
    }

    secret = keys_private_key_get(ctx->keys, keyid);
    if (!secret) {
      errno = ENOKEY;
      return -1;
    }

    curve25519(shared, secret, theirpublic);
    server_setup(ctx, shared, nonce);
    *consumed += 2 + len;
  }

  // we don't have any MACs yet, so this is easy.
  struct iovec_cursor out;
  iovec_cursor_init(&out, outiov, *outlen);

  iovec_cursor_copy_cursor(&out, in);

  *outlen = out.i;

  unsigned i;
  for (i = 0; i < out.i; ++i) {
    obs_encrypt(&ctx->u.b.in, outiov[i].iov_base, outiov[i].iov_base, outiov[i].iov_len);
    *consumed += outiov[i].iov_len;
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %r8, %r13
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq $0x0, (%rcx)
cmpl $0x0, 0x190(%rdi)
je 0x1ee5
movl (%rdx), %eax
leaq 0x1881(%rip), %rcx      # 0x36ec
leaq 0xc0(%rsp), %rbp
movq %rcx, (%rbp)
leaq 0x18c5(%rip), %rcx      # 0x3743
movq %rcx, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movl %eax, 0x18(%rbp)
movl $0x0, 0x1c(%rbp)
movq $0x0, 0x20(%rbp)
movq %rbp, %rdi
movq %r13, %rsi
movq %rdx, %r12
callq 0x24ed
movl 0x1c(%rbp), %r13d
movl %r13d, (%r12)
testq %r13, %r13
je 0x1f25
addq $0x8, %r15
shlq $0x4, %r13
xorl %r12d, %r12d
movq (%r14,%r12), %rdx
movq 0x8(%r14,%r12), %rcx
movq %r15, %rdi
movq %rdx, %rsi
callq 0x254f
movq 0x8(%r14,%r12), %rax
addq %rax, (%rbx)
addq $0x10, %r12
cmpq %r12, %r13
jne 0x1ebe
jmp 0x1f25
movq %rdx, 0x18(%rsp)
leaq 0xc0(%rsp), %rbp
movq $0x2, (%rbp)
movq $0x0, 0x8(%rbp)
leaq 0x17d2(%rip), %rsi      # 0x36db
movq %r13, %rdi
movq %rbp, %rdx
callq *0x8(%r13)
cmpq $0x1, 0x8(%rbp)
ja 0x1f39
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
xorl %eax, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36(%rsp), %rdi
movl $0x2, %edx
movq %r13, %rsi
callq 0x246c
movzwl (%rax), %r12d
movl %r12d, %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl $0x181, %eax            # imm = 0x181
jb 0x1f87
movq 0x18(%rsp), %r12
movl $0x0, (%r12)
callq 0x1050
movq %r12, %rdx
movl $0x47, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
jmp 0x245f
movq %r13, %rbp
movq %rax, 0x10(%rsp)
movl %eax, %r13d
leaq 0xc0(%rsp), %rdx
movq %r13, (%rdx)
movq $0x0, 0x8(%rdx)
leaq 0x172f(%rip), %rsi      # 0x36db
movq %rbp, %rdi
callq *0x8(%rbp)
leaq 0xc0(%rsp), %rax
cmpq %r13, 0x8(%rax)
jae 0x1fd7
movq 0x18(%rsp), %rdx
movl $0x0, (%rdx)
xorl %ecx, %ecx
xorl %eax, %eax
movq %rbp, %r13
jmp 0x245f
leaq 0xc0(%rsp), %rdi
movq %rbp, %rsi
movq %r13, 0x50(%rsp)
movq %r13, %rdx
callq 0x246c
movb $0x1, 0xb(%rsp)
testw %r12w, %r12w
movq %rbp, %r13
je 0x22f3
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0xc(%rsp)
negl %ecx
movslq %ecx, %rcx
decq %rcx
movq %rcx, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r10d, %r10d
leal 0x3(%r10), %ebp
movl %r10d, %ecx
leaq (%rax,%rcx), %rdx
addq 0x58(%rsp), %rcx
xorl %r8d, %r8d
xorl %esi, %esi
movq %r8, %r11
movl %ecx, %edi
addl %r11d, %edi
je 0x209a
movl %esi, %edi
shll $0x7, %edi
movzbl (%rdx,%r11), %r12d
movl %r12d, %esi
andl $0x7f, %esi
orl %edi, %esi
cmpl $0x3, %r11d
je 0x20a3
leaq 0x1(%r11), %r8
testb %r12b, %r12b
js 0x2067
addl %r10d, %r8d
movl %r8d, %ebp
jmp 0x20a3
movl 0xc(%rsp), %ecx
movl %ecx, %ebp
movl %r9d, %esi
addl %r11d, %r10d
cmpl 0x10(%rsp), %r10d
ja 0x22ed
movl %esi, %ecx
shrl %ecx
cmpl $0x2, %ecx
je 0x21a8
cmpl $0x1, %ecx
je 0x213a
testl %ecx, %ecx
jne 0x22ed
testb $0x1, %sil
je 0x22ed
movl 0xc(%rsp), %ecx
cmpl %ecx, %ebp
cmoval %ebp, %ecx
leal 0x3(%rbp), %r8d
movl %ebp, %edi
leaq (%rax,%rdi), %rdx
movl %ecx, %r11d
negl %r11d
addq %rdi, %r11
xorl %r12d, %r12d
xorl %r9d, %r9d
movq %r12, %r10
movl %r11d, %edi
addl %r10d, %edi
je 0x221a
movl %r9d, %r12d
shll $0x7, %r12d
movzbl (%rdx,%r10), %edi
movl %edi, %r9d
andl $0x7f, %r9d
orl %r12d, %r9d
cmpl $0x3, %r10d
je 0x2263
leaq 0x1(%r10), %r12
testb %dil, %dil
js 0x20f7
addl %ebp, %r12d
movl %r12d, %ecx
jmp 0x2266
testb $0x1, %sil
je 0x22ed
movl 0xc(%rsp), %ecx
cmpl %ecx, %ebp
movl %ecx, %r11d
cmoval %ebp, %r11d
leal 0x3(%rbp), %r8d
movl %ebp, %edi
leaq (%rax,%rdi), %rdx
movl %r11d, %ecx
negl %ecx
addq %rdi, %rcx
xorl %r12d, %r12d
xorl %r9d, %r9d
movq %r12, %r10
movl %ecx, %edi
addl %r10d, %edi
je 0x2215
movl %r9d, %r12d
shll $0x7, %r12d
movzbl (%rdx,%r10), %edi
movl %edi, %r9d
andl $0x7f, %r9d
orl %r12d, %r9d
cmpl $0x3, %r10d
je 0x2224
leaq 0x1(%r10), %r12
testb %dil, %dil
js 0x2169
addl %ebp, %r12d
movl %r12d, %r11d
jmp 0x2227
testb $0x1, %sil
je 0x22ed
movl 0xc(%rsp), %ecx
cmpl %ecx, %ebp
movl %ecx, %r11d
cmoval %ebp, %r11d
leal 0x3(%rbp), %r8d
movl %ebp, %edi
leaq (%rax,%rdi), %rdx
movl %r11d, %ecx
negl %ecx
addq %rdi, %rcx
xorl %r12d, %r12d
xorl %r9d, %r9d
movq %r12, %r10
movl %ecx, %edi
addl %r10d, %edi
je 0x221f
movl %r9d, %r12d
shll $0x7, %r12d
movzbl (%rdx,%r10), %edi
movl %edi, %r9d
andl $0x7f, %r9d
orl %r12d, %r9d
cmpl $0x3, %r10d
je 0x2294
leaq 0x1(%r10), %r12
testb %dil, %dil
js 0x21d7
addl %ebp, %r12d
movl %r12d, %r11d
jmp 0x2297
movl %esi, %r9d
jmp 0x2227
movl %esi, %r9d
jmp 0x2266
movl %esi, %r9d
jmp 0x2297
movl %r8d, %r11d
addl %r10d, %ebp
movq 0x10(%rsp), %rdx
cmpl %edx, %ebp
ja 0x22ed
cmpl $0x4, %r9d
jne 0x22ed
leal 0x4(%r11), %r10d
cmpl %edx, %r10d
ja 0x22ed
movl %r11d, %ecx
movl (%rax,%rcx), %ecx
bswapl %ecx
movl %ecx, 0x4(%rsp)
movb $0x1, %cl
movq %rcx, 0x38(%rsp)
jmp 0x22c4
movl %r8d, %ecx
addl %r10d, %ebp
movq 0x10(%rsp), %rdx
cmpl %edx, %ebp
ja 0x22ed
cmpl $0x20, %r9d
jne 0x22ed
leal 0x20(%rcx), %r10d
cmpl %edx, %r10d
ja 0x22ed
movl %ecx, %ecx
addq %rax, %rcx
movq %rcx, 0x20(%rsp)
movb $0x1, %cl
movq %rcx, 0x40(%rsp)
jmp 0x22c4
movl %r8d, %r11d
addl %r10d, %ebp
movq 0x10(%rsp), %rdx
cmpl %edx, %ebp
ja 0x22ed
cmpl $0x10, %r9d
jne 0x22ed
leal 0x10(%r11), %r10d
cmpl %edx, %r10d
ja 0x22ed
movl %r11d, %ecx
addq %rax, %rcx
movq %rcx, 0x28(%rsp)
movb $0x1, %cl
movq %rcx, 0x48(%rsp)
cmpl %edx, %r10d
jne 0x2052
cmpb $0x0, 0x38(%rsp)
sete %al
cmpb $0x0, 0x40(%rsp)
sete %cl
orb %al, %cl
cmpb $0x0, 0x48(%rsp)
sete %al
orb %cl, %al
movb %al, 0xb(%rsp)
movl 0x4(%rsp), %eax
jmp 0x2307
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
xorl %eax, %eax
cmpb $0x0, 0xb(%rsp)
je 0x231e
callq 0x1050
movl $0x47, (%rax)
jmp 0x2453
movl %eax, %ecx
movq (%r15), %rax
movq (%rax), %rsi
testq %rsi, %rsi
je 0x233b
movl %ecx, %eax
cmpl %eax, 0x40(%rsi)
je 0x233d
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
jne 0x232d
xorl %esi, %esi
testq %rsi, %rsi
je 0x2448
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %rdx
callq 0x5c0c
leaq 0x248(%rsp), %rbp
movq %rbp, %rdi
callq 0x3d68
movq %rbp, %rdi
movq %r12, %rsi
movl $0x20, %edx
callq 0x3d8d
movq %rbp, %rdi
movq 0x28(%rsp), %rsi
movl $0x10, %edx
callq 0x3d8d
leaq 0xa0(%rsp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5a16
movq %rbp, %rdi
callq 0x3d68
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
movl $0x20, %edx
callq 0x3d8d
movq %rbp, %rdi
movq %r12, %rsi
movl $0x20, %edx
callq 0x3d8d
leaq 0x80(%rsp), %rsi
movq %rbp, %rdi
movq %rsi, %rbp
callq 0x5a16
movl $0x1, 0x190(%r15)
leaq 0x8(%r15), %rdi
movl $0xe8, %edx
xorl %esi, %esi
callq 0x1080
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
movups %xmm0, 0x4c(%r15)
movups %xmm1, 0x5c(%r15)
movaps (%rbp), %xmm0
movaps 0x10(%rbp), %xmm1
movups %xmm0, 0xc0(%r15)
movups %xmm1, 0xd0(%r15)
movl $0x40, %eax
movl %eax, 0x48(%r15)
movl %eax, 0xbc(%r15)
movq (%rbx), %rax
movq 0x50(%rsp), %rcx
addq %rcx, %rax
addq $0x2, %rax
movq %rax, (%rbx)
movb $0x1, %cl
jmp 0x2455
callq 0x1050
movl $0x7e, (%rax)
xorl %ecx, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rdx
testb %cl, %cl
jne 0x1e62
jmp 0x1f27