#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__ {
  scalar_t__ frag_off;
  int protocol;
  scalar_t__ ttl;
};
struct ip_tunnel_parm {
  int /*<<< orphan*/ 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*/ VTI_ISVTI;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ parse_args(int, char **, int, struct ip_tunnel_parm *);
int /*<<< orphan*/ stderr;
int tnl_add_ioctl(int, char *, int /*<<< orphan*/, struct ip_tunnel_parm *);
int do_add(int cmd, int argc, char **argv) {
  struct ip_tunnel_parm p;
  if (parse_args(argc, argv, cmd, &p) < 0)
    return -1;
  if (p.iph.ttl && p.iph.frag_off == 0) {
    fprintf(stderr, "ttl != 0 and nopmtudisc are incompatible\n");
    return -1;
  }
  switch (p.iph.protocol) {
  case IPPROTO_IPIP:
    if (p.i_flags != VTI_ISVTI)
      return tnl_add_ioctl(cmd, "tunl0", p.name, &p);
    else
      return tnl_add_ioctl(cmd, "ip_vti0", p.name, &p);
  case IPPROTO_GRE:
    return tnl_add_ioctl(cmd, "gre0", p.name, &p);
  case IPPROTO_IPV6:
    return tnl_add_ioctl(cmd, "sit0", p.name, &p);
  default:
    fprintf(stderr, "cannot determine tunnel mode (ipip, gre, vti or sit)\n");
    return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<do_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    -0x38(%rbp),%rcx
call   1040 <parse_args@plt>
cmp    $0x0,%rax
jge    116b <do_add+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <do_add+0x154>
cmpq   $0x0,-0x20(%rbp)
je     11a2 <do_add+0x72>
cmpq   $0x0,-0x30(%rbp)
jne    11a2 <do_add+0x72>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <do_add+0x154>
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x80,%eax
je     124a <do_add+0x11a>
jmp    11b8 <do_add+0x88>
mov    -0x3c(%rbp),%eax
sub    $0x81,%eax
je     11de <do_add+0xae>
jmp    11cb <do_add+0x9b>
mov    -0x3c(%rbp),%eax
sub    $0x82,%eax
je     122c <do_add+0xfc>
jmp    1268 <do_add+0x138>
mov    -0x34(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     120e <do_add+0xde>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%edx
lea    0xe2d(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1030 <tnl_add_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1284 <do_add+0x154>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%edx
lea    0xe15(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1030 <tnl_add_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1284 <do_add+0x154>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%edx
lea    0xdff(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1030 <tnl_add_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1284 <do_add+0x154>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%edx
lea    0xde6(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1030 <tnl_add_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1284 <do_add+0x154>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_add>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
lea    0x8(%rsp),%rcx
mov    %esi,%edi
mov    %rdx,%rsi
mov    %ebp,%edx
call   1040 <parse_args@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11f4 <do_add+0xc4>
cmpq   $0x0,0x20(%rsp)
je     117e <do_add+0x4e>
cmpq   $0x0,0x10(%rsp)
jne    117e <do_add+0x4e>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f4 <do_add+0xc4>
mov    0x18(%rsp),%eax
cmp    $0x80,%eax
je     11b3 <do_add+0x83>
cmp    $0x82,%eax
je     11c0 <do_add+0x90>
cmp    $0x81,%eax
jne    11cd <do_add+0x9d>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%eax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%eax
jne    11df <do_add+0xaf>
lea    0xe7f(%rip),%rsi
jmp    11e6 <do_add+0xb6>
mov    0x8(%rsp),%edx
lea    0xe7f(%rip),%rsi
jmp    11e6 <do_add+0xb6>
mov    0x8(%rsp),%edx
lea    0xe6d(%rip),%rsi
jmp    11e6 <do_add+0xb6>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
jmp    1177 <do_add+0x47>
lea    0xe44(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
call   1030 <tnl_add_ioctl@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_tunnel_parm = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i32, i64 }
@stderr = global i32 0
@.str = [42 x i8] c"ttl != 0 and nopmtudisc are incompatible\0A\00"
@VTI_ISVTI = global i32 0
@.str.1 = [6 x i8] c"tunl0\00"
@.str.2 = [8 x i8] c"ip_vti0\00"
@.str.3 = [5 x i8] c"gre0\00"
@.str.4 = [5 x i8] c"sit0\00"
@.str.5 = [54 x i8] c"cannot determine tunnel mode (ipip, gre, vti or sit)\0A\00"
define i32 @do_add(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca %struct.ip_tunnel_parm
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%9 = load i32, i32* %6
%10 = load i8**, i8*** %7
%11 = load i32, i32* %5
%12 = call i64 @parse_args(i32 %9, i8** %10, i32 %11, %struct.ip_tunnel_parm* %8)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %60
15: ; preds = %3
%16 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 2
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 2
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 2
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %60
28: ; preds = %20, %15
%29 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 2
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 1
%31 = load i32, i32* %30
switch i32 %31, label %57 [
i32 129, label %32
i32 130, label %47
i32 128, label %52
]
32: ; preds = %28
%33 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load i32, i32* @VTI_ISVTI
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32, i32* %5
%39 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @tnl_add_ioctl(i32 %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %40, %struct.ip_tunnel_parm* %8)
store i32 %41, i32* %4
br label %60
42: ; preds = %32
%43 = load i32, i32* %5
%44 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @tnl_add_ioctl(i32 %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %45, %struct.ip_tunnel_parm* %8)
store i32 %46, i32* %4
br label %60
47: ; preds = %28
%48 = load i32, i32* %5
%49 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @tnl_add_ioctl(i32 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %50, %struct.ip_tunnel_parm* %8)
store i32 %51, i32* %4
br label %60
52: ; preds = %28
%53 = load i32, i32* %5
%54 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @tnl_add_ioctl(i32 %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %55, %struct.ip_tunnel_parm* %8)
store i32 %56, i32* %4
br label %60
57: ; preds = %28
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %4
br label %60
60: ; preds = %57, %52, %47, %42, %37, %25, %14
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
%struct.ip_tunnel_parm = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i32, i64 }
@stderr = global i32 0
@.str = [42 x i8] c"ttl != 0 and nopmtudisc are incompatible\0A\00"
@VTI_ISVTI = global i32 0
@.str.1 = [6 x i8] c"tunl0\00"
@.str.2 = [8 x i8] c"ip_vti0\00"
@.str.3 = [5 x i8] c"gre0\00"
@.str.4 = [5 x i8] c"sit0\00"
@.str.5 = [54 x i8] c"cannot determine tunnel mode (ipip, gre, vti or sit)\0A\00"
define i32 @do_add(i32 %0, i32 %1, i8** %2) {
%4 = alloca %struct.ip_tunnel_parm
%5 = bitcast %struct.ip_tunnel_parm* %4 to i8*
%6 = call i64 @parse_args(i32 %1, i8** %2, i32 %0, %struct.ip_tunnel_parm* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %44, label %8
8: ; preds = %3
%9 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 2, i32 2
%10 = load i64, i64* %9
%11 = icmp ne i64 %10, 0
%12 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 2, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %44
19: ; preds = %8
%20 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 2, i32 1
%21 = load i32, i32* %20
switch i32 %21, label %41 [
i32 129, label %22
i32 130, label %33
i32 128, label %37
]
22: ; preds = %19
%23 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 1
%24 = load i32, i32* %23
%25 = load i32, i32* @VTI_ISVTI
%26 = icmp eq i32 %24, %25
%27 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 0
%28 = load i32, i32* %27
br i1 %26, label %31, label %29
29: ; preds = %22
%30 = call i32 @tnl_add_ioctl(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28, %struct.ip_tunnel_parm* %4)
br label %44
31: ; preds = %22
%32 = call i32 @tnl_add_ioctl(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %28, %struct.ip_tunnel_parm* %4)
br label %44
33: ; preds = %19
%34 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @tnl_add_ioctl(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %35, %struct.ip_tunnel_parm* %4)
br label %44
37: ; preds = %19
%38 = getelementptr inbounds %struct.ip_tunnel_parm, %struct.ip_tunnel_parm* %4, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @tnl_add_ioctl(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %39, %struct.ip_tunnel_parm* %4)
br label %44
41: ; preds = %19
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %3, %41, %37, %33, %31, %29, %16
%45 = phi i32 [ -1, %16 ], [ -1, %41 ], [ %40, %37 ], [ %36, %33 ], [ %30, %29 ], [ %32, %31 ], [ -1, %3 ]
ret i32 %45
}