#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*/ NETLINK_ROUTE;
int /*<<< orphan*/ PF_NETLINK;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int rtnl_recv(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int rtnl_send_vlan_newlink(int, int, int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int vlan_create(int ifindex, int vid, char *name) {
  int s;
  int rc;
  s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
  if (s < 0)
    return s;
  rc = rtnl_send_vlan_newlink(s, ifindex, vid, name);
  if (rc < 0)
    goto out;
  rc = rtnl_recv(s, NULL, NULL);
out:
  close(s);
  return rc;
}


x86 assembly (clang, -O0):
<vlan_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    118a <vlan_create+0x4a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <vlan_create+0x8e>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <rtnl_send_vlan_newlink@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ae <vlan_create+0x6e>
jmp    11c0 <vlan_create+0x80>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <rtnl_recv@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlan_create>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     119e <vlan_create+0x5e>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <rtnl_send_vlan_newlink@plt>
test   %eax,%eax
js     1193 <vlan_create+0x53>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <rtnl_recv@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PF_NETLINK = global i32 0
@SOCK_DGRAM = global i32 0
@NETLINK_ROUTE = global i32 0
define i32 @vlan_create(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* @PF_NETLINK
%11 = load i32, i32* @SOCK_DGRAM
%12 = load i32, i32* @NETLINK_ROUTE
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %8
store i32 %17, i32* %4
br label %34
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i8*, i8** %7
%23 = call i32 @rtnl_send_vlan_newlink(i32 %19, i32 %20, i32 %21, i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
br label %30
27: ; preds = %18
%28 = load i32, i32* %8
%29 = call i32 @rtnl_recv(i32 %28, i32* null, i32* null)
store i32 %29, i32* %9
br label %30
30: ; preds = %27, %26
%31 = load i32, i32* %8
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %30, %16
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@PF_NETLINK = global i32 0
@SOCK_DGRAM = global i32 0
@NETLINK_ROUTE = global i32 0
define i32 @vlan_create(i32 %0, i32 %1, i8* %2) {
%4 = load i32, i32* @PF_NETLINK
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @NETLINK_ROUTE
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = tail call i32 @rtnl_send_vlan_newlink(i32 %7, i32 %0, i32 %1, i8* %2)
%11 = icmp slt i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @rtnl_recv(i32 %7, i32* null, i32* null)
br label %14
14: ; preds = %9, %12
%15 = phi i32 [ %10, %9 ], [ %13, %12 ]
%16 = tail call i32 @close(i32 %7)
br label %17
17: ; preds = %3, %14
%18 = phi i32 [ %15, %14 ], [ %7, %3 ]
ret i32 %18
}