#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 construct_vap(char *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ nvram_get_ap_beacon_interval(int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ system(char *);
int set_beacon_interval(int radio) {
  int ret;
  int beacon_interval;
  char vap_name[8] = {0};
  char cmd[128] = {0};
  nvram_get_ap_beacon_interval(radio, &beacon_interval);
  if (beacon_interval < 100 || beacon_interval > 1000) {
    printf("ERRO:Beacon interval is out of region\n");
    return -1;
  }
  ret = construct_vap(vap_name, radio, 0, 0);
  if (-1 == ret) {
    printf("ERROR:Construct VAP failure!\n");
    return -1;
  }
  sprintf(cmd, "iwpriv %s bintval %d", vap_name, beacon_interval);
  do {
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<set_beacon_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <nvram_get_ap_beacon_interval@plt>
cmpl   $0x64,-0x10(%rbp)
jl     11b4 <set_beacon_interval+0x54>
cmpl   $0x3e8,-0x10(%rbp)
jle    11cc <set_beacon_interval+0x6c>
lea    0xe45(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <set_beacon_interval+0x102>
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <construct_vap@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    1205 <set_beacon_interval+0xa5>
lea    0xe33(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1262 <set_beacon_interval+0x102>
lea    -0xa0(%rbp),%rdi
lea    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe2b(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe34(%rip),%rdi
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1060 <printf@plt>
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_beacon_interval>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x4(%rsp),%rsi
call   1060 <nvram_get_ap_beacon_interval@plt>
mov    $0xfffffc17,%eax
add    0x4(%rsp),%eax
cmp    $0xfffffc7a,%eax
ja     11d5 <set_beacon_interval+0x65>
lea    0xe6f(%rip),%rdi
jmp    1244 <set_beacon_interval+0xd4>
lea    0x8(%rsp),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <construct_vap@plt>
cmp    $0xffffffff,%eax
je     123d <set_beacon_interval+0xcd>
mov    0x4(%rsp),%ecx
lea    0xe09(%rip),%rsi
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1090 <sprintf@plt>
lea    0xe05(%rip),%rdi
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1080 <printf@plt>
lea    0xdfc(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
call   1070 <system@plt>
jmp    124e <set_beacon_interval+0xde>
lea    0xde1(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"ERRO:Beacon interval is out of region\0A\00"
@.str.1 = [30 x i8] c"ERROR:Construct VAP failure!\0A\00"
@.str.2 = [21 x i8] c"iwpriv %s bintval %d\00"
@.str.3 = [11 x i8] c"\1B[1;33;40m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @set_beacon_interval(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca [128 x i8]
store i32 %0, i32* %3
%8 = bitcast [8 x i8]* %6 to i8*
%9 = bitcast [128 x i8]* %7 to i8*
%10 = load i32, i32* %3
%11 = call i32 @nvram_get_ap_beacon_interval(i32 %10, i32* %5)
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 100
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 1000
br i1 %16, label %17, label %19
17: ; preds = %14, %1
%18 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
19: ; preds = %14
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @construct_vap(i8* %20, i32 %21, i32 0, i32 0)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
27: ; preds = %19
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%35 = call i32 @printf(i8* %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%39 = call i32 @system(i8* %38)
br label %40
40: ; preds = %32
store i32 0, i32* %2
br label %41
41: ; preds = %40, %25, %17
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str.2 = [21 x i8] c"iwpriv %s bintval %d\00"
@.str.3 = [11 x i8] c"\1B[1;33;40m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@str = [29 x i8] c"ERROR:Construct VAP failure!\00"
@str.6 = [38 x i8] c"ERRO:Beacon interval is out of region\00"
define i32 @set_beacon_interval(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [128 x i8]
%5 = bitcast i32* %2 to i8*
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = call i32 @nvram_get_ap_beacon_interval(i32 %0, i32* %2)
%9 = load i32, i32* %2
%10 = add i32 %9, -1001
%11 = icmp ult i32 %10, -901
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
br label %27
14: ; preds = %1
%15 = call i32 @construct_vap(i8* %6, i32 %0, i32 0, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %27
19: ; preds = %14
%20 = load i32, i32* %2
%21 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %20)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @printf(i8* %7)
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @putchar(i32 10)
%26 = call i32 @system(i8* %7)
br label %27
27: ; preds = %19, %17, %12
%28 = phi i32 [ -1, %12 ], [ -1, %17 ], [ 0, %19 ]
ret i32 %28
}