#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int get_chainmask_num(int radio, int *chain_num) {
  FILE *fin;
  int chain_tmp = 0;
  int chain_count = 0;
  char c;
  char str[256] = {0};
  char chain_str[8] = {0};
  char wifi_name[8] = {0};
  char cmd[256] = {0};
  char buf[16] = {0};
  if (0 == radio) {
    strcpy(wifi_name, "wifi0");
  } else if (1 == radio) {
    strcpy(wifi_name, "wifi1");
  }
  sprintf(
      cmd,
      "iwpriv %s get_txchainmask | awk '{gsub(/get_txchainmask:/,\"\");print}' "
      "| awk '{print $2}' > /tmp/chainmask_num",
      wifi_name);
  do {
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
  } while (0);
  fin = fopen("/tmp/chainmask_num", "r");
  if (!fgets(buf, 8, fin)) {
    fclose(fin);
    return -1;
  }
  fclose(fin);
  do {
    printf("\033[1;33;40m");
    printf("rm -f /tmp/chainmask_num");
    printf("\033[0m");
    printf("\n");
    system("rm -f /tmp/chainmask_num");
  } while (0);
  if ((atoi(buf) < 1) || (atoi(buf) > 7)) {
    printf("TxChainMask illegal value\n");
    return -1;
  }
  *chain_num = chain_count;
  return 0;
}


