#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 atoi(char *);
int construct_vap(char *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ nvram_get_wlan_mode(int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readline(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy_delspace(char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int get_wlan_rate(int radio, int *rate) {
  char str[256] = {0}, c;
  char rate_s[8] = {0};
  char vap_name[8];
  int wlan_mode;
  int ret;
  FILE *fin = NULL;
  char cmd[256];
  *rate = 0;
  nvram_get_wlan_mode(radio, &wlan_mode);
  ret = construct_vap(vap_name, radio, 0, wlan_mode);
  if (-1 == ret) {
    printf("ERROR:Get VAP Name Failure!\n");
    return -1;
  }
  sprintf(cmd,
          "iwconfig %s | grep Rate | awk '{print substr($2,6,3)}' > "
          "/tmp/current_wlan_rate",
          vap_name);
  do {
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
  } while (0);
  fin = fopen("/tmp/current_wlan_rate", "r");
  while ((c = fgetc(fin)) != EOF) {
    ungetc(c, fin);
    readline(str, fin);
    strcpy_delspace(str, rate_s);
    *rate = atoi(rate_s);
  }
  fclose(fin);
  do {
    printf("\033[1;33;40m");
    printf("rm -f /tmp/current_wlan_rate");
    printf("\033[0m");
    printf("\n");
    system("rm -f /tmp/current_wlan_rate");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<get_wlan_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x119(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
movq   $0x0,-0x138(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0x128(%rbp),%rsi
call   10c0 <nvram_get_wlan_mode@plt>
lea    -0x121(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x128(%rbp),%ecx
xor    %edx,%edx
call   1040 <construct_vap@plt>
mov    %eax,-0x12c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x12c(%rbp),%eax
jne    1272 <get_wlan_rate+0xa2>
lea    0xd9f(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <get_wlan_rate+0x1dc>
lea    -0x240(%rbp),%rdi
lea    -0x121(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   10f0 <sprintf@plt>
lea    0xdda(%rip),%rdi
call   1070 <printf@plt>
lea    -0x240(%rbp),%rdi
call   1070 <printf@plt>
lea    0xdcd(%rip),%rdi
call   1070 <printf@plt>
lea    0xd64(%rip),%rdi
call   1070 <printf@plt>
lea    -0x240(%rbp),%rdi
call   1060 <system@plt>
lea    0xd87(%rip),%rdi
lea    0xda7(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   10a0 <fgetc@plt>
mov    %al,-0x111(%rbp)
movsbl %al,%eax
mov    0x2cea(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     135d <get_wlan_rate+0x18d>
mov    -0x111(%rbp),%al
mov    -0x138(%rbp),%rsi
movsbl %al,%edi
call   10b0 <ungetc@plt>
lea    -0x110(%rbp),%rdi
mov    -0x138(%rbp),%rsi
call   1090 <readline@plt>
lea    -0x110(%rbp),%rdi
lea    -0x119(%rbp),%rsi
call   1030 <strcpy_delspace@plt>
lea    -0x119(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12e2 <get_wlan_rate+0x112>
mov    -0x138(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xcfd(%rip),%rdi
call   1070 <printf@plt>
lea    0xd03(%rip),%rdi
call   1070 <printf@plt>
lea    0xcf0(%rip),%rdi
call   1070 <printf@plt>
lea    0xc87(%rip),%rdi
call   1070 <printf@plt>
lea    0xcdf(%rip),%rdi
call   1060 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wlan_rate>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x220,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xorps  %xmm0,%xmm0
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)
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)
movq   $0x0,0x10(%rsp)
movl   $0x0,(%rsi)
lea    0xc(%rsp),%rsi
call   10d0 <nvram_get_wlan_mode@plt>
mov    0xc(%rsp),%ecx
lea    0x18(%rsp),%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <construct_vap@plt>
cmp    $0xffffffff,%eax
je     139f <get_wlan_rate+0x1bf>
lea    0xd5f(%rip),%rsi
lea    0x120(%rsp),%rbx
lea    0x18(%rsp),%rdx
mov    %rbx,%rdi
call   1100 <sprintf@plt>
lea    0xd93(%rip),%rdi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1090 <printf@plt>
lea    0xd8a(%rip),%rdi
call   1090 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1080 <system@plt>
lea    0xd4a(%rip),%rdi
lea    0xd6a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <fgetc@plt>
mov    0x2cdb(%rip),%r13
cmp    0x0(%r13),%al
je     135a <get_wlan_rate+0x17a>
lea    0x20(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   (%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   10c0 <ungetc@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <readline@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy_delspace@plt>
mov    %r12,%rdi
call   10f0 <atoi@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   10b0 <fgetc@plt>
cmp    0x0(%r13),%al
jne    1320 <get_wlan_rate+0x140>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xce7(%rip),%rdi
call   1090 <printf@plt>
lea    0xced(%rip),%rbx
mov    %rbx,%rdi
call   1090 <printf@plt>
lea    0xcd7(%rip),%rdi
call   1090 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1080 <system@plt>
xor    %eax,%eax
jmp    13b0 <get_wlan_rate+0x1d0>
lea    0xcd9(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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