#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int ifpipe(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setup_device(int, int /*<<< orphan*/ *);
int open_macvtap_device(const char *tapdev) {
  int fd, ret;
  fd = open(tapdev, O_RDWR);
  if (fd < 0) {
    perror("open");
    return (EXIT_FAILURE);
  }
  if ((ret = setup_device(fd, NULL)) != (EXIT_SUCCESS)) {
    close(fd);
    return ret;
  }
  return ifpipe(fd);
}


x86 assembly (clang, -O0):
<open_macvtap_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1198 <open_macvtap_device+0x48>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <open_macvtap_device+0x84>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setup_device@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     11c9 <open_macvtap_device+0x79>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <open_macvtap_device+0x84>
mov    -0x14(%rbp),%edi
call   1050 <ifpipe@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_macvtap_device>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     119a <open_macvtap_device+0x4a>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1030 <setup_device@plt>
mov    %eax,%ebp
mov    0x2e57(%rip),%rax
cmp    (%rax),%ebp
jne    118a <open_macvtap_device+0x3a>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <ifpipe@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebp
jmp    1191 <open_macvtap_device+0x41>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @open_macvtap_device(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %2
br label %26
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @setup_device(i32 %15, i32* null)
store i32 %16, i32* %5
%17 = load i32, i32* @EXIT_SUCCESS
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %5
store i32 %22, i32* %2
br label %26
23: ; preds = %14
%24 = load i32, i32* %4
%25 = call i32 @ifpipe(i32 %24)
store i32 %25, i32* %2
br label %26
26: ; preds = %23, %19, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @open_macvtap_device(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
br label %16
8: ; preds = %1
%9 = tail call i32 @setup_device(i32 %3, i32* null)
%10 = load i32, i32* @EXIT_SUCCESS
%11 = icmp eq i32 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @close(i32 %3)
br label %16
14: ; preds = %8
%15 = tail call i32 @ifpipe(i32 %3)
br label %16
16: ; preds = %14, %12, %5
%17 = phi i32 [ %7, %5 ], [ %9, %12 ], [ %15, %14 ]
ret i32 %17
}