#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(unsigned char *, char *);
int /*<<< orphan*/ sprintf(unsigned char *, char *, int);
int set_channel(int channel) {
  int result;
  int result_i;
  FILE *fp;
  unsigned char result_code[10];
  unsigned char wlanctl_cmd[100];
  sprintf(wlanctl_cmd,
          "wlanctl-ng wlan0 lnxreq_wlansniff channel=%d enable=true", channel);
  fp = popen(wlanctl_cmd, "r");
  if (fp < 0) {
    perror("Could not execute wlanctl-ng");
    exit(0);
  }
  result = fscanf(fp, "message=%c", &result_i);
  if ((result < 0) || (result == 0)) {
    perror("Could not put into promiscuous mode!");
    exit(0);
  }
  pclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<set_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe81(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    11b9 <set_channel+0x59>
lea    0xe8e(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11e4 <set_channel+0x84>
cmpl   $0x0,-0x8(%rbp)
jne    11f7 <set_channel+0x97>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x8(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_channel>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    %edi,%edx
lea    0xe91(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
mov    %rax,%rbx
lea    0xea6(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %eax,%eax
jle    11b9 <set_channel+0x59>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"wlanctl-ng wlan0 lnxreq_wlansniff channel=%d enable=true\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Could not execute wlanctl-ng\00"
@.str.3 = [11 x i8] c"message=%c\00"
@.str.4 = [37 x i8] c"Could not put into promiscuous mode!\00"
define i32 @set_channel(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [10 x i8]
%7 = alloca [100 x i8]
store i32 %0, i32* %2
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = call i32* @popen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ult i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %1
%19 = load i32*, i32** %5
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %4)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23, %18
%27 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %23
%30 = load i32*, i32** %5
%31 = call i32 @pclose(i32* %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [57 x i8] c"wlanctl-ng wlan0 lnxreq_wlansniff channel=%d enable=true\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [11 x i8] c"message=%c\00"
@.str.4 = [37 x i8] c"Could not put into promiscuous mode!\00"
define i32 @set_channel(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = call i32 @pclose(i32* %7)
ret i32 %8
}