#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 u_int32_t;

/* Variables and functions */
int br_set_trill_vni(char *const, char *const, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int, ...);
int sscanf(char *const, char *, int *);
int /*<<< orphan*/ stderr;
int br_cmd_setvni(int argc, char *const *argv) {
  int err;
  u_int32_t label, vni;
  if (sscanf(argv[3], "%i", &label) != 1) {
    fprintf(stderr, "bad vni value\n");
    return 1;
  }
  if ((label > 16777215) || (label < 1)) {
    fprintf(stderr, "s-vid must be in range [1..16777215] \n");
    return 1;
  }
  vni = (((label & 0x0FFF000) << 4) | (label & 0x00000FFF));
  err = br_set_trill_vni(argv[1], argv[2], vni);
  printf("vni %i\n", vni);
  printf("adding vni %i  to interface %s  %s\n", label, argv[2],
         err == 0 ? "suceeded"
                  : "failed !!!\n------	       \nvni could be applied only to "
                    "existant guest vif\n------\n");
  if (err)
    fprintf(stderr, "error adding vni %i on interface %s \n", label, argv[2]);
  return err != 0;
}


x86 assembly (clang, -O0):
<br_cmd_setvni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xea2(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1193 <br_cmd_setvni+0x53>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127e <br_cmd_setvni+0x13e>
cmpl   $0xffffff,-0x18(%rbp)
jg     11aa <br_cmd_setvni+0x6a>
cmpl   $0x1,-0x18(%rbp)
jge    11cd <br_cmd_setvni+0x8d>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127e <br_cmd_setvni+0x13e>
mov    -0x18(%rbp),%eax
and    $0xfff000,%eax
shl    $0x4,%eax
mov    -0x18(%rbp),%ecx
and    $0xfff,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <br_set_trill_vni@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x14(%rbp),%edi
lea    0xe47(%rip),%rcx
lea    0xe37(%rip),%rax
cmp    $0x0,%edi
cmove  %rax,%rcx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     126f <br_cmd_setvni+0x12f>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_cmd_setvni>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xeaa(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1188 <br_cmd_setvni+0x48>
mov    0xc(%rsp),%ebp
lea    -0x1000000(%rbp),%eax
cmp    $0xff000000,%eax
ja     11a9 <br_cmd_setvni+0x69>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
jmp    1198 <br_cmd_setvni+0x58>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1234 <br_cmd_setvni+0xf4>
mov    %ebp,%eax
shl    $0x4,%eax
and    $0xfff0000,%eax
and    $0xfff,%ebp
or     %eax,%ebp
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %ebp,%edx
call   1030 <br_set_trill_vni@plt>
mov    %eax,%r14d
lea    0xe65(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rbx),%rdx
test   %r14d,%r14d
lea    0xe76(%rip),%rax
lea    0xe78(%rip),%rcx
cmove  %rax,%rcx
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     122c <br_cmd_setvni+0xec>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
mov    0x10(%rbx),%rcx
lea    0xe9b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
test   %r14d,%r14d
setne  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"bad vni value\0A\00"
@.str.2 = [39 x i8] c"s-vid must be in range [1..16777215] \0A\00"
@.str.3 = [8 x i8] c"vni %i\0A\00"
@.str.4 = [36 x i8] c"adding vni %i to interface %s %s\0A\00"
@.str.5 = [9 x i8] c"suceeded\00"
@.str.6 = [82 x i8] c"failed !!!\0A------\09 \0Avni could be applied only to existant guest vif\0A------\0A\00"
@.str.7 = [38 x i8] c"error adding vni %i on interface %s \0A\00"
define i32 @br_cmd_setvni(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 3
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %65
17: ; preds = %2
%18 = load i32, i32* %7
%19 = icmp sgt i32 %18, 16777215
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %20, %17
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %65
26: ; preds = %20
%27 = load i32, i32* %7
%28 = and i32 %27, 16773120
%29 = shl i32 %28, 4
%30 = load i32, i32* %7
%31 = and i32 %30, 4095
%32 = or i32 %29, %31
store i32 %32, i32* %8
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i32, i32* %8
%40 = call i32 @br_set_trill_vni(i8* %35, i8* %38, i32 %39)
store i32 %40, i32* %6
%41 = load i32, i32* %8
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0)
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %43, i8* %46, i8* %50)
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %26
%55 = load i32, i32* @stderr
%56 = load i32, i32* %7
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %56, i8* %59)
br label %61
61: ; preds = %54, %26
%62 = load i32, i32* %6
%63 = icmp ne i32 %62, 0
%64 = zext i1 %63 to i32
store i32 %64, i32* %3
br label %65
65: ; preds = %61, %23, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"bad vni value\0A\00"
@.str.2 = [39 x i8] c"s-vid must be in range [1..16777215] \0A\00"
@.str.3 = [8 x i8] c"vni %i\0A\00"
@.str.4 = [36 x i8] c"adding vni %i to interface %s %s\0A\00"
@.str.5 = [9 x i8] c"suceeded\00"
@.str.6 = [82 x i8] c"failed !!!\0A------\09 \0Avni could be applied only to existant guest vif\0A------\0A\00"
@.str.7 = [38 x i8] c"error adding vni %i on interface %s \0A\00"
define i32 @br_cmd_setvni(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %43
12: ; preds = %2
%13 = load i32, i32* %3
%14 = add i32 %13, -16777216
%15 = icmp ult i32 %14, -16777215
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %43
19: ; preds = %12
%20 = shl nuw nsw i32 %13, 4
%21 = and i32 %20, 268369920
%22 = and i32 %13, 4095
%23 = or i32 %21, %22
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @br_set_trill_vni(i8* %25, i8* %27, i32 %23)
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%30 = load i32, i32* %3
%31 = load i8*, i8** %26
%32 = icmp eq i32 %28, 0
%33 = select i1 %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.6, i64 0, i64 0)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %31, i8* %33)
%35 = icmp ne i32 %28, 0
br i1 %35, label %36, label %41
36: ; preds = %19
%37 = load i32, i32* @stderr
%38 = load i32, i32* %3
%39 = load i8*, i8** %26
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %38, i8* %39)
br label %41
41: ; preds = %36, %19
%42 = zext i1 %35 to i32
br label %43
43: ; preds = %41, %16, %9
%44 = phi i32 [ 1, %9 ], [ 1, %16 ], [ %42, %41 ]
ret i32 %44
}