#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct option {
  char *name;
  int has_arg;
  char val;
  int /*<<< orphan*/ member_0;
};
struct ibv_device {
  int dummy;
};
struct ibv_context {
  int async_fd;
};
struct TYPE_2__ {
  int port_num;
};
struct ibv_async_event {
  int event_type;
  TYPE_1__ element;
};

/* Variables and functions */
int /*<<< orphan*/ _IOLBF;
char *event_name_str(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ibv_ack_async_event(struct ibv_async_event *);
scalar_t__ ibv_get_async_event(struct ibv_context *, struct ibv_async_event *);
struct ibv_device **ibv_get_device_list(int /*<<< orphan*/ *);
char *ibv_get_device_name(struct ibv_device *);
struct ibv_context *ibv_open_device(struct ibv_device *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
char *strdupa(int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  struct ibv_device **dev_list;
  struct ibv_context *context;
  struct ibv_async_event event;
  char *ib_devname = NULL;
  int i = 0;
  setvbuf(stdout, NULL, _IOLBF, 0);
  while (1) {
    int ret = 1;
    int c;
    static struct option long_options[] = {
        {.name = "ib-dev", .has_arg = 1, .val = 'd'},
        {.name = "help", .has_arg = 0, .val = 'h'},
        {0}};
    c = getopt_long(argc, argv, "d:h", long_options, NULL);
    if (c == -1)
      break;
    switch (c) {
    case 'd':
      ib_devname = strdupa(optarg);
      break;
    case 'h':
      ret = 0;
    default:
      usage(argv[0]);
      return ret;
    }
  }
  dev_list = ibv_get_device_list(NULL);
  if (!dev_list) {
    perror("Failed to get IB devices list");
    return 1;
  }
  if (ib_devname) {
    for (; dev_list[i]; ++i) {
      if (!strcmp(ibv_get_device_name(dev_list[i]), ib_devname))
        break;
    }
  }
  if (!dev_list[i]) {
    fprintf(stderr, "IB device %s not found\n", ib_devname ? ib_devname : "");
    return 1;
  }
  context = ibv_open_device(dev_list[i]);
  if (!context) {
    fprintf(stderr, "Couldn't get context for %s\n",
            ibv_get_device_name(dev_list[i]));
    return 1;
  }
  printf("%s: async event FD %d\n", ibv_get_device_name(dev_list[i]),
         context->async_fd);
  while (1) {
    if (ibv_get_async_event(context, &event))
      return 1;
    printf("  event_type %s (%d), port %d\n", event_name_str(event.event_type),
           event.event_type, event.element.port_num);
    ibv_ack_async_event(&event);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10c0 <setvbuf@plt>
movl   $0x1,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdd5(%rip),%rdx
lea    0x2e62(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    125a <main+0x7a>
jmp    12b9 <main+0xd9>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x64,%eax
je     127f <main+0x9f>
jmp    126e <main+0x8e>
mov    -0x40(%rbp),%eax
sub    $0x68,%eax
je     1296 <main+0xb6>
jmp    129d <main+0xbd>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10a0 <strdupa@plt>
mov    %rax,-0x30(%rbp)
jmp    12b4 <main+0xd4>
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <usage@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1488 <main+0x2a8>
jmp    1222 <main+0x42>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <ibv_get_device_list@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e9 <main+0x109>
lea    0xd38(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1488 <main+0x2a8>
cmpq   $0x0,-0x30(%rbp)
je     134f <main+0x16f>
jmp    12f9 <main+0x119>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     134a <main+0x16a>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <ibv_get_device_name@plt>
mov    %rax,%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1337 <main+0x157>
jmp    134a <main+0x16a>
jmp    133c <main+0x15c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12f9 <main+0x119>
jmp    134f <main+0x16f>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    13b5 <main+0x1d5>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1386 <main+0x1a6>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1396 <main+0x1b6>
lea    0xcec(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1396 <main+0x1b6>
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%rdx
lea    0xc8a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1488 <main+0x2a8>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <ibv_open_device@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1410 <main+0x230>
mov    0x2bfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <ibv_get_device_name@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xc47(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1488 <main+0x2a8>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <ibv_get_device_name@plt>
mov    %rax,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <ibv_get_async_event@plt>
cmp    $0x0,%rax
je     145b <main+0x27b>
movl   $0x1,-0x4(%rbp)
jmp    1488 <main+0x2a8>
mov    -0x28(%rbp),%edi
call   1100 <event_name_str@plt>
mov    %rax,%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xc07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
call   1090 <ibv_ack_async_event@plt>
jmp    1438 <main+0x258>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
xor    %esi,%esi
xor    %ecx,%ecx
call   10c0 <setvbuf@plt>
lea    0xdf7(%rip),%r14
lea    0x2e84(%rip),%r12
mov    0x2dd5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
cmp    $0x64,%eax
jne    1256 <main+0x76>
mov    0x0(%r13),%edi
call   10a0 <strdupa@plt>
mov    %rax,%r15
jmp    1230 <main+0x50>
cmp    $0xffffffff,%eax
je     1265 <main+0x85>
cmp    $0x68,%eax
jne    12b6 <main+0xd6>
xor    %r14d,%r14d
jmp    12bc <main+0xdc>
xor    %edi,%edi
call   1080 <ibv_get_device_list@plt>
test   %rax,%rax
je     13c6 <main+0x1e6>
mov    %rax,%r14
test   %r15,%r15
je     12ca <main+0xea>
mov    (%r14),%rdi
test   %rdi,%rdi
je     12d1 <main+0xf1>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
call   10e0 <ibv_get_device_name@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12b2 <main+0xd2>
mov    0x8(%r14,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1290 <main+0xb0>
mov    %ebx,%ebp
jmp    12d3 <main+0xf3>
mov    $0x1,%r14d
mov    0x0(%rbp),%rdi
call   10b0 <usage@plt>
jmp    13b4 <main+0x1d4>
lea    0xda8(%rip),%r15
xor    %ebp,%ebp
mov    (%r14,%rbp,8),%rdi
test   %rdi,%rdi
je     1376 <main+0x196>
call   10d0 <ibv_open_device@plt>
test   %rax,%rax
je     138b <main+0x1ab>
mov    %rax,%rbx
mov    (%r14,%rbp,8),%rdi
call   10e0 <ibv_get_device_name@plt>
mov    (%rbx),%edx
lea    0xd60(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <ibv_get_async_event@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    13b4 <main+0x1d4>
lea    0xd4c(%rip),%r15
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%edi
call   1100 <event_name_str@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1090 <ibv_ack_async_event@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <ibv_get_async_event@plt>
test   %rax,%rax
je     1340 <main+0x160>
jmp    13b4 <main+0x1d4>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xca8(%rip),%rsi
mov    %r15,%rdx
jmp    13a9 <main+0x1c9>
mov    0x2c46(%rip),%rax
mov    (%rax),%ebx
mov    (%r14,%rbp,8),%rdi
call   10e0 <ibv_get_device_name@plt>
lea    0xca2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc43(%rip),%rdi
call   10f0 <perror@plt>
jmp    13ae <main+0x1ce>

LLVM IR (-O0):
%struct.option = type { i8*, i32, i8, i32 }
%struct.ibv_device = type { i32 }
%struct.ibv_context = type { i32 }
%struct.ibv_async_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@stdout = global i32 0
@_IOLBF = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 1, i8 100, i32 0 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 104, i32 0 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"ib-dev\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [4 x i8] c"d:h\00"
@optarg = global i32 0
@.str.3 = [30 x i8] c"Failed to get IB devices list\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"IB device %s not found\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [29 x i8] c"Couldn't get context for %s\0A\00"
@.str.7 = [23 x i8] c"%s: async event FD %d\0A\00"
@.str.8 = [31 x i8] c" event_type %s (%d), port %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ibv_device**
%7 = alloca %struct.ibv_context*
%8 = alloca %struct.ibv_async_event
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
store i32 0, i32* %10
%13 = load i32, i32* @stdout
%14 = load i32, i32* @_IOLBF
%15 = call i32 @setvbuf(i32 %13, i32* null, i32 %14, i32 0)
br label %16
16: ; preds = %2, %35
store i32 1, i32* %11
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt_long(i32 %17, i8** %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
br label %36
23: ; preds = %16
%24 = load i32, i32* %12
switch i32 %24, label %29 [
i32 100, label %25
i32 104, label %28
]
25: ; preds = %23
%26 = load i32, i32* @optarg
%27 = call i8* @strdupa(i32 %26)
store i8* %27, i8** %9
br label %35
28: ; preds = %23
store i32 0, i32* %11
br label %29
29: ; preds = %23, %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @usage(i8* %32)
%34 = load i32, i32* %11
store i32 %34, i32* %3
br label %131
35: ; preds = %25
br label %16
36: ; preds = %22
%37 = call %struct.ibv_device** @ibv_get_device_list(i32* null)
store %struct.ibv_device** %37, %struct.ibv_device*** %6
%38 = load %struct.ibv_device**, %struct.ibv_device*** %6
%39 = icmp ne %struct.ibv_device** %38, null
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %131
42: ; preds = %36
%43 = load i8*, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %69
45: ; preds = %42
br label %46
46: ; preds = %65, %45
%47 = load %struct.ibv_device**, %struct.ibv_device*** %6
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %47, i64 %49
%51 = load %struct.ibv_device*, %struct.ibv_device** %50
%52 = icmp ne %struct.ibv_device* %51, null
br i1 %52, label %53, label %68
53: ; preds = %46
%54 = load %struct.ibv_device**, %struct.ibv_device*** %6
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %54, i64 %56
%58 = load %struct.ibv_device*, %struct.ibv_device** %57
%59 = call i8* @ibv_get_device_name(%struct.ibv_device* %58)
%60 = load i8*, i8** %9
%61 = call i32 @strcmp(i8* %59, i8* %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %53
br label %68
64: ; preds = %53
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %46
68: ; preds = %63, %46
br label %69
69: ; preds = %68, %42
%70 = load %struct.ibv_device**, %struct.ibv_device*** %6
%71 = load i32, i32* %10
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %70, i64 %72
%74 = load %struct.ibv_device*, %struct.ibv_device** %73
%75 = icmp ne %struct.ibv_device* %74, null
br i1 %75, label %86, label %76
76: ; preds = %69
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %9
%79 = icmp ne i8* %78, null
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = load i8*, i8** %9
br label %83
82: ; preds = %76
br label %83
83: ; preds = %82, %80
%84 = phi i8* [ %81, %80 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %82 ]
%85 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %84)
store i32 1, i32* %3
br label %131
86: ; preds = %69
%87 = load %struct.ibv_device**, %struct.ibv_device*** %6
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %87, i64 %89
%91 = load %struct.ibv_device*, %struct.ibv_device** %90
%92 = call %struct.ibv_context* @ibv_open_device(%struct.ibv_device* %91)
store %struct.ibv_context* %92, %struct.ibv_context** %7
%93 = load %struct.ibv_context*, %struct.ibv_context** %7
%94 = icmp ne %struct.ibv_context* %93, null
br i1 %94, label %104, label %95
95: ; preds = %86
%96 = load i32, i32* @stderr
%97 = load %struct.ibv_device**, %struct.ibv_device*** %6
%98 = load i32, i32* %10
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %97, i64 %99
%101 = load %struct.ibv_device*, %struct.ibv_device** %100
%102 = call i8* @ibv_get_device_name(%struct.ibv_device* %101)
%103 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %102)
store i32 1, i32* %3
br label %131
104: ; preds = %86
%105 = load %struct.ibv_device**, %struct.ibv_device*** %6
%106 = load i32, i32* %10
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %105, i64 %107
%109 = load %struct.ibv_device*, %struct.ibv_device** %108
%110 = call i8* @ibv_get_device_name(%struct.ibv_device* %109)
%111 = load %struct.ibv_context*, %struct.ibv_context** %7
%112 = getelementptr inbounds %struct.ibv_context, %struct.ibv_context* %111, i32 0, i32 0
%113 = load i32, i32* %112
%114 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %110, i32 %113)
br label %115
115: ; preds = %104, %120
%116 = load %struct.ibv_context*, %struct.ibv_context** %7
%117 = call i64 @ibv_get_async_event(%struct.ibv_context* %116, %struct.ibv_async_event* %8)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %120
119: ; preds = %115
store i32 1, i32* %3
br label %131
120: ; preds = %115
%121 = getelementptr inbounds %struct.ibv_async_event, %struct.ibv_async_event* %8, i32 0, i32 0
%122 = load i32, i32* %121
%123 = call i8* @event_name_str(i32 %122)
%124 = getelementptr inbounds %struct.ibv_async_event, %struct.ibv_async_event* %8, i32 0, i32 0
%125 = load i32, i32* %124
%126 = getelementptr inbounds %struct.ibv_async_event, %struct.ibv_async_event* %8, i32 0, i32 1
%127 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %126, i32 0, i32 0
%128 = load i32, i32* %127
%129 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %123, i32 %125, i32 %128)
%130 = call i32 @ibv_ack_async_event(%struct.ibv_async_event* %8)
br label %115
131: ; preds = %119, %95, %83, %40, %29
%132 = load i32, i32* %3
ret i32 %132
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i8, i32 }
%struct.ibv_async_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.ibv_device = type { i32 }
%struct.ibv_context = type { i32 }
@stdout = global i32 0
@_IOLBF = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 1, i8 100, i32 0 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i32 0, i8 104, i32 0 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"ib-dev\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [4 x i8] c"d:h\00"
@optarg = global i32 0
@.str.3 = [30 x i8] c"Failed to get IB devices list\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"IB device %s not found\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [29 x i8] c"Couldn't get context for %s\0A\00"
@.str.7 = [23 x i8] c"%s: async event FD %d\0A\00"
@.str.8 = [31 x i8] c" event_type %s (%d), port %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.ibv_async_event
%4 = bitcast %struct.ibv_async_event* %3 to i8*
%5 = load i32, i32* @stdout
%6 = load i32, i32* @_IOLBF
%7 = tail call i32 @setvbuf(i32 %5, i32* null, i32 %6, i32 0)
br label %8
8: ; preds = %16, %2
%9 = phi i8* [ null, %2 ], [ %18, %16 ]
%10 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
switch i32 %10, label %11 [
i32 -1, label %19
i32 100, label %16
i32 104, label %12
]
11: ; preds = %8
br label %12
12: ; preds = %8, %11
%13 = phi i32 [ 1, %11 ], [ 0, %8 ]
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
br label %80
16: ; preds = %8
%17 = load i32, i32* @optarg
%18 = tail call i8* @strdupa(i32 %17)
br label %8
19: ; preds = %8
%20 = tail call %struct.ibv_device** @ibv_get_device_list(i32* null)
%21 = icmp eq %struct.ibv_device** %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %80
24: ; preds = %19
%25 = icmp eq i8* %9, null
br i1 %25, label %43, label %26
26: ; preds = %24
%27 = load %struct.ibv_device*, %struct.ibv_device** %20
%28 = icmp eq %struct.ibv_device* %27, null
br i1 %28, label %43, label %29
29: ; preds = %26, %35
%30 = phi i64 [ %36, %35 ], [ 0, %26 ]
%31 = phi %struct.ibv_device* [ %38, %35 ], [ %27, %26 ]
%32 = tail call i8* @ibv_get_device_name(%struct.ibv_device* %31)
%33 = tail call i32 @strcmp(i8* dereferenceable(1) %32, i8* %9)
%34 = icmp eq i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %29
%36 = add nuw i64 %30, 1
%37 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %20, i64 %36
%38 = load %struct.ibv_device*, %struct.ibv_device** %37
%39 = icmp eq %struct.ibv_device* %38, null
br i1 %39, label %40, label %29
40: ; preds = %35, %29
%41 = phi i64 [ %30, %29 ], [ %36, %35 ]
%42 = and i64 %41, 4294967295
br label %43
43: ; preds = %40, %26, %24
%44 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %24 ], [ %9, %26 ], [ %9, %40 ]
%45 = phi i64 [ 0, %24 ], [ 0, %26 ], [ %42, %40 ]
%46 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %20, i64 %45
%47 = load %struct.ibv_device*, %struct.ibv_device** %46
%48 = icmp eq %struct.ibv_device* %47, null
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i32, i32* @stderr
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %80
52: ; preds = %43
%53 = tail call %struct.ibv_context* @ibv_open_device(%struct.ibv_device* %47)
%54 = icmp eq %struct.ibv_context* %53, null
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = load %struct.ibv_device*, %struct.ibv_device** %46
%58 = tail call i8* @ibv_get_device_name(%struct.ibv_device* %57)
%59 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %58)
br label %80
60: ; preds = %52
%61 = load %struct.ibv_device*, %struct.ibv_device** %46
%62 = tail call i8* @ibv_get_device_name(%struct.ibv_device* %61)
%63 = getelementptr inbounds %struct.ibv_context, %struct.ibv_context* %53, i64 0, i32 0
%64 = load i32, i32* %63
%65 = tail call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %62, i32 %64)
%66 = call i64 @ibv_get_async_event(%struct.ibv_context* %53, %struct.ibv_async_event* %3)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %80
68: ; preds = %60
%69 = getelementptr inbounds %struct.ibv_async_event, %struct.ibv_async_event* %3, i64 0, i32 0
%70 = getelementptr inbounds %struct.ibv_async_event, %struct.ibv_async_event* %3, i64 0, i32 1, i32 0
br label %71
71: ; preds = %68, %71
%72 = load i32, i32* %69
%73 = call i8* @event_name_str(i32 %72)
%74 = load i32, i32* %69
%75 = load i32, i32* %70
%76 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %73, i32 %74, i32 %75)
%77 = call i32 @ibv_ack_async_event(%struct.ibv_async_event* %3)
%78 = call i64 @ibv_get_async_event(%struct.ibv_context* %53, %struct.ibv_async_event* %3)
%79 = icmp eq i64 %78, 0
br i1 %79, label %71, label %80
80: ; preds = %71, %60, %12, %55, %49, %22
%81 = phi i32 [ 1, %55 ], [ 1, %49 ], [ 1, %22 ], [ %13, %12 ], [ 1, %60 ], [ 1, %71 ]
ret i32 %81
}