#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_port_attr {
  int lid;
};
struct ibv_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ibv_query_port(struct ibv_context *, int, struct ibv_port_attr *);
int /*<<< orphan*/ stderr;
int ibGetLID(struct ibv_context *ctxt, int port) {
  struct ibv_port_attr ipa;
  if (ibv_query_port(ctxt, port, &ipa)) {
    fprintf(stderr, "ibv_query_port failed\n");
    exit(1);
  }
  return ipa.lid;
}


x86 assembly (clang, -O0):
<ibGetLID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ibv_query_port@plt>
cmp    $0x0,%rax
je     1178 <ibGetLID+0x48>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibGetLID>:
push   %rax
mov    %rsp,%rdx
call   1030 <ibv_query_port@plt>
test   %rax,%rax
jne    1143 <ibGetLID+0x13>
mov    (%rsp),%eax
pop    %rcx
ret
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.ibv_context = type { i32 }
%struct.ibv_port_attr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"ibv_query_port failed\0A\00"
define i32 @ibGetLID(%struct.ibv_context* %0, i32 %1) {
%3 = alloca %struct.ibv_context*
%4 = alloca i32
%5 = alloca %struct.ibv_port_attr
store %struct.ibv_context* %0, %struct.ibv_context** %3
store i32 %1, i32* %4
%6 = load %struct.ibv_context*, %struct.ibv_context** %3
%7 = load i32, i32* %4
%8 = call i64 @ibv_query_port(%struct.ibv_context* %6, i32 %7, %struct.ibv_port_attr* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds %struct.ibv_port_attr, %struct.ibv_port_attr* %5, i32 0, i32 0
%16 = load i32, i32* %15
ret i32 %16
}

LLVM IR (-O2):
%struct.ibv_context = type { i32 }
%struct.ibv_port_attr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"ibv_query_port failed\0A\00"
define i32 @ibGetLID(%struct.ibv_context* %0, i32 %1) {
%3 = alloca %struct.ibv_port_attr
%4 = bitcast %struct.ibv_port_attr* %3 to i8*
%5 = call i64 @ibv_query_port(%struct.ibv_context* %0, i32 %1, %struct.ibv_port_attr* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.ibv_port_attr, %struct.ibv_port_attr* %3, i64 0, i32 0
%13 = load i32, i32* %12
ret i32 %13
}