#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 */
scalar_t__ ifup(char *);
int /*<<< orphan*/ printf(char *, char *);
int tun_alloc(char *);
int StartTap(char *name) {
  int tapfd;
  if ((tapfd = tun_alloc(name)) <= 0) {
    printf("Failed to allocate tap %s\n", name);
    return -1;
  }
  if (ifup(name) != 0) {
    printf("Failed to bring up interface %s\n", name);
    return -1;
  }
  return tapfd;
}


x86 assembly (clang, -O0):
<StartTap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <tun_alloc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     116d <StartTap+0x3d>
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <StartTap+0x72>
mov    -0x10(%rbp),%rdi
call   1050 <ifup@plt>
cmp    $0x0,%rax
je     119c <StartTap+0x6c>
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <StartTap+0x72>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StartTap>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <tun_alloc@plt>
test   %eax,%eax
jle    1157 <StartTap+0x27>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <ifup@plt>
test   %rax,%rax
je     116b <StartTap+0x3b>
lea    0xec6(%rip),%rdi
jmp    115e <StartTap+0x2e>
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Failed to allocate tap %s\0A\00"
@.str.1 = [33 x i8] c"Failed to bring up interface %s\0A\00"
define i32 @StartTap(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @tun_alloc(i8* %5)
store i32 %6, i32* %4
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 -1, i32* %2
br label %20
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @ifup(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 -1, i32* %2
br label %20
18: ; preds = %11
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %15, %8
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [27 x i8] c"Failed to allocate tap %s\0A\00"
@.str.1 = [33 x i8] c"Failed to bring up interface %s\0A\00"
define i32 @StartTap(i8* %0) {
%2 = tail call i32 @tun_alloc(i8* %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i64 @ifup(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4, %1
%8 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %4 ]
%9 = tail call i32 @printf(i8* %8, i8* %0)
br label %10
10: ; preds = %7, %4
%11 = phi i32 [ %2, %4 ], [ -1, %7 ]
ret i32 %11
}