// File: KinderRiven[P]rdma_demo/server.cc
// Function: register_memory_region(rdma_context_t*)
static void register_memory_region(rdma_context_t* context)
{
    printf("|register_memory_regio.\n");
    // 注册一段内存区域的函数
    context->ib_buf = new char[context->ib_buf_size]; // 申请一段内存
    if (context->ib_buf == NULL) {
        printf("|--memalign failed.\n");
        exit(1);
    } else {
        strcpy(context->ib_buf, "Hello RDMA!");
        printf("|--memalign ok [%zuB].\n", context->ib_buf_size);
    }

    context->mr = ibv_reg_mr(context->pd, (void*)context->ib_buf,
        context->ib_buf_size,
        IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | IBV_ACCESS_REMOTE_WRITE);
    if (context->mr == NULL) {
        printf("|--ibv_reg_mr failed.\n");
        exit(1);
    } else {
        printf("|--ibv_reg_mr ok.\n");
        printf("|----[lkey:%d][rkey:%d]\n", context->mr->lkey, context->mr->rkey);
        printf("|----[addr:0x%llx][length:%.2fMB]\n", (uint64_t)context->mr->addr, 1.0 * context->mr->length / (1024 * 1024));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x30(%rbp)
leaq 0x13d9(%rip), %rdi      # 0x32ec
movb $0x0, %al
callq 0x1050
movq -0x30(%rbp), %rax
movq 0x578(%rax), %rdi
callq 0x1030
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1f56
leaq 0x13c0(%rip), %rdi      # 0x3305
movb $0x0, %al
callq 0x1050
movl $0x1, %edi
callq 0x1150
movq -0x30(%rbp), %rax
movq (%rax), %rdi
leaq 0x13b6(%rip), %rsi      # 0x331a
callq 0x10f0
movq -0x30(%rbp), %rax
movq 0x578(%rax), %rsi
leaq 0x13ab(%rip), %rdi      # 0x3326
movb $0x0, %al
callq 0x1050
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x578(%rax), %rax
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %rax, -0x20(%rbp)
movl $0x7, -0x24(%rbp)
movl $0x1, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x1fe3
movl -0x24(%rbp), %eax
andl $0x3ff00000, %eax       # imm = 0x3FF00000
cmpl $0x0, %eax
jne 0x1fe3
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x1100
movq %rax, -0x8(%rbp)
jmp 0x2000
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x24(%rbp), %r8d
callq 0x11d0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x202f
leaq 0x1320(%rip), %rdi      # 0x333e
movb $0x0, %al
callq 0x1050
movl $0x1, %edi
callq 0x1150
leaq 0x131f(%rip), %rdi      # 0x3355
xorl %eax, %eax
movb %al, -0x31(%rbp)
callq 0x1050
movb -0x31(%rbp), %al
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x24(%rcx), %esi
movl 0x28(%rcx), %edx
leaq 0x1310(%rip), %rdi      # 0x3368
callq 0x1050
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %xmm1
movaps 0xfab(%rip), %xmm0      # 0x3020
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xfaf(%rip), %xmm0      # 0x3030
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0xf78(%rip), %xmm0      # 0x3010
mulsd %xmm1, %xmm0
movsd 0xf64(%rip), %xmm1      # 0x3008
divsd %xmm1, %xmm0
leaq 0x12d2(%rip), %rdi      # 0x3381
movb $0x1, %al
callq 0x1050
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)