#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_ATOMIC;
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 |
                          IBV_ACCESS_REMOTE_ATOMIC;
  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    0x2e5c(%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    0x2e3f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
or     (%rax),%ecx
mov    0x2e3d(%rip),%rax
or     (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    0x2de4(%rip),%rax
or     (%rax),%edx
mov    0x2e23(%rip),%rax
or     (%rax),%edx
mov    0x2dda(%rip),%rax
or     (%rax),%edx
call   1040 <ibv_modify_qp@plt>
cmp    $0x0,%rax
je     11fb <qp_change_state_init+0xbb>
lea    0xe0a(%rip),%rdi
call   1060 <die@plt>
jmp    1200 <qp_change_state_init+0xc0>
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    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
mov    0x2e60(%rip),%rax
mov    0x2e41(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e5e(%rip),%rax
or     (%rax),%ecx
mov    0x2e15(%rip),%rax
mov    0x2e16(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
movq   $0x0,0x8(%rbx)
mov    %ebp,(%rbx)
mov    0x2e49(%rip),%rax
or     (%rax),%edx
mov    %ecx,0x4(%rbx)
mov    0x2dfd(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <ibv_modify_qp@plt>
test   %rax,%rax
je     11d9 <qp_change_state_init+0x99>
lea    0xe2c(%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_ACCESS_REMOTE_ATOMIC = 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 i32, i32* @IBV_ACCESS_REMOTE_ATOMIC
%21 = or i32 %19, %20
%22 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%23 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %22, i32 0, i32 1
store i32 %21, i32* %23
br label %24
24: ; preds = %2
%25 = load %struct.ibv_qp*, %struct.ibv_qp** %3
%26 = load %struct.ibv_qp_attr*, %struct.ibv_qp_attr** %5
%27 = load i32, i32* @IBV_QP_STATE
%28 = load i32, i32* @IBV_QP_PKEY_INDEX
%29 = or i32 %27, %28
%30 = load i32, i32* @IBV_QP_PORT
%31 = or i32 %29, %30
%32 = load i32, i32* @IBV_QP_ACCESS_FLAGS
%33 = or i32 %31, %32
%34 = call i64 @ibv_modify_qp(%struct.ibv_qp* %25, %struct.ibv_qp_attr* %26, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %24
br label %39
39: ; preds = %38
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_ACCESS_REMOTE_ATOMIC = 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 = load i32, i32* @IBV_ACCESS_REMOTE_ATOMIC
%13 = or i32 %11, %12
%14 = getelementptr inbounds %struct.ibv_qp_attr, %struct.ibv_qp_attr* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @IBV_QP_STATE
%16 = load i32, i32* @IBV_QP_PKEY_INDEX
%17 = or i32 %16, %15
%18 = load i32, i32* @IBV_QP_PORT
%19 = or i32 %17, %18
%20 = load i32, i32* @IBV_QP_ACCESS_FLAGS
%21 = or i32 %19, %20
%22 = tail call i64 @ibv_modify_qp(%struct.ibv_qp* %0, %struct.ibv_qp_attr* %3, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %2
%25 = tail call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
ret i32 0
}