#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_device {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ibv_free_device_list(struct ibv_device **);
int /*<<< orphan*/ ibv_get_device_guid(struct ibv_device *);
struct ibv_device **ibv_get_device_list(int *);
char *ibv_get_device_name(struct ibv_device *);
scalar_t__ ntohll(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  struct ibv_device **dev_list;
  int num_devices, i;
  dev_list = ibv_get_device_list(&num_devices);
  if (!dev_list) {
    perror("Failed to get IB devices list");
    return 1;
  }
  printf("    %-16s\t   node GUID\n", "device");
  printf("    %-16s\t----------------\n", "------");
  for (i = 0; i < num_devices; ++i) {
    printf("    %-16s\t%016llx\n", ibv_get_device_name(dev_list[i]),
           (unsigned long long)ntohll(ibv_get_device_guid(dev_list[i])));
  }
  ibv_free_device_list(dev_list);
  return 0;
}


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)
lea    -0x1c(%rbp),%rdi
call   1050 <ibv_get_device_list@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <main+0x46>
lea    0xe5b(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <main+0xe3>
lea    0xe61(%rip),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1243 <main+0xd3>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <ibv_get_device_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <ibv_get_device_guid@plt>
mov    %eax,%edi
call   1040 <ntohll@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e7 <main+0x77>
mov    -0x18(%rbp),%rdi
call   1070 <ibv_free_device_list@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1050 <ibv_get_device_list@plt>
test   %rax,%rax
je     1222 <main+0xb2>
mov    %rax,%r12
lea    0xe85(%rip),%rdi
lea    0xe96(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    0xea1(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    120a <main+0x9a>
lea    0xe93(%rip),%r15
xor    %ebx,%ebx
nop
mov    (%r12,%rbx,8),%rdi
call   1080 <ibv_get_device_name@plt>
mov    %rax,%rbp
mov    (%r12,%rbx,8),%rdi
call   1060 <ibv_get_device_guid@plt>
mov    %eax,%edi
call   1040 <ntohll@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x60>
mov    %r12,%rdi
call   1070 <ibv_free_device_list@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd7(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%r14d
jmp    1212 <main+0xa2>

LLVM IR (-O0):
%struct.ibv_device = type { i32 }
@.str = [30 x i8] c"Failed to get IB devices list\00"
@.str.1 = [24 x i8] c" %-16s\09 node GUID\0A\00"
@.str.2 = [7 x i8] c"device\00"
@.str.3 = [28 x i8] c" %-16s\09----------------\0A\00"
@.str.4 = [7 x i8] c"------\00"
@.str.5 = [19 x i8] c" %-16s\09%016llx\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 i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.ibv_device** @ibv_get_device_list(i32* %7)
store %struct.ibv_device** %9, %struct.ibv_device*** %6
%10 = load %struct.ibv_device**, %struct.ibv_device*** %6
%11 = icmp ne %struct.ibv_device** %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %42
14: ; preds = %2
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %17
17: ; preds = %36, %14
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = load %struct.ibv_device**, %struct.ibv_device*** %6
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %22, i64 %24
%26 = load %struct.ibv_device*, %struct.ibv_device** %25
%27 = call i8* @ibv_get_device_name(%struct.ibv_device* %26)
%28 = load %struct.ibv_device**, %struct.ibv_device*** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %28, i64 %30
%32 = load %struct.ibv_device*, %struct.ibv_device** %31
%33 = call i32 @ibv_get_device_guid(%struct.ibv_device* %32)
%34 = call i64 @ntohll(i32 %33)
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %27, i64 %34)
br label %36
36: ; preds = %21
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %17
39: ; preds = %17
%40 = load %struct.ibv_device**, %struct.ibv_device*** %6
%41 = call i32 @ibv_free_device_list(%struct.ibv_device** %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.ibv_device = type { i32 }
@.str = [30 x i8] c"Failed to get IB devices list\00"
@.str.1 = [24 x i8] c" %-16s\09 node GUID\0A\00"
@.str.2 = [7 x i8] c"device\00"
@.str.3 = [28 x i8] c" %-16s\09----------------\0A\00"
@.str.4 = [7 x i8] c"------\00"
@.str.5 = [19 x i8] c" %-16s\09%016llx\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call %struct.ibv_device** @ibv_get_device_list(i32* %3)
%6 = icmp eq %struct.ibv_device** %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %9, %14
%15 = phi i64 [ %23, %14 ], [ 0, %9 ]
%16 = getelementptr inbounds %struct.ibv_device*, %struct.ibv_device** %5, i64 %15
%17 = load %struct.ibv_device*, %struct.ibv_device** %16
%18 = call i8* @ibv_get_device_name(%struct.ibv_device* %17)
%19 = load %struct.ibv_device*, %struct.ibv_device** %16
%20 = call i32 @ibv_get_device_guid(%struct.ibv_device* %19)
%21 = call i64 @ntohll(i32 %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %18, i64 %21)
%23 = add nuw nsw i64 %15, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %14, label %27
27: ; preds = %14, %9
%28 = call i32 @ibv_free_device_list(%struct.ibv_device** %5)
br label %29
29: ; preds = %27, %7
%30 = phi i32 [ 0, %27 ], [ 1, %7 ]
ret i32 %30
}