#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_qp_attr {
  int port_num;
  int qp_access_flags;
  scalar_t__ pkey_index;
  int /*<<< orphan*/ qp_state;
};
struct ibv_qp {
  int dummy;
};

/* Variables and functions */
int IBV_ACCESS_REMOTE_READ;
int IBV_ACCESS_REMOTE_WRITE;
int /*<<< orphan*/ IBV_QPS_INIT;
int IBV_QP_ACCESS_FLAGS;
int IBV_QP_PKEY_INDEX;
int IBV_QP_PORT;
int IBV_QP_STATE;
int /*<<< orphan*/ die(char *);
scalar_t__ ibv_modify_qp(struct ibv_qp *, struct ibv_qp_attr *, int);
struct ibv_qp_attr *malloc(int);
int /*<<< orphan*/ memset(struct ibv_qp_attr *, int /*<<< orphan*/, int);
int qp_change_state_init(struct ibv_qp *qp, int port) {
  struct ibv_qp_attr *attr;
  attr = malloc(sizeof *attr);
  memset(attr, 0, sizeof *attr);
  attr->qp_state = IBV_QPS_INIT;
  attr->pkey_index = 0;
  attr->port_num = port;
  attr->qp_access_flags = IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_REMOTE_READ;
  do {
    if ((ibv_modify_qp(qp, attr,
                       IBV_QP_STATE | IBV_QP_PKEY_INDEX | IBV_QP_PORT |
                           IBV_QP_ACCESS_FLAGS)))
      die("Could not modify QP to INIT, ibv_modify_qp");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<qp_change_state_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e47(%rip),%rax
mov    (%rax),%ecx
mov    0x2e26(%rip),%rax
or     (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
mov    0x2df5(%rip),%rax
or     (%rax),%edx
mov    0x2e2c(%rip),%rax
or     (%rax),%edx
mov    0x2deb(%rip),%rax
or     (%rax),%edx
call   1040 <ibv_modify_qp@plt>
cmp    $0x0,%rax
je     11f2 <qp_change_state_init+0xb2>
lea    0xe13(%rip),%rdi
call   1060 <die@plt>
jmp    11f7 <qp_change_state_init+0xb7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qp_change_state_init>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
mov    0x2e68(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e26(%rip),%rax
mov    0x2e27(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
movq   $0x0,0x8(%rbx)
mov    %ebp,(%rbx)
mov    0x2e52(%rip),%rax
or     (%rax),%edx
mov    %ecx,0x4(%rbx)
mov    0x2e0e(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <ibv_modify_qp@plt>
test   %rax,%rax
je     11d0 <qp_change_state_init+0x90>
lea    0xe35(%rip),%rdi
call   1060 <die@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ibv_qp = type { i32 }
%struct.ibv_qp_attr = type { i32, i32, i64, i32 }
@IBV_QPS_INIT = global i32 0
@IBV_ACCESS_REMOTE_WRITE = global i32 0
@IBV_ACCESS_REMOTE_READ = global i32 0
@IBV_QP_STATE = global i32 0
@IBV_QP_PKEY_INDEX = global i32 0
@IBV_QP_PORT = global i32 0
@IBV_QP_ACCESS_FLAGS = global i32 0
@.str = [43 x i8] c"Could not modify QP to INIT, ibv_modify_qp\00"
define i32 @qp_change_state_init(%struct.ibv_qp* %0, i32 %1) {
%3 = alloca %struct.ibv_qp*
%4 = alloca i32
%5 = alloca %struct.ibv_qp_attr*
store %struct.ibv_qp* %0, %struct.ibv_qp** %3
store i32 %1, i32* %4
%6 = call %struct.ibv_qp_attr* @malloc(i32 24)
store %struct.ibv_qp_attr* %6, %struct.ibv_qp_attr** %5
%7 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%8 = call i32 @memset(%struct.ibv_qp_attr* %7, i32 0, i32 24)
%9 = load i32, i32* @IBV_QPS_INIT
%10 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%11 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %10, i32 0, i32 3
store i32 %9, i32* %11
%12 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%13 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %12, i32 0, i32 2
store i64 0, i64* %13
%14 = load i32, i32* %4
%15 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%16 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* @IBV_ACCESS_REMOTE_WRITE
%18 = load i32, i32* @IBV_ACCESS_REMOTE_READ
%19 = or i32 %17, %18
%20 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%21 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %20, i32 0, i32 1
store i32 %19, i32* %21
br label %22
22: ; preds = %2
%23 = load %struct.ibv_qp*, %struct.ibv_qp** %3
%24 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%25 = load i32, i32* @IBV_QP_STATE
%26 = load i32, i32* @IBV_QP_PKEY_INDEX
%27 = or i32 %25, %26
%28 = load i32, i32* @IBV_QP_PORT
%29 = or i32 %27, %28
%30 = load i32, i32* @IBV_QP_ACCESS_FLAGS
%31 = or i32 %29, %30
%32 = call i64 @ibv_modify_qp(%struct.ibv_qp* %23, %struct.ibv_qp_attr* %24, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %22
br label %37
37: ; preds = %36
ret i32 0
}

LLVM IR (-O2):
%struct.ibv_qp = type { i32 }
%struct.ibv_qp_attr = type { i32, i32, i64, i32 }
@IBV_QPS_INIT = global i32 0
@IBV_ACCESS_REMOTE_WRITE = global i32 0
@IBV_ACCESS_REMOTE_READ = global i32 0
@IBV_QP_STATE = global i32 0
@IBV_QP_PKEY_INDEX = global i32 0
@IBV_QP_PORT = global i32 0
@IBV_QP_ACCESS_FLAGS = global i32 0
@.str = [43 x i8] c"Could not modify QP to INIT, ibv_modify_qp\00"
define i32 @qp_change_state_init(%struct.ibv_qp* %0, i32 %1) {
%3 = tail call %struct.ibv_qp_attr* @malloc(i32 24)
%4 = tail call i32 @memset(%struct.ibv_qp_attr* %3, i32 0, i32 24)
%5 = load i32, i32* @IBV_QPS_INIT
%6 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %3, i64 0, i32 3
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %3, i64 0, i32 2
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %3, i64 0, i32 0
store i32 %1, i32* %8
%9 = load i32, i32* @IBV_ACCESS_REMOTE_WRITE
%10 = load i32, i32* @IBV_ACCESS_REMOTE_READ
%11 = or i32 %10, %9
%12 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @IBV_QP_STATE
%14 = load i32, i32* @IBV_QP_PKEY_INDEX
%15 = or i32 %14, %13
%16 = load i32, i32* @IBV_QP_PORT
%17 = or i32 %15, %16
%18 = load i32, i32* @IBV_QP_ACCESS_FLAGS
%19 = or i32 %17, %18
%20 = tail call i64 @ibv_modify_qp(%struct.ibv_qp* %0, %struct.ibv_qp_attr* %3, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %2
%23 = tail call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
ret i32 0
}