#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 convert_vap_id(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int nvram_get_vap_status(int, int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int set_security_open(int radio, int vap_id) {
  int ret = 0;
  int unit = 0;
  char pidname[64] = {0};
  int updown = 0;
  unit = convert_vap_id(radio, vap_id);
  sprintf(pidname, "%s%d.pid", "/var/run/hostapd_ath", unit);
  do {
    char *cmd = (char *)malloc(128 * sizeof(char));
    sprintf(cmd, "kill `cat %s`", pidname);
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
    free(cmd);
  } while (0);
  ret = nvram_get_vap_status(radio, vap_id, &updown);
  if (-1 == ret) {
    fprintf(stderr, "Get VAP status failure!\n");
    return -1;
  }
  if (updown) {
    sleep(1);
    do {
      char *cmd = (char *)malloc(128 * sizeof(char));
      sprintf(cmd, " ifconfig ath%d up", unit);
      printf("\033[1;33;40m");
      printf(cmd);
      printf("\033[0m");
      printf("\n");
      system(cmd);
      free(cmd);
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_security_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <convert_vap_id@plt>
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xe0e(%rip),%rsi
lea    0xe10(%rip),%rdx
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1060 <printf@plt>
lea    0xdf7(%rip),%rdi
call   1060 <printf@plt>
lea    0xe07(%rip),%rdi
call   1060 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1050 <system@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x64(%rbp),%rdx
call   1080 <nvram_get_vap_status@plt>
mov    %eax,-0x10(%rbp)
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
jne    12a4 <set_security_open+0x104>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1326 <set_security_open+0x186>
cmpl   $0x0,-0x64(%rbp)
je     131f <set_security_open+0x17f>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    0xd4a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1060 <printf@plt>
lea    0xd40(%rip),%rdi
call   1060 <printf@plt>
lea    0xd50(%rip),%rdi
call   1060 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1050 <system@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
jmp    131f <set_security_open+0x17f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_security_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %esi,%r12d
mov    %edi,%r13d
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
call   1050 <convert_vap_id@plt>
mov    %eax,%r14d
lea    0xe1e(%rip),%rsi
lea    0xe20(%rip),%rdx
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
lea    0xe0d(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xe07(%rip),%rdi
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1070 <printf@plt>
lea    0xdfe(%rip),%rdi
call   1070 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
mov    %r12d,%esi
call   1080 <nvram_get_vap_status@plt>
cmp    $0xffffffff,%eax
je     12e2 <set_security_open+0x142>
cmpl   $0x0,0xc(%rsp)
je     12fd <set_security_open+0x15d>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xdbf(%rip),%rsi
xor    %r15d,%r15d
mov    %rax,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xd7f(%rip),%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1070 <printf@plt>
lea    0xd76(%rip),%rdi
call   1070 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12fd <set_security_open+0x15d>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s%d.pid\00"
@.str.1 = [21 x i8] c"/var/run/hostapd_ath\00"
@.str.2 = [14 x i8] c"kill `cat %s`\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"
@stderr = global i32 0
@.str.6 = [25 x i8] c"Get VAP status failure!\0A\00"
@.str.7 = [19 x i8] c" ifconfig ath%d up\00"
define i32 @set_security_open(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = bitcast [64 x i8]* %8 to i8*
store i32 0, i32* %9
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @convert_vap_id(i32 %13, i32 %14)
store i32 %15, i32* %7
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%17 = load i32, i32* %7
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %2
%20 = call i64 @malloc(i32 128)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%26 = load i8*, i8** %10
%27 = call i32 @printf(i8* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = load i8*, i8** %10
%31 = call i32 @system(i8* %30)
%32 = load i8*, i8** %10
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %19
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @nvram_get_vap_status(i32 %35, i32 %36, i32* %9)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp eq i32 -1, %38
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
43: ; preds = %34
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %64
46: ; preds = %43
%47 = call i32 @sleep(i32 1)
br label %48
48: ; preds = %46
%49 = call i64 @malloc(i32 128)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %11
%51 = load i8*, i8** %11
%52 = load i32, i32* %7
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%55 = load i8*, i8** %11
%56 = call i32 @printf(i8* %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%59 = load i8*, i8** %11
%60 = call i32 @system(i8* %59)
%61 = load i8*, i8** %11
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %48
br label %64
64: ; preds = %63, %43
store i32 0, i32* %3
br label %65
65: ; preds = %64, %40
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s%d.pid\00"
@.str.1 = [21 x i8] c"/var/run/hostapd_ath\00"
@.str.2 = [14 x i8] c"kill `cat %s`\00"
@.str.3 = [11 x i8] c"\1B[1;33;40m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@stderr = global i32 0
@.str.6 = [25 x i8] c"Get VAP status failure!\0A\00"
@.str.7 = [19 x i8] c" ifconfig ath%d up\00"
define i32 @set_security_open(i32 %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32 @convert_vap_id(i32 %0, i32 %1)
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i64 @malloc(i32 128)
%10 = inttoptr i64 %9 to i8*
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @printf(i8* dereferenceable(1) %10)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @putchar(i32 10)
%16 = call i32 @system(i8* %10)
%17 = call i32 @free(i8* %10)
%18 = call i32 @nvram_get_vap_status(i32 %0, i32 %1, i32* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %37
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 0
br i1 %25, label %37, label %26
26: ; preds = %23
%27 = call i32 @sleep(i32 1)
%28 = call i64 @malloc(i32 128)
%29 = inttoptr i64 %28 to i8*
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %7)
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @printf(i8* dereferenceable(1) %29)
%33 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @putchar(i32 10)
%35 = call i32 @system(i8* %29)
%36 = call i32 @free(i8* %29)
br label %37
37: ; preds = %23, %26, %20
%38 = phi i32 [ -1, %20 ], [ 0, %26 ], [ 0, %23 ]
ret i32 %38
}