#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 */
struct ibv_wc {
  scalar_t__ status;
};
struct ibv_qp {
  int dummy;
};
struct ibv_mr {
  int dummy;
};
struct ibv_cq {
  int dummy;
};

/* Variables and functions */
scalar_t__ IBV_WC_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ibPostSend(struct ibv_qp *, struct ibv_mr *, char *, size_t);
int ibv_poll_cq(struct ibv_cq *, int, struct ibv_wc *);
int /*<<< orphan*/ stderr;
void ibPostSendAndWait(struct ibv_qp *qp, struct ibv_mr *mr, char *txbuf,
                       size_t txbufsize, struct ibv_cq *cq) {
  ibPostSend(qp, mr, txbuf, txbufsize);
  struct ibv_wc iwc;
  while (ibv_poll_cq(cq, 1, &iwc) < 1)
    ;
  if (iwc.status != IBV_WC_SUCCESS) {
    fprintf(stderr, "ibv_poll_cq returned failure\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<ibPostSendAndWait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <ibPostSend@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
lea    -0x30(%rbp),%rdx
call   1040 <ibv_poll_cq@plt>
cmp    $0x1,%eax
jge    1191 <ibPostSendAndWait+0x51>
jmp    1171 <ibPostSendAndWait+0x31>
mov    -0x30(%rbp),%rax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
je     11c4 <ibPostSendAndWait+0x84>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibPostSendAndWait>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
call   1030 <ibPostSend@plt>
mov    %rsp,%r14
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1040 <ibv_poll_cq@plt>
test   %eax,%eax
jle    1150 <ibPostSendAndWait+0x10>
mov    (%rsp),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <ibPostSendAndWait+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.ibv_qp = type { i32 }
%struct.ibv_mr = type { i32 }
%struct.ibv_cq = type { i32 }
%struct.ibv_wc = type { i64 }
@IBV_WC_SUCCESS = global i64 0
@stderr = global i32 0
@.str = [30 x i8] c"ibv_poll_cq returned failure\0A\00"
define void @ibPostSendAndWait(%struct.ibv_qp* %0, %struct.ibv_mr* %1, i8* %2, i64 %3, %struct.ibv_cq* %4) {
%6 = alloca %struct.ibv_qp*
%7 = alloca %struct.ibv_mr*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.ibv_cq*
%11 = alloca %struct.ibv_wc
store %struct.ibv_qp* %0, %struct.ibv_qp** %6
store %struct.ibv_mr* %1, %struct.ibv_mr** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store %struct.ibv_cq* %4, %struct.ibv_cq** %10
%12 = load %struct.ibv_qp*, %struct.ibv_qp** %6
%13 = load %struct.ibv_mr*, %struct.ibv_mr** %7
%14 = load i8*, i8** %8
%15 = load i64, i64* %9
%16 = call i32 @ibPostSend(%struct.ibv_qp* %12, %struct.ibv_mr* %13, i8* %14, i64 %15)
br label %17
17: ; preds = %21, %5
%18 = load %struct.ibv_cq*, %struct.ibv_cq** %10
%19 = call i32 @ibv_poll_cq(%struct.ibv_cq* %18, i32 1, %struct.ibv_wc* %11)
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %17
br label %17
22: ; preds = %17
%23 = getelementptr inbounds %struct.ibv_wc, %struct.ibv_wc* %11, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* @IBV_WC_SUCCESS
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.ibv_qp = type { i32 }
%struct.ibv_mr = type { i32 }
%struct.ibv_cq = type { i32 }
%struct.ibv_wc = type { i64 }
@IBV_WC_SUCCESS = global i64 0
@stderr = global i32 0
@.str = [30 x i8] c"ibv_poll_cq returned failure\0A\00"
define void @ibPostSendAndWait(%struct.ibv_qp* %0, %struct.ibv_mr* %1, i8* %2, i64 %3, %struct.ibv_cq* %4) {
%6 = alloca %struct.ibv_wc
%7 = tail call i32 @ibPostSend(%struct.ibv_qp* %0, %struct.ibv_mr* %1, i8* %2, i64 %3)
%8 = bitcast %struct.ibv_wc* %6 to i8*
br label %9
9: ; preds = %9, %5
%10 = call i32 @ibv_poll_cq(%struct.ibv_cq* %4, i32 1, %struct.ibv_wc* %6)
%11 = icmp slt i32 %10, 1
br i1 %11, label %9, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.ibv_wc, %struct.ibv_wc* %6, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @IBV_WC_SUCCESS
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
ret void
}