#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 sockaddr_nl {
  scalar_t__ nl_groups;
  int /*<<< orphan*/ nl_pid;
  int /*<<< orphan*/ nl_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srcAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ NETLINK_GENERIC;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int _createGenericNetlinkSocket(void) {
  int socketFd;
  socketFd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
  struct sockaddr_nl srcAddr;
  memset(&srcAddr, 0, sizeof(srcAddr));
  srcAddr.nl_family = AF_NETLINK;
  srcAddr.nl_pid = getpid();
  srcAddr.nl_groups = 0;
  bind(socketFd, (struct sockaddr *)&srcAddr, sizeof(srcAddr));
  return socketFd;
}


x86 assembly (clang, -O0):
<_createGenericNetlinkSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_createGenericNetlinkSocket>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e90(%rip),%r15
mov    (%r15),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <bind@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i64, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_GENERIC = global i32 0
define i32 @_createGenericNetlinkSocket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_nl
%3 = load i32, i32* @AF_NETLINK
%4 = load i32, i32* @SOCK_RAW
%5 = load i32, i32* @NETLINK_GENERIC
%6 = call i32 @socket(i32 %3, i32 %4, i32 %5)
store i32 %6, i32* %1
%7 = call i32 @memset(%struct.sockaddr_nl* %2, i32 0, i32 16)
%8 = load i32, i32* @AF_NETLINK
%9 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 2
store i32 %8, i32* %9
%10 = call i32 (...) @getpid()
%11 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 0
store i64 0, i64* %12
%13 = load i32, i32* %1
%14 = bitcast %struct.sockaddr_nl* %2 to %struct.sockaddr*
%15 = call i32 @bind(i32 %13, %struct.sockaddr* %14, i32 16)
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i64, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_GENERIC = global i32 0
define i32 @_createGenericNetlinkSocket() {
%1 = alloca %struct.sockaddr_nl
%2 = load i32, i32* @AF_NETLINK
%3 = load i32, i32* @SOCK_RAW
%4 = load i32, i32* @NETLINK_GENERIC
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = bitcast %struct.sockaddr_nl* %1 to i8*
%7 = call i32 @memset(%struct.sockaddr_nl* %1, i32 0, i32 16)
%8 = load i32, i32* @AF_NETLINK
%9 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 2
store i32 %8, i32* %9
%10 = call i32 (...) @getpid()
%11 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 0
store i64 0, i64* %12
%13 = bitcast %struct.sockaddr_nl* %1 to %struct.sockaddr*
%14 = call i32 @bind(i32 %5, %struct.sockaddr* %13, i32 16)
ret i32 %5
}