// File: /workspace/github_c_makefile_star2_O0/wuxb45[P]SLB/ib1.c
// Function: ib_socket_create
struct ib_socket *
ib_socket_create(struct ib_port * const port, const u64 depth)
{
  struct ib_socket * const s = (typeof(s))calloc(1, sizeof(*s));
  debug_assert(s);
  s->port = port;

  struct ibv_cq * const cqs = ibv_create_cq(port->ctx, depth, NULL, NULL, 0);
  struct ibv_cq * const cqr = ibv_create_cq(port->ctx, depth, NULL, NULL, 0);
  debug_assert(cqs);
  debug_assert(cqr);
  s->cqs = cqs;
  s->cqr = cqr;

  // qp
  struct ibv_qp_init_attr iattr = {};
  iattr.send_cq = cqs;
  iattr.recv_cq = cqr;
  iattr.qp_type = IBV_QPT_RC;
  iattr.sq_sig_all = 0;

  iattr.cap.max_send_wr = depth;
  iattr.cap.max_recv_wr = depth;
  iattr.cap.max_send_sge = IB1_SGE_DEPTH;
  iattr.cap.max_recv_sge = IB1_SGE_DEPTH;
  iattr.cap.max_inline_data = 60;

  s->qp = ibv_create_qp(port->pd, &iattr);
  debug_assert(s->qp);

  // qp init state
  struct ibv_qp_attr qattr = {};
  qattr.qp_state = IBV_QPS_INIT;
  qattr.pkey_index = 0;
  qattr.port_num = port->port_id;
  qattr.qp_access_flags = IB1_MR_FLAGS;
  const int r = ibv_modify_qp(s->qp, &qattr, IB1_SOCKET_QP_INIT);
  debug_assert(r == 0);

  // wc
  s->wc = (typeof(s->wc))calloc(depth, sizeof(s->wc[0]));
  debug_assert(s->wc);

  // wr/sg
  s->swr.num_sge = 1;
  s->rwr.num_sge = 1;
  s->depth = depth;
  return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, %edi
movl $0xe8, %esi
callq 0x64d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rdx
callq 0x6170
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rdx
callq 0x6170
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
cmpq $0x0, -0x28(%rbp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x6080
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x2, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0x44(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x1, -0x3c(%rbp)
movl $0x3c, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6100
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x90, %edx
callq 0x6080
movl $0x1, -0xf8(%rbp)
movw $0x0, -0x80(%rbp)
movq -0x8(%rbp), %rax
movb 0x8(%rax), %al
movb %al, -0x77(%rbp)
movl $0xf, -0xd8(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0xf8(%rbp), %rsi
movl $0x39, %edx
callq 0x62a0
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
sete %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
movq -0x10(%rbp), %rdi
movl $0x30, %esi
callq 0x64d0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x77b0
movq -0x18(%rbp), %rax
movl $0x1, 0x40(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0xc0(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x18(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)