#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int protocol;
};
struct ip_tunnel_parm {
  char *name;
  int /*<<< orphan*/ i_flags;
  TYPE_1__ iph;
};

/* Variables and functions */
#define IPPROTO_GRE 130
#define IPPROTO_IPIP 129
#define IPPROTO_IPV6 128
int /*<<< orphan*/ SIOCDELTUNNEL;
int /*<<< orphan*/ VTI_ISVTI;
scalar_t__ parse_args(int, char **, int /*<<< orphan*/,
                      struct ip_tunnel_parm *);
int tnl_del_ioctl(char *, char *, struct ip_tunnel_parm *);
int do_del(int argc, char **argv) {
  struct ip_tunnel_parm p;
  if (parse_args(argc, argv, SIOCDELTUNNEL, &p) < 0)
    return -1;
  switch (p.iph.protocol) {
  case IPPROTO_IPIP:
    if (p.i_flags != VTI_ISVTI)
      return tnl_del_ioctl("tunl0", p.name, &p);
    else
      return tnl_del_ioctl("ip_vti0", p.name, &p);
  case IPPROTO_GRE:
    return tnl_del_ioctl("gre0", p.name, &p);
  case IPPROTO_IPV6:
    return tnl_del_ioctl("sit0", p.name, &p);
  default:
    return tnl_del_ioctl(p.name, p.name, &p);
  }
  return -1;
}


x86 assembly (clang, -O0):
<do_del>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
call   1030 <parse_args@plt>
cmp    $0x0,%rax
jge    115e <do_del+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <do_del+0x110>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     1200 <do_del+0xe0>
jmp    1174 <do_del+0x54>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     119a <do_del+0x7a>
jmp    1187 <do_del+0x67>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
je     11e4 <do_del+0xc4>
jmp    121c <do_del+0xfc>
mov    -0x18(%rbp),%eax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
je     11c8 <do_del+0xa8>
mov    -0x20(%rbp),%rsi
lea    0xe49(%rip),%rdi
lea    -0x20(%rbp),%rdx
call   1040 <tnl_del_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1230 <do_del+0x110>
mov    -0x20(%rbp),%rsi
lea    0xe33(%rip),%rdi
lea    -0x20(%rbp),%rdx
call   1040 <tnl_del_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1230 <do_del+0x110>
mov    -0x20(%rbp),%rsi
lea    0xe1f(%rip),%rdi
lea    -0x20(%rbp),%rdx
call   1040 <tnl_del_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1230 <do_del+0x110>
mov    -0x20(%rbp),%rsi
lea    0xe08(%rip),%rdi
lea    -0x20(%rbp),%rdx
call   1040 <tnl_del_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1230 <do_del+0x110>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <tnl_del_ioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_del>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
call   1030 <parse_args@plt>
test   %rax,%rax
js     1172 <do_del+0x52>
mov    0x14(%rsp),%eax
cmp    $0x80,%eax
je     117c <do_del+0x5c>
cmp    $0x82,%eax
je     118a <do_del+0x6a>
cmp    $0x81,%eax
jne    1198 <do_del+0x78>
mov    0x10(%rsp),%eax
mov    0x2e80(%rip),%rcx
mov    0x8(%rsp),%rsi
cmp    (%rcx),%eax
jne    11a7 <do_del+0x87>
lea    0xe96(%rip),%rdi
jmp    11ae <do_del+0x8e>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
mov    0x8(%rsp),%rsi
lea    0xe8b(%rip),%rdi
jmp    11ae <do_del+0x8e>
mov    0x8(%rsp),%rsi
lea    0xe78(%rip),%rdi
jmp    11ae <do_del+0x8e>
mov    0x8(%rsp),%rdi
lea    0x8(%rsp),%rdx
mov    %rdi,%rsi
jmp    11b3 <do_del+0x93>
lea    0xe52(%rip),%rdi
lea    0x8(%rsp),%rdx
call   1040 <tnl_del_ioctl@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.ip_tunnel_parm = type { i8*, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCDELTUNNEL = global i32 0
@VTI_ISVTI = global i32 0
@.str = [6 x i8] c"tunl0\00"
@.str.1 = [8 x i8] c"ip_vti0\00"
@.str.2 = [5 x i8] c"gre0\00"
@.str.3 = [5 x i8] c"sit0\00"
define i32 @do_del(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.ip_tunnel_parm
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = load i32, i32* @SIOCDELTUNNEL
%10 = call i64 @parse_args(i32 %7, i8** %8, i32 %9, %struct.ip_tunnel_parm* %6)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %44
13: ; preds = %2
%14 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 2
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
switch i32 %16, label %38 [
i32 129, label %17
i32 130, label %30
i32 128, label %34
]
17: ; preds = %13
%18 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i32, i32* @VTI_ISVTI
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %24, %struct.ip_tunnel_parm* %6)
store i32 %25, i32* %3
br label %44
26: ; preds = %17
%27 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %28, %struct.ip_tunnel_parm* %6)
store i32 %29, i32* %3
br label %44
30: ; preds = %13
%31 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %32, %struct.ip_tunnel_parm* %6)
store i32 %33, i32* %3
br label %44
34: ; preds = %13
%35 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %36, %struct.ip_tunnel_parm* %6)
store i32 %37, i32* %3
br label %44
38: ; preds = %13
%39 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %6, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i32 @tnl_del_ioctl(i8* %40, i8* %42, %struct.ip_tunnel_parm* %6)
store i32 %43, i32* %3
br label %44
44: ; preds = %38, %34, %30, %26, %22, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.ip_tunnel_parm = type { i8*, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@SIOCDELTUNNEL = global i32 0
@VTI_ISVTI = global i32 0
@.str = [6 x i8] c"tunl0\00"
@.str.1 = [8 x i8] c"ip_vti0\00"
@.str.2 = [5 x i8] c"gre0\00"
@.str.3 = [5 x i8] c"sit0\00"
define i32 @do_del(i32 %0, i8** %1) {
%3 = alloca %struct.ip_tunnel_parm
%4 = bitcast %struct.ip_tunnel_parm* %3 to i8*
%5 = load i32, i32* @SIOCDELTUNNEL
%6 = call i64 @parse_args(i32 %0, i8** %1, i32 %5, %struct.ip_tunnel_parm* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 2, i32 0
%10 = load i32, i32* %9
switch i32 %10, label %30 [
i32 129, label %11
i32 130, label %22
i32 128, label %26
]
11: ; preds = %8
%12 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = load i32, i32* @VTI_ISVTI
%15 = icmp eq i32 %13, %14
%16 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 0
%17 = load i8*, i8** %16
br i1 %15, label %20, label %18
18: ; preds = %11
%19 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %17, %struct.ip_tunnel_parm* %3)
br label %34
20: ; preds = %11
%21 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17, %struct.ip_tunnel_parm* %3)
br label %34
22: ; preds = %8
%23 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %24, %struct.ip_tunnel_parm* %3)
br label %34
26: ; preds = %8
%27 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @tnl_del_ioctl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %28, %struct.ip_tunnel_parm* %3)
br label %34
30: ; preds = %8
%31 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %3, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @tnl_del_ioctl(i8* %32, i8* %32, %struct.ip_tunnel_parm* %3)
br label %34
34: ; preds = %2, %30, %26, %22, %20, %18
%35 = phi i32 [ %33, %30 ], [ %29, %26 ], [ %25, %22 ], [ %19, %18 ], [ %21, %20 ], [ -1, %2 ]
ret i32 %35
}