#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*/ TASKSTATS_CMD_ATTR_REGISTER_CPUMASK;
int /*<<< orphan*/ TASKSTATS_CMD_GET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getnumcpu();
int /*<<< orphan*/ getpid();
int nlsock_getfam(int);
int nlsock_open();
int nlsock_sendcmd(int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                   int /*<<< orphan*/, char **, scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int netlink_open(void) {
  int nlsock, famid;
  char cpudef[64];
  nlsock = nlsock_open();
  famid = nlsock_getfam(nlsock);
  sprintf(cpudef, "0-%d", getnumcpu() - 1);
  if (nlsock_sendcmd(nlsock, famid, getpid(), TASKSTATS_CMD_GET,
                     TASKSTATS_CMD_ATTR_REGISTER_CPUMASK, &cpudef,
                     strlen(cpudef) + 1) == -1) {
    fprintf(stderr, "register cpumask failed\n");
    return -1;
  }
  return nlsock;
}


x86 assembly (clang, -O0):
<netlink_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    $0x0,%al
call   1070 <nlsock_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   10a0 <nlsock_getfam@plt>
mov    %eax,-0xc(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1080 <getnumcpu@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%edx
sub    $0x1,%edx
lea    0xe41(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x64(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    -0x58(%rbp),%r9
add    $0x1,%rax
mov    %rax,(%rsp)
call   1030 <nlsock_sendcmd@plt>
cmp    $0xffffffff,%eax
jne    124e <netlink_open+0xce>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <netlink_open+0xd4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netlink_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %eax,%eax
call   1070 <nlsock_open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   10a0 <nlsock_getfam@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1080 <getnumcpu@plt>
lea    -0x1(%rax),%edx
lea    0xe4e(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1090 <sprintf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r12d
mov    0x2e18(%rip),%rax
mov    (%rax),%r13d
mov    0x2e06(%rip),%rax
mov    (%rax),%ebp
mov    %r15,%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,(%rsp)
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %ebp,%r8d
mov    %r15,%r9
call   1030 <nlsock_sendcmd@plt>
cmp    $0xffffffff,%eax
jne    1221 <netlink_open+0xa1>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0-%d\00"
@TASKSTATS_CMD_GET = global i32 0
@TASKSTATS_CMD_ATTR_REGISTER_CPUMASK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"register cpumask failed\0A\00"
define i32 @netlink_open() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = call i32 (...) @nlsock_open()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @nlsock_getfam(i32 %6)
store i32 %7, i32* %3
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = call i32 (...) @getnumcpu()
%10 = sub nsw i32 %9, 1
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 (...) @getpid()
%15 = load i32, i32* @TASKSTATS_CMD_GET
%16 = load i32, i32* @TASKSTATS_CMD_ATTR_REGISTER_CPUMASK
%17 = bitcast [64 x i8]* %4 to i8**
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i32 @nlsock_sendcmd(i32 %12, i32 %13, i32 %14, i32 %15, i32 %16, i8** %17, i64 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %0
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %28
26: ; preds = %0
%27 = load i32, i32* %2
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"0-%d\00"
@TASKSTATS_CMD_GET = global i32 0
@TASKSTATS_CMD_ATTR_REGISTER_CPUMASK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"register cpumask failed\0A\00"
define i32 @netlink_open() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @nlsock_open()
%4 = tail call i32 @nlsock_getfam(i32 %3)
%5 = tail call i32 (...) @getnumcpu()
%6 = add nsw i32 %5, -1
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @getpid()
%9 = load i32, i32* @TASKSTATS_CMD_GET
%10 = load i32, i32* @TASKSTATS_CMD_ATTR_REGISTER_CPUMASK
%11 = bitcast [64 x i8]* %1 to i8**
%12 = call i64 @strlen(i8* %2)
%13 = add nsw i64 %12, 1
%14 = call i32 @nlsock_sendcmd(i32 %3, i32 %4, i32 %8, i32 %9, i32 %10, i8** %11, i64 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %0, %16
%20 = phi i32 [ -1, %16 ], [ %3, %0 ]
ret i32 %20
}