#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_send_wr {
  int wr_id;
  int num_sge;
  int /*<<< orphan*/ send_flags;
  int /*<<< orphan*/ opcode;
  struct ibv_sge *sg_list;
  int /*<<< orphan*/ *next;
};
struct ibv_qp {
  int dummy;
};
struct ibv_mr {
  int /*<<< orphan*/ lkey;
};
typedef int /*<<< orphan*/ iswr;

/* Variables and functions */
int /*<<< orphan*/ IBV_SEND_SIGNALED;
int /*<<< orphan*/ IBV_WR_SEND;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ibv_post_send(struct ibv_qp *, struct ibv_send_wr *,
                         struct ibv_send_wr **);
int /*<<< orphan*/ memset(struct ibv_send_wr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void ibPostSend(struct ibv_qp *qp, struct ibv_mr *mr, char *txbuf,
                size_t txbufsize) {
  struct ibv_sge isge = {(uint64_t)txbuf, txbufsize, mr->lkey};
  struct ibv_send_wr iswr;
  memset(&iswr, 0, sizeof(iswr));
  iswr.wr_id = 2;
  iswr.next = NULL;
  iswr.sg_list = &isge;
  iswr.num_sge = 1;
  iswr.opcode = IBV_WR_SEND;
  iswr.send_flags = IBV_SEND_SIGNALED;
  struct ibv_send_wr *bad_iswr;
  if (ibv_post_send(qp, &iswr, &bad_iswr)) {
    fprintf(stderr, "ibv_post_send failed!\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<ibPostSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
movl   $0x2,-0x50(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1040 <ibv_post_send@plt>
cmp    $0x0,%rax
je     11f2 <ibPostSend+0xb2>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibPostSend>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
movslq %edx,%rax
mov    %rax,(%rsp)
mov    %ecx,0x8(%rsp)
mov    (%rsi),%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
movabs $0x100000002,%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x28(%rsp)
mov    %rsp,%rax
mov    %rax,0x20(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0x30(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <ibv_post_send@plt>
test   %rax,%rax
jne    11c6 <ibPostSend+0x86>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%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_sge = type { i64, i32, i32 }
%struct.ibv_send_wr = type { i32, i32, i32, i32, %struct.ibv_sge*, i32* }
@IBV_WR_SEND = global i32 0
@IBV_SEND_SIGNALED = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"ibv_post_send failed!\0A\00"
define void @ibPostSend(%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_send_wr
%11 = alloca %struct.ibv_send_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_send_wr* %10, i32 0, i32 32)
%24 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 0
store i32 2, i32* %24
%25 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 5
store i32* null, i32** %25
%26 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 4
store %struct.ibv_sge* %9, %struct.ibv_sge** %26
%27 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 1
store i32 1, i32* %27
%28 = load i32, i32* @IBV_WR_SEND
%29 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 3
store i32 %28, i32* %29
%30 = load i32, i32* @IBV_SEND_SIGNALED
%31 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %10, i32 0, i32 2
store i32 %30, i32* %31
%32 = load %struct.ibv_qp*, %struct.ibv_qp** %5
%33 = call i64 @ibv_post_send(%struct.ibv_qp* %32, %struct.ibv_send_wr* %10, %struct.ibv_send_wr** %11)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %4
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; 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_send_wr = type { i32, i32, i32, i32, %struct.ibv_sge*, i32* }
@IBV_WR_SEND = global i32 0
@IBV_SEND_SIGNALED = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"ibv_post_send failed!\0A\00"
define void @ibPostSend(%struct.ibv_qp* %0, %struct.ibv_mr* nocapture %1, i8* %2, i64 %3) {
%5 = alloca %struct.ibv_sge
%6 = alloca %struct.ibv_send_wr
%7 = alloca %struct.ibv_send_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_send_wr* %6 to i8*
%19 = call i32 @memset(%struct.ibv_send_wr* %6, i32 0, i32 32)
%20 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 0
store i32 2, i32* %20
%21 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 5
store i32* null, i32** %21
%22 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 4
store %struct.ibv_sge* %5, %struct.ibv_sge** %22
%23 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 1
store i32 1, i32* %23
%24 = load i32, i32* @IBV_WR_SEND
%25 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 3
store i32 %24, i32* %25
%26 = load i32, i32* @IBV_SEND_SIGNALED
%27 = getelementptr inbounds %struct.ibv_send_wr, %struct.ibv_send_wr* %6, i64 0, i32 2
store i32 %26, i32* %27
%28 = bitcast %struct.ibv_send_wr** %7 to i8*
%29 = call i64 @ibv_post_send(%struct.ibv_qp* %0, %struct.ibv_send_wr* %6, %struct.ibv_send_wr** %7)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %4
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %4
ret void
}