#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 */
int convert_vap_id(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int judge_vap_up(int radio, int vap_id) {
  int unit = 0;
  char buf[32] = {0};
  FILE *fp = NULL;
  char filename[64] = {0};
  unit = convert_vap_id(radio, vap_id);
  sprintf(filename, "%s%d.conf.pid", "/tmp/ath", unit);
  do {
    char *cmd = (char *)malloc(128 * sizeof(char));
    sprintf(cmd, "ifconfig | grep ath%d > /tmp/judge_ath", unit);
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
    free(cmd);
  } while (0);
  if ((fp = fopen("/tmp/judge_ath", "r")) != NULL) {
    fread(buf, 1, 32, fp);
    printf("\n=====================buf=%s,len=%d=====================\n", buf,
           strlen(buf));
    fclose(fp);
    fp = NULL;
    if (strlen(buf) > 3) {
      printf("ath%d is up\n", unit);
      return 0;
    } else {
      printf("ath%d is down\n", unit);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<judge_vap_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10a0 <memset@plt>
movq   $0x0,-0x38(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   10a0 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <convert_vap_id@plt>
mov    %eax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%ecx
lea    0xdf4(%rip),%rsi
lea    0xdfb(%rip),%rdx
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    $0x80,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x88(%rbp),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x88(%rbp),%rdi
call   1080 <system@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
lea    0xd95(%rip),%rdi
lea    0xdad(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1353 <judge_vap_up+0x1a3>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1040 <fread@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x3,%eax
jle    1336 <judge_vap_up+0x186>
mov    -0x10(%rbp),%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135a <judge_vap_up+0x1aa>
mov    -0x10(%rbp),%esi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135a <judge_vap_up+0x1aa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<judge_vap_up>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1060 <convert_vap_id@plt>
mov    %eax,%r14d
lea    0xe2d(%rip),%rsi
lea    0xe34(%rip),%rdx
xor    %ebp,%ebp
lea    0x20(%rsp),%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    $0x80,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
lea    0xe19(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   10d0 <sprintf@plt>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1090 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xddd(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12d0 <judge_vap_up+0x120>
mov    %rax,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1080 <strlen@plt>
lea    0xdc3(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rbp,%rdi
call   1080 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
setl   %bpl
lea    0xdd1(%rip),%rax
lea    0xdd7(%rip),%rdi
cmovge %rax,%rdi
neg    %ebp
mov    %r14d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %ebp,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%s%d.conf.pid\00"
@.str.1 = [9 x i8] c"/tmp/ath\00"
@.str.2 = [39 x i8] c"ifconfig | grep ath%d > /tmp/judge_ath\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"
@.str.6 = [15 x i8] c"/tmp/judge_ath\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [58 x i8] c"\0A=====================buf=%s,len=%d=====================\0A\00"
@.str.9 = [13 x i8] c"ath%d is up\0A\00"
@.str.10 = [15 x i8] c"ath%d is down\0A\00"
define i32 @judge_vap_up(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i32*
%9 = alloca [64 x i8]
%10 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%11 = bitcast [32 x i8]* %7 to i8*
store i32* null, i32** %8
%12 = bitcast [64 x i8]* %9 to i8*
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @convert_vap_id(i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%17 = load i32, i32* %6
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 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 = load i32, i32* %6
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%26 = load i8*, i8** %10
%27 = call i32 (i8*, ...) @printf(i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @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 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %35, i32** %8
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %56
37: ; preds = %34
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%39 = load i32*, i32** %8
%40 = call i32 @fread(i8* %38, i32 1, i32 32, i32* %39)
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i8* %41, i32 %43)
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
store i32* null, i32** %8
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = icmp sgt i32 %48, 3
br i1 %49, label %50, label %53
50: ; preds = %37
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 %51)
store i32 0, i32* %3
br label %57
53: ; preds = %37
%54 = load i32, i32* %6
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %54)
store i32 -1, i32* %3
br label %57
56: ; preds = %34
store i32 0, i32* %3
br label %57
57: ; preds = %56, %53, %50
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [14 x i8] c"%s%d.conf.pid\00"
@.str.1 = [9 x i8] c"/tmp/ath\00"
@.str.2 = [39 x i8] c"ifconfig | grep ath%d > /tmp/judge_ath\00"
@.str.3 = [11 x i8] c"\1B[1;33;40m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.6 = [15 x i8] c"/tmp/judge_ath\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [58 x i8] c"\0A=====================buf=%s,len=%d=====================\0A\00"
@.str.9 = [13 x i8] c"ath%d is up\0A\00"
@.str.10 = [15 x i8] c"ath%d is down\0A\00"
define i32 @judge_vap_up(i32 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @convert_vap_id(i32 %0, i32 %1)
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i64 @malloc(i32 128)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %10)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @putchar(i32 10)
%16 = tail call i32 @system(i8* %10)
%17 = tail call i32 @free(i8* %10)
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %31, label %20
20: ; preds = %2
%21 = call i32 @fread(i8* %5, i32 1, i32 32, i32* %18)
%22 = call i32 @strlen(i8* %5)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i8* %5, i32 %22)
%24 = call i32 @fclose(i32* %18)
%25 = call i32 @strlen(i8* %5)
%26 = icmp sgt i32 %25, 3
%27 = select i1 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0)
%28 = xor i1 %26, true
%29 = sext i1 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %27, i32 %7)
br label %31
31: ; preds = %20, %2
%32 = phi i32 [ 0, %2 ], [ %29, %20 ]
ret i32 %32
}