#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*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int start_hostapd(int radio, int vap_id) {
  int unit = 0, ret = 0;
  char filename[64] = {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) {
    sprintf(filename, "%s%d.conf", "/tmp/ath", unit);
    do {
      char *cmd = (char *)malloc(128 * sizeof(char));
      sprintf(cmd, "hostapd -B %s -P %s", filename, pidname);
      printf("\033[1;33;40m");
      printf(cmd);
      printf("\033[0m");
      printf("\n");
      system(cmd);
      free(cmd);
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<start_hostapd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%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>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
movl   $0x0,-0xa4(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <convert_vap_id@plt>
mov    %eax,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%ecx
lea    0xe05(%rip),%rsi
lea    0xe07(%rip),%rdx
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    0xdef(%rip),%rdi
call   1060 <printf@plt>
mov    -0xb0(%rbp),%rdi
call   1060 <printf@plt>
lea    0xde2(%rip),%rdi
call   1060 <printf@plt>
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
mov    -0xb0(%rbp),%rdi
call   1050 <system@plt>
mov    -0xb0(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0xa4(%rbp),%rdx
call   1080 <nvram_get_vap_status@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    12c2 <start_hostapd+0x132>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1370 <start_hostapd+0x1e0>
cmpl   $0x0,-0xa4(%rbp)
je     1369 <start_hostapd+0x1d9>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%ecx
lea    0xd78(%rip),%rsi
lea    0xd7b(%rip),%rdx
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    0xd09(%rip),%rdi
call   1060 <printf@plt>
mov    -0xb8(%rbp),%rdi
call   1060 <printf@plt>
lea    0xcfc(%rip),%rdi
call   1060 <printf@plt>
lea    0xd0c(%rip),%rdi
call   1060 <printf@plt>
mov    -0xb8(%rbp),%rdi
call   1050 <system@plt>
mov    -0xb8(%rbp),%rdi
call   1030 <free@plt>
jmp    1369 <start_hostapd+0x1d9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_hostapd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %esi,%r12d
mov    %edi,%r13d
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)
movl   $0x0,0xc(%rsp)
call   1050 <convert_vap_id@plt>
mov    %eax,%r15d
lea    0xe14(%rip),%rsi
lea    0xe16(%rip),%rdx
xor    %r14d,%r14d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xe03(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xdfd(%rip),%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1070 <printf@plt>
lea    0xdf4(%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>
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
mov    %r12d,%esi
call   1080 <nvram_get_vap_status@plt>
cmp    $0xffffffff,%eax
je     130b <start_hostapd+0x17b>
cmpl   $0x0,0xc(%rsp)
je     1326 <start_hostapd+0x196>
lea    0xdc8(%rip),%rsi
lea    0xdcb(%rip),%rdx
xor    %r14d,%r14d
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15d,%ecx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    $0x80,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xdab(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xd56(%rip),%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1070 <printf@plt>
lea    0xd4d(%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    1326 <start_hostapd+0x196>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x98,%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 = [10 x i8] c"%s%d.conf\00"
@.str.8 = [9 x i8] c"/tmp/ath\00"
@.str.9 = [20 x i8] c"hostapd -B %s -P %s\00"
define i32 @start_hostapd(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 [64 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%13 = bitcast [64 x i8]* %8 to i8*
%14 = bitcast [64 x i8]* %9 to i8*
store i32 0, i32* %10
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @convert_vap_id(i32 %15, i32 %16)
store i32 %17, i32* %6
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %18, 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 %19)
br label %21
21: ; preds = %2
%22 = call i64 @malloc(i32 128)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%28 = load i8*, i8** %11
%29 = call i32 @printf(i8* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = load i8*, i8** %11
%33 = call i32 @system(i8* %32)
%34 = load i8*, i8** %11
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %21
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @nvram_get_vap_status(i32 %37, i32 %38, i32* %10)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp eq i32 -1, %40
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
45: ; preds = %36
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %69
48: ; preds = %45
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%50 = load i32, i32* %6
%51 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %48
%53 = call i64 @malloc(i32 128)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %12
%55 = load i8*, i8** %12
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%58 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %56, i8* %57)
%59 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%60 = load i8*, i8** %12
%61 = call i32 @printf(i8* %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%64 = load i8*, i8** %12
%65 = call i32 @system(i8* %64)
%66 = load i8*, i8** %12
%67 = call i32 @free(i8* %66)
br label %68
68: ; preds = %52
br label %69
69: ; preds = %68, %45
store i32 0, i32* %3
br label %70
70: ; preds = %69, %42
%71 = load i32, i32* %3
ret i32 %71
}

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 = [10 x i8] c"%s%d.conf\00"
@.str.8 = [9 x i8] c"/tmp/ath\00"
@.str.9 = [20 x i8] c"hostapd -B %s -P %s\00"
define i32 @start_hostapd(i32 %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = tail call i32 @convert_vap_id(i32 %0, i32 %1)
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, 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 %9)
%11 = tail call i64 @malloc(i32 128)
%12 = inttoptr i64 %11 to i8*
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) %12)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @putchar(i32 10)
%18 = call i32 @system(i8* %12)
%19 = call i32 @free(i8* %12)
%20 = call i32 @nvram_get_vap_status(i32 %0, i32 %1, i32* %5)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %39
25: ; preds = %2
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %25
%29 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %9)
%30 = call i64 @malloc(i32 128)
%31 = inttoptr i64 %30 to i8*
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %6, i8* %7)
%33 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @printf(i8* dereferenceable(1) %31)
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @putchar(i32 10)
%37 = call i32 @system(i8* %31)
%38 = call i32 @free(i8* %31)
br label %39
39: ; preds = %25, %28, %22
%40 = phi i32 [ -1, %22 ], [ 0, %28 ], [ 0, %25 ]
ret i32 %40
}