#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int vrf_connect(char const *);
int vrf_popfd(int);
scalar_t__ vrf_sendcmd(int, int /*<<< orphan*/, void const *, size_t);
int vrf_do(const char *vrf, uint8_t cmd, const void *arg, size_t arglen) {
  int ctlfd = vrf_connect(vrf), fd;
  if (ctlfd == -1)
    return -1;
  if (vrf_sendcmd(ctlfd, cmd, arg, arglen)) {
    close(ctlfd);
    return -1;
  }
  fd = vrf_popfd(ctlfd);
  close(ctlfd);
  return fd;
}


x86 assembly (clang, -O0):
<vrf_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <vrf_connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1179 <vrf_do+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <vrf_do+0x83>
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <vrf_sendcmd@plt>
cmp    $0x0,%rax
je     11aa <vrf_do+0x6a>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <vrf_do+0x83>
mov    -0x2c(%rbp),%edi
call   1060 <vrf_popfd@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vrf_do>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
call   1040 <vrf_connect@plt>
cmp    $0xffffffff,%eax
je     1186 <vrf_do+0x46>
mov    %eax,%ebx
mov    %eax,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <vrf_sendcmd@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    117d <vrf_do+0x3d>
mov    %ebx,%edi
call   1060 <vrf_popfd@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
jmp    118b <vrf_do+0x4b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vrf_do(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %6
%13 = call i32 @vrf_connect(i8* %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %33
17: ; preds = %4
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = load i8*, i8** %8
%21 = load i64, i64* %9
%22 = call i64 @vrf_sendcmd(i32 %18, i32 %19, i8* %20, i64 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %10
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %5
br label %33
27: ; preds = %17
%28 = load i32, i32* %10
%29 = call i32 @vrf_popfd(i32 %28)
store i32 %29, i32* %11
%30 = load i32, i32* %10
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %11
store i32 %32, i32* %5
br label %33
33: ; preds = %27, %24, %16
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
define i32 @vrf_do(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = tail call i32 @vrf_connect(i8* %0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = tail call i64 @vrf_sendcmd(i32 %5, i32 %1, i8* %2, i64 %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @vrf_popfd(i32 %5)
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ %11, %10 ], [ -1, %7 ]
%14 = tail call i32 @close(i32 %5)
br label %15
15: ; preds = %12, %4
%16 = phi i32 [ -1, %4 ], [ %13, %12 ]
ret i32 %16
}