#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_operstate(int, int, char *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int set_operstate(char *ifname, __u8 operstate) {
  int s;
  int rc;
  int ifindex = 0;
  s = socket(PF_NETLINK, SOCK_DGRAM, 0);
  if (s < 0)
    return s;
  rc = rtnl_send_operstate(s, ifindex, ifname, operstate);
  if (rc < 0)
    goto out;
  rc = rtnl_recv(s, NULL, NULL);
out:
  close(s);
  return rc;
}


x86 assembly (clang, -O0):
<set_operstate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1187 <set_operstate+0x47>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <set_operstate+0x8b>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <rtnl_send_operstate@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ab <set_operstate+0x6b>
jmp    11bd <set_operstate+0x7d>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <rtnl_recv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <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_operstate>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1192 <set_operstate+0x52>
mov    %ebx,%edi
xor    %esi,%esi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1030 <rtnl_send_operstate@plt>
test   %eax,%eax
js     1187 <set_operstate+0x47>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <rtnl_recv@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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