// File: /workspace/github_c_makefile_star2_O2/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 $0x218, %rsp            # imm = 0x218
cmpq $0x0, (%rsi)
je 0x24fe
movl %ecx, %r14d
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
andl $0x0, 0x10(%rsp)
movl %ecx, %edi
callq 0x54e4
cmpl $0x180, %eax            # imm = 0x180
ja 0x24fe
movl %eax, %ebp
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x54eb
testl %eax, %eax
je 0x24fe
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %eax, %eax
leaq 0x30(%rsp), %r12
leaq 0x90(%rsp), %r13
leaq 0x10(%rsp), %r14
cmpl %ebp, %eax
je 0x24f7
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x32cb
testl %eax, %eax
je 0x24fe
movl 0x30(%rsp), %eax
cmpl $0x1, %eax
jbe 0x24a2
testb $0x1, %al
jne 0x247c
movl 0x10(%rsp), %eax
jmp 0x2449
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x32cb
testl %eax, %eax
je 0x24fe
movl 0x30(%rsp), %eax
addl 0x10(%rsp), %eax
cmpl %ebp, %eax
ja 0x24fe
movl %eax, 0x10(%rsp)
jmp 0x2449
testl %eax, %eax
je 0x24fe
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x32cb
testl %eax, %eax
je 0x24fe
cmpl $0x20, 0x30(%rsp)
jne 0x24fe
movl 0x10(%rsp), %ecx
leal 0x20(%rcx), %eax
cmpl %ebp, %eax
ja 0x24fe
movups 0x90(%rsp,%rcx), %xmm0
movups 0xa0(%rsp,%rcx), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movl %eax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
jmp 0x2449
testb $0x1, 0x4(%rsp)
je 0x251f
callq 0x1050
movl $0x16, (%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rsi
leaq 0x10(%rsp), %rbp
leaq 0x50(%rsp), %rdx
movq %rbp, %rdi
callq 0x55c0
leaq 0x90(%rsp), %r12
movq %r12, %rdi
callq 0x39a0
pushq $0x20
popq %r14
movq %r12, %rdi
movq %rbp, %rsi
movl %r14d, %edx
callq 0x39bf
pushq $0x10
popq %rdx
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x39bf
leaq 0x70(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x541c
movq %r12, %rdi
callq 0x39a0
movq %r12, %rdi
movq %rbp, %rsi
movl %r14d, %edx
callq 0x39bf
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x39bf
leaq 0x30(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x541c
movl $0x288, %edx            # imm = 0x288
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1080
movaps (%r14), %xmm0
movaps 0x10(%r14), %xmm1
movups %xmm0, 0x1cc(%rbx)
movups %xmm1, 0x1dc(%rbx)
movaps (%r13), %xmm0
movaps 0x10(%r13), %xmm1
movups %xmm0, 0x240(%rbx)
movups %xmm1, 0x250(%rbx)
pushq $0x40
popq %rax
movl %eax, 0x1c8(%rbx)
movl %eax, 0x23c(%rbx)
movq (%r15), %r12
movq %rsp, %r14
movl $0x2, (%r14)
leaq 0x50(%rsp), %rdi
callq 0x1c89
movl %eax, %r15d
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
movq %r14, %rdx
movl %ebp, %ecx
callq 0x328b
testl %eax, %eax
je 0x2717
movq %rsp, %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
callq 0x328b
testl %eax, %eax
je 0x2717
movl (%rsp), %eax
leal 0x20(%rax), %ecx
cmpl $0x182, %ecx            # imm = 0x182
ja 0x2717
movups 0x20(%r12), %xmm0
movups 0x30(%r12), %xmm1
movups %xmm1, 0x10(%rbx,%rax)
movups %xmm0, (%rbx,%rax)
movq %rsp, %rdx
movl %ecx, (%rdx)
pushq $0x5
popq %rcx
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
callq 0x328b
testl %eax, %eax
je 0x2717
movq %rsp, %rdx
pushq $0x10
popq %rcx
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
callq 0x328b
testl %eax, %eax
je 0x2717
movl (%rsp), %eax
leal 0x10(%rax), %ecx
cmpl $0x182, %ecx            # imm = 0x182
ja 0x2717
movq 0x8(%rsp), %rdx
movups (%rdx), %xmm0
movups %xmm0, (%rbx,%rax)
movq %rsp, %rdx
movl %ecx, (%rdx)
pushq $0x3
popq %rcx
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
callq 0x328b
testl %eax, %eax
je 0x2717
movq %rsp, %rdx
pushq $0x4
popq %rcx
movq %rbx, %rdi
movl $0x182, %esi            # imm = 0x182
callq 0x328b
testl %eax, %eax
je 0x2717
movl (%rsp), %ecx
leal 0x4(%rcx), %eax
cmpl $0x183, %eax            # imm = 0x183
jae 0x2717
bswapl %r15d
movl %r15d, (%rbx,%rcx)
leal -0x2(%rax), %ecx
rolw $0x8, %cx
movw %cx, (%rbx)
movl %eax, 0x184(%rbx)
jmp 0x250b
callq 0x1040