#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 */
typedef int /*<<< orphan*/ __u8;

/* Variables and functions */
int /*<<< orphan*/ PF_NETLINK;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int rtnl_recv(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int rtnl_send_linkmode(int, int, char const *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int set_linkmode(int ifindex, const char *ifname, __u8 linkmode) {
  int s;
  int rc;
  s = socket(PF_NETLINK, SOCK_DGRAM, 0);
  if (s < 0)
    return s;
  rc = rtnl_send_linkmode(s, ifindex, ifname, linkmode);
  if (rc < 0)
    goto out;
  rc = rtnl_recv(s, NULL, NULL);
out:
  close(s);
  return rc;
}


x86 assembly (clang, -O0):
<set_linkmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1183 <set_linkmode+0x43>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <set_linkmode+0x87>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1050 <rtnl_send_linkmode@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a7 <set_linkmode+0x67>
jmp    11b9 <set_linkmode+0x79>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1040 <rtnl_recv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_linkmode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1197 <set_linkmode+0x57>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1050 <rtnl_send_linkmode@plt>
test   %eax,%eax
js     118c <set_linkmode+0x4c>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <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
define i32 @set_linkmode(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* @PF_NETLINK
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %33
17: ; preds = %3
%18 = load i32, i32* %8
%19 = load i32, i32* %5
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @rtnl_send_linkmode(i32 %18, i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
br label %29
26: ; preds = %17
%27 = load i32, i32* %8
%28 = call i32 @rtnl_recv(i32 %27, i32* null, i32* null)
store i32 %28, i32* %9
br label %29
29: ; preds = %26, %25
%30 = load i32, i32* %8
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %9
store i32 %32, i32* %4
br label %33
33: ; preds = %29, %15
%34 = load i32, i32* %4
ret i32 %34
}

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