// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x30bf
callq 0x1050
movl $0x16, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3270
leaq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x3280
cmpl $0x0, %eax
jne 0x30eb
callq 0x1050
movl $0x16, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3270
leaq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq -0x50(%rbp), %rdx
callq 0xa380
leaq -0x120(%rbp), %rdi
callq 0x5ae0
leaq -0x70(%rbp), %rsi
leaq -0x120(%rbp), %rdi
movl $0x20, %edx
callq 0x5b60
movq -0x30(%rbp), %rsi
leaq -0x120(%rbp), %rdi
movl $0x10, %edx
callq 0x5b60
leaq -0xb0(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x9c40
leaq -0x120(%rbp), %rdi
callq 0x5ae0
leaq -0x70(%rbp), %rsi
leaq -0x120(%rbp), %rdi
movl $0x20, %edx
callq 0x5b60
leaq -0xb0(%rbp), %rsi
leaq -0x120(%rbp), %rdi
movl $0x20, %edx
callq 0x5b60
leaq -0x90(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x9c40
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x288, %edx            # imm = 0x288
callq 0x10a0
movq -0x10(%rbp), %rax
movq -0x90(%rbp), %rcx
movq %rcx, 0x1cc(%rax)
movq -0x88(%rbp), %rcx
movq %rcx, 0x1d4(%rax)
movq -0x80(%rbp), %rcx
movq %rcx, 0x1dc(%rax)
movq -0x78(%rbp), %rcx
movq %rcx, 0x1e4(%rax)
movq -0x10(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq %rcx, 0x240(%rax)
movq -0xa8(%rbp), %rcx
movq %rcx, 0x248(%rax)
movq -0xa0(%rbp), %rcx
movq %rcx, 0x250(%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x258(%rax)
movq -0x10(%rbp), %rax
movl $0x40, 0x1c8(%rax)
movq -0x10(%rbp), %rax
movl $0x40, 0x23c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x270(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x30(%rbp), %rcx
leaq -0x50(%rbp), %r8
movl $0x182, %esi            # imm = 0x182
callq 0x34b0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x184(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)