#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 /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int construct_vap(char *, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ find_pattern_from_str(char *, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readline(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int get_vap_status(int radio, int vapid, int mode, int *vap_status) {
  int ret;
  char cmd[128] = {0};
  char vap_name[8] = {0};
  FILE *fin;
  char str[256] = {0}, c;
  ret = construct_vap(vap_name, radio, vapid, mode);
  if (-1 == ret) {
    printf("ERROR:Construct VAP Failure!\n");
    return -1;
  }
  *vap_status = 0;
  sprintf(cmd, "ifconfig | grep -rn %s > /tmp/vap_link_status", vap_name);
  do {
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
  } while (0);
  fin = fopen("/tmp/vap_link_status", "r");
  while ((c = fgetc(fin)) != EOF) {
    ungetc(c, fin);
    readline(str, fin);
    if (find_pattern_from_str(str, vap_name) == 0) {
      *vap_status = 1;
      break;
    }
  }
  fclose(fin);
  do {
    printf("\033[1;33;40m");
    printf("rm -f /tmp/vap_link_status");
    printf("\033[0m");
    printf("\n");
    system("rm -f /tmp/vap_link_status");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<get_vap_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0xa8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x1b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0xa8(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <construct_vap@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    123f <get_vap_status+0x8f>
lea    0xdd2(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1388 <get_vap_status+0x1d8>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0xa0(%rbp),%rdi
lea    -0xa8(%rbp),%rdx
lea    0xdc0(%rip),%rsi
call   10d0 <sprintf@plt>
lea    0xde2(%rip),%rdi
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1060 <printf@plt>
lea    0xdd5(%rip),%rdi
call   1060 <printf@plt>
lea    0xd8e(%rip),%rdi
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <system@plt>
lea    0xd91(%rip),%rdi
lea    0xdaf(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0x1b1(%rbp)
movsbl %al,%eax
mov    0x2d13(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1339 <get_vap_status+0x189>
mov    -0x1b1(%rbp),%al
mov    -0xb0(%rbp),%rsi
movsbl %al,%edi
call   10a0 <ungetc@plt>
lea    -0x1b0(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
call   1080 <readline@plt>
lea    -0x1b0(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
call   10b0 <find_pattern_from_str@plt>
cmp    $0x0,%rax
jne    1334 <get_vap_status+0x184>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1339 <get_vap_status+0x189>
jmp    12b9 <get_vap_status+0x109>
mov    -0xb0(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd00(%rip),%rdi
call   1060 <printf@plt>
lea    0xd06(%rip),%rdi
call   1060 <printf@plt>
lea    0xcf3(%rip),%rdi
call   1060 <printf@plt>
lea    0xcac(%rip),%rdi
call   1060 <printf@plt>
lea    0xce2(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_vap_status>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x190,%rsp
mov    %rcx,%r14
mov    %edx,%ecx
mov    %esi,%edx
mov    %edi,%esi
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)
movq   $0x0,0x8(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <construct_vap@plt>
cmp    $0xffffffff,%eax
je     13a0 <get_vap_status+0x1e0>
movl   $0x0,(%r14)
lea    0xd4f(%rip),%rsi
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rdx
call   10e0 <sprintf@plt>
lea    0xd61(%rip),%rdi
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1080 <printf@plt>
lea    0xd58(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xd1a(%rip),%rdi
lea    0xd38(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
mov    0x2cd3(%rip),%r13
lea    0x90(%rsp),%r12
nopl   (%rax)
mov    %rbx,%rdi
call   10a0 <fgetc@plt>
cmp    0x0(%r13),%al
je     135b <get_vap_status+0x19b>
movsbl %al,%edi
mov    %rbx,%rsi
call   10b0 <ungetc@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <readline@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   10c0 <find_pattern_from_str@plt>
test   %rax,%rax
jne    1320 <get_vap_status+0x160>
movl   $0x1,(%r14)
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xcc4(%rip),%rdi
call   1080 <printf@plt>
lea    0xcca(%rip),%rbx
mov    %rbx,%rdi
call   1080 <printf@plt>
lea    0xcb4(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
xor    %eax,%eax
jmp    13b1 <get_vap_status+0x1f1>
lea    0xcb4(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x190,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"ERROR:Construct VAP Failure!\0A\00"
@.str.1 = [46 x i8] c"ifconfig | grep -rn %s > /tmp/vap_link_status\00"
@.str.2 = [11 x i8] c"\1B[1;33;40m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [21 x i8] c"/tmp/vap_link_status\00"
@.str.6 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.7 = [27 x i8] c"rm -f /tmp/vap_link_status\00"
define i32 @get_vap_status(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [128 x i8]
%12 = alloca [8 x i8]
%13 = alloca i32*
%14 = alloca [256 x i8]
%15 = alloca i8
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%16 = bitcast [128 x i8]* %11 to i8*
%17 = bitcast [8 x i8]* %12 to i8*
%18 = bitcast [256 x i8]* %14 to i8*
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @construct_vap(i8* %19, i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %74
28: ; preds = %4
%29 = load i32*, i32** %9
store i32 0, i32* %29
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%36 = call i32 @printf(i8* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%40 = call i32 @system(i8* %39)
br label %41
41: ; preds = %33
%42 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %42, i32** %13
br label %43
43: ; preds = %63, %41
%44 = load i32*, i32** %13
%45 = call signext i8 @fgetc(i32* %44)
store i8 %45, i8* %15
%46 = sext i8 %45 to i32
%47 = load i8, i8* @EOF
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %46, %48
br i1 %49, label %50, label %64
50: ; preds = %43
%51 = load i8, i8* %15
%52 = load i32*, i32** %13
%53 = call i32 @ungetc(i8 signext %51, i32* %52)
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%55 = load i32*, i32** %13
%56 = call i32 @readline(i8* %54, i32* %55)
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%59 = call i64 @find_pattern_from_str(i8* %57, i8* %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %50
%62 = load i32*, i32** %9
store i32 1, i32* %62
br label %64
63: ; preds = %50
br label %43
64: ; preds = %61, %43
%65 = load i32*, i32** %13
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %64
%68 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%69 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%70 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%71 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %67
store i32 0, i32* %5
br label %74
74: ; preds = %73, %26
%75 = load i32, i32* %5
ret i32 %75
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"ifconfig | grep -rn %s > /tmp/vap_link_status\00"
@.str.2 = [11 x i8] c"\1B[1;33;40m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.5 = [21 x i8] c"/tmp/vap_link_status\00"
@.str.6 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.7 = [27 x i8] c"rm -f /tmp/vap_link_status\00"
@str = [29 x i8] c"ERROR:Construct VAP Failure!\00"
define i32 @get_vap_status(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca [128 x i8]
%6 = alloca i64
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = call i32 @construct_vap(i8* %9, i32 %0, i32 %1, i32 %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %40
15: ; preds = %4
store i32 0, i32* %3
%16 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* %8)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @putchar(i32 10)
%21 = call i32 @system(i8* %8)
%22 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %27, %15
%24 = call signext i8 @fgetc(i32* %22)
%25 = load i8, i8* @EOF
%26 = icmp eq i8 %24, %25
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = call i32 @ungetc(i8 signext %24, i32* %22)
%29 = call i32 @readline(i8* %10, i32* %22)
%30 = call i64 @find_pattern_from_str(i8* %10, i8* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %23
32: ; preds = %27
store i32 1, i32* %3
br label %33
33: ; preds = %23, %32
%34 = call i32 @fclose(i32* %22)
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @putchar(i32 10)
%39 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %33, %13
%41 = phi i32 [ -1, %13 ], [ 0, %33 ]
ret i32 %41
}