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

/* Variables and functions */
int atoi(char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int get_wlan1_channel() {
  int wlan1_channel = 0;
  char channel1[16] = "\0";
  char buffer[128];
  FILE *read_fp;
  int chars_read;
  int ret = 0;
  memset(buffer, 0, sizeof(buffer));
  read_fp = popen("iwlist wlan1 channel | grep \"Current Frequency:\" | awk "
                  "'{print $5}' | awk -F')' '{print $1}'",
                  "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), sizeof(buffer) - 1, read_fp);
    if (chars_read > 0) {
      wlan1_channel = atoi(buffer);
      ret = wlan1_channel;
    } else {
      ret = 0;
    }
    pclose(read_fp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_wlan1_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x0,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe6a(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     121a <get_wlan1_channel+0xca>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7f,%edx
call   1030 <fread@plt>
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xac(%rbp)
jle    1204 <get_wlan1_channel+0xb4>
lea    -0xa0(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xb0(%rbp)
jmp    120e <get_wlan1_channel+0xbe>
movl   $0x0,-0xb0(%rbp)
mov    -0xa8(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0xb0(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wlan1_channel>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe8f(%rip),%rdi
lea    0xee5(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11b4 <get_wlan1_channel+0x64>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x7f,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11aa <get_wlan1_channel+0x5a>
mov    %rsp,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
jmp    11ac <get_wlan1_channel+0x5c>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [93 x i8] c"iwlist wlan1 channel | grep \22Current Frequency:\22 | awk '{print $5}' | awk -F')' '{print $1}'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_wlan1_channel() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [16 x i8]* %2 to i8*
store i32 0, i32* %6
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 128)
%10 = call i32* @popen(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %27
13: ; preds = %0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32 @fread(i8* %14, i32 1, i32 127, i32* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %1
%22 = load i32, i32* %1
store i32 %22, i32* %6
br label %24
23: ; preds = %13
store i32 0, i32* %6
br label %24
24: ; preds = %23, %19
%25 = load i32*, i32** %4
%26 = call i32 @pclose(i32* %25)
br label %27
27: ; preds = %24, %0
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
@.str = [93 x i8] c"iwlist wlan1 channel | grep \22Current Frequency:\22 | awk '{print $5}' | awk -F')' '{print $1}'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_wlan1_channel() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 128)
%4 = call i32* @popen(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = call i32 @fread(i8* %2, i32 1, i32 127, i32* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @atoi(i8* %2)
br label %11
11: ; preds = %6, %9
%12 = phi i32 [ %10, %9 ], [ 0, %6 ]
%13 = call i32 @pclose(i32* %4)
br label %14
14: ; preds = %11, %0
%15 = phi i32 [ %12, %11 ], [ 0, %0 ]
ret i32 %15
}