#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint64_t;
struct ibv_sge {
  size_t member_1;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_0;
};
struct ibv_recv_wr {
  int wr_id;
  int num_sge;
  struct ibv_sge *sg_list;
  int /*<<< orphan*/ *next;
};
struct ibv_qp {
  int dummy;
};
struct ibv_mr {
  int /*<<< orphan*/ lkey;
};
typedef int /*<<< orphan*/ irwr;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ibv_post_recv(struct ibv_qp *, struct ibv_recv_wr *,
                         struct ibv_recv_wr **);
int /*<<< orphan*/ memset(struct ibv_recv_wr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void ibPostReceive(struct ibv_qp *qp, struct ibv_mr *mr, char *rxbuf,
                   size_t rxbufsize) {
  struct ibv_sge isge = {(uint64_t)rxbuf, rxbufsize, mr->lkey};
  struct ibv_recv_wr irwr;
  memset(&irwr, 0, sizeof(irwr));
  irwr.wr_id = 1;
  irwr.next = NULL;
  irwr.sg_list = &isge;
  irwr.num_sge = 1;
  struct ibv_recv_wr *bad_irwr;
  if (ibv_post_recv(qp, &irwr, &bad_irwr)) {
    fprintf(stderr, "failed to ibv_post_recv\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<ibPostReceive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movl   $0x1,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1060 <ibv_post_recv@plt>
cmp    $0x0,%rax
je     11da <ibPostReceive+0x9a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibPostReceive>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
movslq %edx,%rax
mov    %rax,0x8(%rsp)
mov    %ecx,0x10(%rsp)
mov    (%rsi),%eax
mov    %eax,0x14(%rsp)
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movabs $0x100000001,%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x20(%rsp)
lea    0x30(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <ibv_post_recv@plt>
test   %rax,%rax
jne    11af <ibPostReceive+0x6f>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.ibv_qp = type { i32 }
%struct.ibv_mr = type { i32 }
%struct.ibv_sge = type { i64, i32, i32 }
%struct.ibv_recv_wr = type { i32, i32, %struct.ibv_sge*, i32* }
@stderr = global i32 0
@.str = [25 x i8] c"failed to ibv_post_recv\0A\00"
define void @ibPostReceive(%struct.ibv_qp* %0, %struct.ibv_mr* %1, i8* %2, i64 %3) {
%5 = alloca %struct.ibv_qp*
%6 = alloca %struct.ibv_mr*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.ibv_sge
%10 = alloca %struct.ibv_recv_wr
%11 = alloca %struct.ibv_recv_wr*
store %struct.ibv_qp* %0, %struct.ibv_qp** %5
store %struct.ibv_mr* %1, %struct.ibv_mr** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %9, i32 0, i32 0
%13 = load i8*, i8** %7
%14 = ptrtoint i8* %13 to i32
%15 = sext i32 %14 to i64
store i64 %15, i64* %12
%16 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %9, i32 0, i32 1
%17 = load i64, i64* %8
%18 = trunc i64 %17 to i32
store i32 %18, i32* %16
%19 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %9, i32 0, i32 2
%20 = load %struct.ibv_mr*, %struct.ibv_mr** %6
%21 = getelementptr inbounds %struct.ibv_mr, %struct.ibv_mr* %20, i32 0, i32 0
%22 = load i32, i32* %21
store i32 %22, i32* %19
%23 = call i32 @memset(%struct.ibv_recv_wr* %10, i32 0, i32 24)
%24 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %10, i32 0, i32 0
store i32 1, i32* %24
%25 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %10, i32 0, i32 3
store i32* null, i32** %25
%26 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %10, i32 0, i32 2
store %struct.ibv_sge* %9, %struct.ibv_sge** %26
%27 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %10, i32 0, i32 1
store i32 1, i32* %27
%28 = load %struct.ibv_qp*, %struct.ibv_qp** %5
%29 = call i64 @ibv_post_recv(%struct.ibv_qp* %28, %struct.ibv_recv_wr* %10, %struct.ibv_recv_wr** %11)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %4
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %4
ret void
}

LLVM IR (-O2):
%struct.ibv_qp = type { i32 }
%struct.ibv_mr = type { i32 }
%struct.ibv_sge = type { i64, i32, i32 }
%struct.ibv_recv_wr = type { i32, i32, %struct.ibv_sge*, i32* }
@stderr = global i32 0
@.str = [25 x i8] c"failed to ibv_post_recv\0A\00"
define void @ibPostReceive(%struct.ibv_qp* %0, %struct.ibv_mr* nocapture %1, i8* %2, i64 %3) {
%5 = alloca %struct.ibv_sge
%6 = alloca %struct.ibv_recv_wr
%7 = alloca %struct.ibv_recv_wr*
%8 = bitcast %struct.ibv_sge* %5 to i8*
%9 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %5, i64 0, i32 0
%10 = ptrtoint i8* %2 to i64
%11 = shl i64 %10, 32
%12 = ashr exact i64 %11, 32
store i64 %12, i64* %9
%13 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %5, i64 0, i32 1
%14 = trunc i64 %3 to i32
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.ibv_sge, %struct.ibv_sge* %5, i64 0, i32 2
%16 = getelementptr inbounds %struct.ibv_mr, %struct.ibv_mr* %1, i64 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %15
%18 = bitcast %struct.ibv_recv_wr* %6 to i8*
%19 = call i32 @memset(%struct.ibv_recv_wr* %6, i32 0, i32 24)
%20 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %6, i64 0, i32 0
store i32 1, i32* %20
%21 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %6, i64 0, i32 3
store i32* null, i32** %21
%22 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %6, i64 0, i32 2
store %struct.ibv_sge* %5, %struct.ibv_sge** %22
%23 = getelementptr inbounds %struct.ibv_recv_wr, %struct.ibv_recv_wr* %6, i64 0, i32 1
store i32 1, i32* %23
%24 = bitcast %struct.ibv_recv_wr** %7 to i8*
%25 = call i64 @ibv_post_recv(%struct.ibv_qp* %0, %struct.ibv_recv_wr* %6, %struct.ibv_recv_wr** %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %4
ret void
}