#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 void *uint8_t;
typedef void *uint16_t;

/* Variables and functions */
void *atoi(char *);
int /*<<< orphan*/ cleanup_ib_rsrc();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ init_ib_rsrc(char *);
int init_rc_qp(void *, void *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  uint16_t pkey_index;
  uint8_t port;
  int ret;
  if (argc != 4) {
    printf("Please enter <ib device name> <port number> <pkey index>\n");
    exit(1);
  }
  port = atoi(argv[2]);
  pkey_index = atoi(argv[3]);
  init_ib_rsrc(argv[1]);
  ret = init_rc_qp(port, pkey_index);
  cleanup_ib_rsrc();
  exit(ret);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1196 <main+0x36>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <init_ib_rsrc@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <init_rc_qp@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <cleanup_ib_rsrc@plt>
mov    -0x24(%rbp),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x4,%edi
jne    11a9 <main+0x49>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1030 <init_ib_rsrc@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <init_rc_qp@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <cleanup_ib_rsrc@plt>
mov    %ebx,%edi
call   1080 <exit@plt>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [58 x i8] c"Please enter <ib device name> <port number> <pkey index>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i8* @atoi(i8* %17)
store i8* %18, i8** %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i8* @atoi(i8* %21)
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @init_ib_rsrc(i8* %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = call i32 @init_rc_qp(i8* %27, i8* %28)
store i32 %29, i32* %8
%30 = call i32 (...) @cleanup_ib_rsrc()
%31 = load i32, i32* %8
%32 = call i32 @exit(i32 %31)
unreachable
}

LLVM IR (-O2):
@str = [57 x i8] c"Please enter <ib device name> <port number> <pkey index>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i8* @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i8* @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @init_ib_rsrc(i8* %15)
%17 = tail call i32 @init_rc_qp(i8* %10, i8* %13)
%18 = tail call i32 (...) @cleanup_ib_rsrc()
%19 = tail call i32 @exit(i32 %17)
unreachable
}