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

/* Variables and functions */
int /*<<< orphan*/ NETLINK_GENERIC;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int genl_resolve_family(struct rtnl_handle *, char const *);
scalar_t__ rtnl_open_byproto(struct rtnl_handle *, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int genl_init_handle(struct rtnl_handle *grth, const char *family,
                     int *genl_family) {
  if (*genl_family >= 0)
    return 0;
  if (rtnl_open_byproto(grth, 0, NETLINK_GENERIC) < 0) {
    fprintf(stderr, "Cannot open generic netlink socket\n");
    return -1;
  }
  *genl_family = genl_resolve_family(grth, family);
  if (*genl_family < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<genl_init_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jl     115d <genl_init_handle+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <genl_init_handle+0xa1>
mov    -0x10(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <rtnl_open_byproto@plt>
cmp    $0x0,%rax
jge    119c <genl_init_handle+0x6c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <genl_init_handle+0xa1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <genl_resolve_family@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ca <genl_init_handle+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <genl_init_handle+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genl_init_handle>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
cmpl   $0x0,(%rdx)
jns    1186 <genl_init_handle+0x56>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <rtnl_open_byproto@plt>
test   %rax,%rax
js     116c <genl_init_handle+0x3c>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <genl_resolve_family@plt>
mov    %eax,(%rbx)
sar    $0x1f,%eax
jmp    1186 <genl_init_handle+0x56>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rtnl_handle = type { i32 }
@NETLINK_GENERIC = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"Cannot open generic netlink socket\0A\00"
define i32 @genl_init_handle(%struct.rtnl_handle* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.rtnl_handle*
%6 = alloca i8*
%7 = alloca i32*
store %struct.rtnl_handle* %0, %struct.rtnl_handle** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
%9 = load i32, i32* %8
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %30
12: ; preds = %3
%13 = load %struct.rtnl_handle*, %struct.rtnl_handle** %5
%14 = load i32, i32* @NETLINK_GENERIC
%15 = call i64 @rtnl_open_byproto(%struct.rtnl_handle* %13, i32 0, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %30
20: ; preds = %12
%21 = load %struct.rtnl_handle*, %struct.rtnl_handle** %5
%22 = load i8*, i8** %6
%23 = call i32 @genl_resolve_family(%struct.rtnl_handle* %21, i8* %22)
%24 = load i32*, i32** %7
store i32 %23, i32* %24
%25 = load i32*, i32** %7
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %4
br label %30
29: ; preds = %20
store i32 0, i32* %4
br label %30
30: ; preds = %29, %28, %17, %11
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.rtnl_handle = type { i32 }
@NETLINK_GENERIC = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"Cannot open generic netlink socket\0A\00"
define i32 @genl_init_handle(%struct.rtnl_handle* %0, i8* %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = load i32, i32* @NETLINK_GENERIC
%8 = tail call i64 @rtnl_open_byproto(%struct.rtnl_handle* %0, i32 0, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %16
13: ; preds = %6
%14 = tail call i32 @genl_resolve_family(%struct.rtnl_handle* %0, i8* %1)
store i32 %14, i32* %2
%15 = ashr i32 %14, 31
br label %16
16: ; preds = %13, %3, %10
%17 = phi i32 [ -1, %10 ], [ 0, %3 ], [ %15, %13 ]
ret i32 %17
}