#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 */

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ NETLINK_ROUTE;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
scalar_t__ set_nlkernel(int, unsigned int);
scalar_t__ sk_set_nblock(int);
int sk_socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sk_netlink(unsigned int nl_groups) {
  int nfd;
  nfd = sk_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  if (nfd < 0)
    return -1;
  if (set_nlkernel(nfd, nl_groups) < 0 || sk_set_nblock(nfd) < 0) {
    close(nfd);
    return -1;
  }
  return nfd;
}


x86 assembly (clang, -O0):
<sk_netlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
call   1060 <sk_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1184 <sk_netlink+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <sk_netlink+0x85>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <set_nlkernel@plt>
cmp    $0x0,%rax
jl     11ab <sk_netlink+0x6b>
mov    -0xc(%rbp),%edi
call   1040 <sk_set_nblock@plt>
cmp    $0x0,%rax
jge    11bf <sk_netlink+0x7f>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <sk_netlink+0x85>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sk_netlink>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
call   1060 <sk_socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1198 <sk_netlink+0x58>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14d,%esi
call   1050 <set_nlkernel@plt>
test   %rax,%rax
js     1191 <sk_netlink+0x51>
mov    %ebp,%edi
call   1040 <sk_set_nblock@plt>
test   %rax,%rax
js     1191 <sk_netlink+0x51>
mov    %ebp,%ebx
jmp    1198 <sk_netlink+0x58>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
define i32 @sk_netlink(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @AF_NETLINK
%6 = load i32, i32* @SOCK_RAW
%7 = load i32, i32* @NETLINK_ROUTE
%8 = call i32 @sk_socket(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %26
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = call i64 @set_nlkernel(i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* %4
%19 = call i64 @sk_set_nblock(i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17, %12
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
store i32 -1, i32* %2
br label %26
24: ; preds = %17
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %21, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
define i32 @sk_netlink(i32 %0) {
%2 = load i32, i32* @AF_NETLINK
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @NETLINK_ROUTE
%5 = tail call i32 @sk_socket(i32 %2, i32 %3, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = tail call i64 @set_nlkernel(i32 %5, i32 %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @sk_set_nblock(i32 %5)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10, %7
%14 = tail call i32 @close(i32 %5)
br label %15
15: ; preds = %10, %1, %13
%16 = phi i32 [ -1, %13 ], [ -1, %1 ], [ %5, %10 ]
ret i32 %16
}