#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;
};
struct ibv_ah {
  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_ah *, 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_ah *ah, struct ibv_qp *qp, struct ibv_mr *mr,
                       char *txbuf, size_t txbufsize, struct ibv_cq *cq) {
  ibPostSend(ah, 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    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <ibPostSend@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
lea    -0x38(%rbp),%rdx
call   1040 <ibv_poll_cq@plt>
cmp    $0x1,%eax
jge    1199 <ibPostSendAndWait+0x59>
jmp    1179 <ibPostSendAndWait+0x39>
mov    -0x38(%rbp),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11cc <ibPostSendAndWait+0x8c>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibPostSendAndWait>:
push   %r14
push   %rbx
push   %rax
mov    %r9,%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_ah = type { i32 }
%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_ah* %0, %struct.ibv_qp* %1, %struct.ibv_mr* %2, i8* %3, i64 %4, %struct.ibv_cq* %5) {
%7 = alloca %struct.ibv_ah*
%8 = alloca %struct.ibv_qp*
%9 = alloca %struct.ibv_mr*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.ibv_cq*
%13 = alloca %struct.ibv_wc
store %struct.ibv_ah* %0, %struct.ibv_ah** %7
store %struct.ibv_qp* %1, %struct.ibv_qp** %8
store %struct.ibv_mr* %2, %struct.ibv_mr** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
store %struct.ibv_cq* %5, %struct.ibv_cq** %12
%14 = load %struct.ibv_ah*, %struct.ibv_ah** %7
%15 = load %struct.ibv_qp*, %struct.ibv_qp** %8
%16 = load %struct.ibv_mr*, %struct.ibv_mr** %9
%17 = load i8*, i8** %10
%18 = load i64, i64* %11
%19 = call i32 @ibPostSend(%struct.ibv_ah* %14, %struct.ibv_qp* %15, %struct.ibv_mr* %16, i8* %17, i64 %18)
br label %20
20: ; preds = %24, %6
%21 = load %struct.ibv_cq*, %struct.ibv_cq** %12
%22 = call i32 @ibv_poll_cq(%struct.ibv_cq* %21, i32 1, %struct.ibv_wc* %13)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %20
br label %20
25: ; preds = %20
%26 = getelementptr inbounds %struct.ibv_wc, %struct.ibv_wc* %13, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @IBV_WC_SUCCESS
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
ret void
}

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