x86 assembly (clang, -O0):
<get_chainmask_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x138(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    1232 <get_chainmask_num+0xa2>
lea    -0x140(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1258 <get_chainmask_num+0xc8>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    1253 <get_chainmask_num+0xc3>
lea    -0x140(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1258 <get_chainmask_num+0xc8>
lea    -0x240(%rbp),%rdi
lea    -0x140(%rbp),%rdx
lea    0xd9f(%rip),%rsi
call   10b0 <sprintf@plt>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
lea    -0x240(%rbp),%rdi
call   1060 <printf@plt>
lea    0xdf4(%rip),%rdi
call   1060 <printf@plt>
lea    0xe21(%rip),%rdi
call   1060 <printf@plt>
lea    -0x240(%rbp),%rdi
call   1050 <system@plt>
lea    0xdb2(%rip),%rdi
lea    0xdce(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x250(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x8,%esi
call   1080 <fgets@plt>
cmp    $0x0,%eax
jne    12f8 <get_chainmask_num+0x168>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138f <get_chainmask_num+0x1ff>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd72(%rip),%rdi
call   1060 <printf@plt>
lea    0xd78(%rip),%rdi
call   1060 <printf@plt>
lea    0xd65(%rip),%rdi
call   1060 <printf@plt>
lea    0xd92(%rip),%rdi
call   1060 <printf@plt>
lea    0xd54(%rip),%rdi
call   1050 <system@plt>
lea    -0x250(%rbp),%rdi
call   10a0 <atoi@plt>
cmp    $0x1,%eax
jl     1367 <get_chainmask_num+0x1d7>
lea    -0x250(%rbp),%rdi
call   10a0 <atoi@plt>
cmp    $0x7,%eax
jle    137f <get_chainmask_num+0x1ef>
lea    0xd37(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138f <get_chainmask_num+0x1ff>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_chainmask_num>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%r14
movq   $0x0,0x8(%rsp)
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)
movaps %xmm0,0x10(%rsp)
test   %edi,%edi
je     123f <get_chainmask_num+0x9f>
cmp    $0x1,%edi
jne    1250 <get_chainmask_num+0xb0>
lea    0xdc9(%rip),%rsi
jmp    1246 <get_chainmask_num+0xa6>
lea    0xdba(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xdb5(%rip),%rsi
lea    0x20(%rsp),%rbp
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   10c0 <sprintf@plt>
lea    0xe0a(%rip),%rdi
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1080 <printf@plt>
lea    0xe01(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
call   1070 <system@plt>
lea    0xdc5(%rip),%rdi
lea    0xde1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%ebp
test   %ebx,%ebx
je     1338 <get_chainmask_num+0x198>
lea    0xd9d(%rip),%rdi
call   1080 <printf@plt>
lea    0xda3(%rip),%rbx
mov    %rbx,%rdi
call   1080 <printf@plt>
lea    0xd8d(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0x10(%rsp),%rdi
call   10b0 <atoi@plt>
add    $0xfffffff8,%eax
cmp    $0xfffffff8,%eax
ja     132f <get_chainmask_num+0x18f>
lea    0xd7d(%rip),%rdi
call   1050 <puts@plt>
jmp    1338 <get_chainmask_num+0x198>
movl   $0x0,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"wifi0\00"
@.str.1 = [6 x i8] c"wifi1\00"
@.str.2 = [110 x i8] c"iwpriv %s get_txchainmask | awk '{gsub(/get_txchainmask:/,\22\22);print}' | awk '{print $2}' > /tmp/chainmask_num\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 = [19 x i8] c"/tmp/chainmask_num\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [25 x i8] c"rm -f /tmp/chainmask_num\00"
@.str.9 = [27 x i8] c"TxChainMask illegal value\0A\00"
define i32 @get_chainmask_num(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca [256 x i8]
%11 = alloca [8 x i8]
%12 = alloca [8 x i8]
%13 = alloca [256 x i8]
%14 = alloca [16 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %7
store i32 0, i32* %8
%15 = bitcast [256 x i8]* %10 to i8*
%16 = bitcast [8 x i8]* %11 to i8*
%17 = bitcast [8 x i8]* %12 to i8*
%18 = bitcast [256 x i8]* %13 to i8*
%19 = bitcast [16 x i8]* %14 to i8*
%20 = load i32, i32* %4
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %32
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp eq i32 1, %26
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31, %22
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%39 = call i32 @printf(i8* %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%43 = call i32 @system(i8* %42)
br label %44
44: ; preds = %36
%45 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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* %45, i32** %6
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = call i32 @fgets(i8* %46, i32 8, i32* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
store i32 -1, i32* %3
br label %75
53: ; preds = %44
%54 = load i32*, i32** %6
%55 = call i32 @fclose(i32* %54)
br label %56
56: ; preds = %53
%57 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %62
62: ; preds = %56
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%64 = call i32 @atoi(i8* %63)
%65 = icmp slt i32 %64, 1
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%68 = call i32 @atoi(i8* %67)
%69 = icmp sgt i32 %68, 7
br i1 %69, label %70, label %72
70: ; preds = %66, %62
%71 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
72: ; preds = %66
%73 = load i32, i32* %8
%74 = load i32*, i32** %5
store i32 %73, i32* %74
store i32 0, i32* %3
br label %75
75: ; preds = %72, %70, %50
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [6 x i8] c"wifi0\00"
@.str.1 = [6 x i8] c"wifi1\00"
@.str.2 = [110 x i8] c"iwpriv %s get_txchainmask | awk '{gsub(/get_txchainmask:/,\22\22);print}' | awk '{print $2}' > /tmp/chainmask_num\00"
@.str.3 = [11 x i8] c"\1B[1;33;40m\00"
@.str.4 = [5 x i8] c"\1B[0m\00"
@.str.6 = [19 x i8] c"/tmp/chainmask_num\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [25 x i8] c"rm -f /tmp/chainmask_num\00"
@str = [26 x i8] c"TxChainMask illegal value\00"
define i32 @get_chainmask_num(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i64
%4 = alloca [256 x i8]
%5 = alloca [16 x i8]
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
switch i32 %0, label %13 [
i32 0, label %10
i32 1, label %9
]
9: ; preds = %2
br label %10
10: ; preds = %2, %9
%11 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = call i32 @strcpy(i8* %6, i8* %11)
br label %13
13: ; preds = %10, %2
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([110 x i8], [110 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* %7)
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @putchar(i32 10)
%19 = call i32 @system(i8* %7)
%20 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 @fgets(i8* %8, i32 8, i32* %20)
%22 = icmp eq i32 %21, 0
%23 = call i32 @fclose(i32* %20)
br i1 %22, label %36, label %24
24: ; preds = %13
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @putchar(i32 10)
%29 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%30 = call i32 @atoi(i8* %8)
%31 = add i32 %30, -8
%32 = icmp ult i32 %31, -7
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %36
35: ; preds = %24
store i32 0, i32* %1
br label %36
36: ; preds = %13, %35, %33
%37 = phi i32 [ -1, %33 ], [ 0, %35 ], [ -1, %13 ]
ret i32 %37
}