// File: /workspace/github_c_makefile_star2_O3/agl[P]obstcp/libobstcp.c
// Function: obstcp_client_ctx_init
int EXPORTED
obstcp_client_ctx_init(struct obstcp_client_ctx *ctx, struct obstcp_keys *keys,
                       const char *advert, unsigned len, const uint8_t *random) {
  uint8_t serverpublic[32], shared[32], in_key[32], out_key[32];
  struct sha256_ctx sha;

  if (!keys->keys) {
    errno = EINVAL;
    return 0;
  }

  if (!client_parse_advert(serverpublic, advert, len)) {
    errno = EINVAL;
    return 0;
  }

  curve25519(shared, keys->keys->private_key, serverpublic);

  sha256_init(&sha);
  sha256_update(&sha, shared, 32);
  sha256_update(&sha, random, 16);
  sha256_final(&sha, out_key);

  sha256_init(&sha);
  sha256_update(&sha, shared, 32);
  sha256_update(&sha, out_key, 32);
  sha256_final(&sha, in_key);

  memset(ctx, 0, sizeof(struct obstcp_client_ctx));

  memcpy(ctx->in.key, in_key, 32);
  memcpy(ctx->out.key, out_key, 32);

  ctx->in.used = 64;
  ctx->out.used = 64;

  ctx->state = CLI_ST_WRITING;

  ctx->n = client_write_banner(ctx->buffer, sizeof(ctx->buffer),
                               keys->keys, random, serverpublic);

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
cmpq $0x0, (%rsi)
je 0x2544
movq %r8, %r14
movl %ecx, %r12d
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
movl %ecx, %edi
callq 0x5794
cmpl $0x180, %eax            # imm = 0x180
jbe 0x2563
callq 0x1050
movl $0x16, (%rax)
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebp
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x579b
testl %ebp, %ebp
je 0x2544
testl %eax, %eax
je 0x2544
xorl %edx, %edx
movb $0x1, %cl
leal 0x3(%rdx), %eax
xorl %esi, %esi
xorl %edi, %edi
leal (%rdx,%rdi), %r8d
cmpl %ebp, %r8d
ja 0x2544
shll $0x7, %esi
movl %r8d, %r8d
movzbl 0x80(%rsp,%r8), %r9d
movl %r9d, %r8d
andl $0x7f, %r8d
orl %r8d, %esi
cmpl $0x3, %edi
je 0x25bd
incl %edi
testb %r9b, %r9b
js 0x258b
addl %edi, %edx
movl %edx, %eax
cmpl $0x1, %esi
jbe 0x2620
testb $0x1, %r8b
je 0x2614
leal 0x3(%rax), %edx
xorl %esi, %esi
xorl %edi, %edi
leal (%rax,%rdi), %r8d
cmpl %ebp, %r8d
ja 0x2544
movl %esi, %r9d
shll $0x7, %r9d
movl %r8d, %esi
movzbl 0x80(%rsp,%rsi), %r8d
movl %r8d, %esi
andl $0x7f, %esi
orl %r9d, %esi
cmpl $0x3, %edi
je 0x2608
incl %edi
testb %r8b, %r8b
js 0x25cf
addl %edi, %eax
movl %eax, %edx
addl %esi, %edx
movl %edx, %eax
cmpl %ebp, %edx
ja 0x2544
movl %eax, %edx
cmpl %ebp, %eax
jne 0x2584
jmp 0x269e
testl %esi, %esi
je 0x2544
leal 0x3(%rax), %ecx
xorl %edx, %edx
xorl %esi, %esi
leal (%rax,%rsi), %edi
cmpl %ebp, %edi
ja 0x2544
movl %edx, %r8d
shll $0x7, %r8d
movl %edi, %edx
movzbl 0x80(%rsp,%rdx), %edi
movl %edi, %edx
andl $0x7f, %edx
orl %r8d, %edx
cmpl $0x3, %esi
je 0x2663
incl %esi
testb %dil, %dil
js 0x262f
addl %esi, %eax
movl %eax, %ecx
cmpl $0x20, %edx
jne 0x2544
leal 0x20(%rcx), %edx
cmpl %ebp, %edx
ja 0x2544
movl %ecx, %eax
movups 0x80(%rsp,%rax), %xmm0
movups 0x90(%rsp,%rax), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
xorl %ecx, %ecx
cmpl %ebp, %edx
jne 0x2584
jmp 0x26a7
testb $0x1, %cl
jne 0x2544
movq (%r15), %rsi
leaq 0x60(%rsp), %r12
movq %rsp, %rdx
movq %r12, %rdi
callq 0x5880
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x3be4
movq %r13, %rdi
movq %r12, %rsi
movl $0x20, %edx
callq 0x3c09
movq %r13, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x3c09
leaq 0x20(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x56b3
movq %r13, %rdi
callq 0x3be4
movq %r13, %rdi
movq %r12, %rsi
movl $0x20, %edx
callq 0x3c09
movq %r13, %rdi
movq %rbp, %rsi
movl $0x20, %edx
callq 0x3c09
leaq 0x40(%rsp), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x56b3
movl $0x288, %edx            # imm = 0x288
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1080
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
movups %xmm0, 0x1cc(%rbx)
movups %xmm1, 0x1dc(%rbx)
movaps (%rbp), %xmm0
movaps 0x10(%rbp), %xmm1
movups %xmm0, 0x240(%rbx)
movups %xmm1, 0x250(%rbx)
movl $0x40, %eax
movl %eax, 0x1c8(%rbx)
movl %eax, 0x23c(%rbx)
movq %rsp, %rax
movdqa 0x10(%rax), %xmm0
pxor (%rax), %xmm0
movq (%r15), %rax
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
pxor %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
pxor %xmm1, %xmm0
movd %xmm0, %ecx
movw $0x2001, 0x2(%rbx)      # imm = 0x2001
movups 0x20(%rax), %xmm0
movups 0x30(%rax), %xmm1
movups %xmm1, 0x14(%rbx)
movups %xmm0, 0x4(%rbx)
movw $0x1005, 0x24(%rbx)     # imm = 0x1005
movups (%r14), %xmm0
movups %xmm0, 0x26(%rbx)
movw $0x403, 0x36(%rbx)      # imm = 0x403
bswapl %ecx
movl %ecx, 0x38(%rbx)
movw $0x3a00, (%rbx)         # imm = 0x3A00
movl $0x3c, 0x184(%rbx)
movl $0x1, %eax
jmp 0x2551