#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*/ system_str;

/* Variables and functions */
scalar_t__ get_wifi_client_status();
int get_wlan0_channel();
int get_wlan1_channel();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  int wlan0_channel = 0;
  int wlan1_channel = 0;
  int cur_wifi_client_status = 0;
  int old_wifi_client_status = 0;
  int connect_flag = 0;
  char system_str[128] = "\0";
  memset(system_str, 0, sizeof(system_str));
  while (1) {
    if ((wlan0_channel = get_wlan0_channel()) != 0 &&
        (wlan1_channel = get_wlan1_channel()) != 0 &&
        get_wifi_client_status()) {
      connect_flag = 1;
      if (wlan0_channel != wlan1_channel) {
        printf("wlan0_channel=%d,wlan1_channel=%d\n", wlan0_channel,
               wlan1_channel);
        sprintf(system_str, "iw wlan0 set channel %d", wlan1_channel);
        system(system_str);
        printf("%s\n", system_str);
        memset(system_str, 0, sizeof(system_str));
      }
    }
    old_wifi_client_status = cur_wifi_client_status;
    sleep(60);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1070 <get_wlan0_channel@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     128f <main+0x10f>
mov    $0x0,%al
call   1060 <get_wlan1_channel@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     128f <main+0x10f>
mov    $0x0,%al
call   1080 <get_wifi_client_status@plt>
cmp    $0x0,%rax
je     128f <main+0x10f>
movl   $0x1,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     128a <main+0x10a>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdd2(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <system@plt>
lea    -0xb0(%rbp),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
jmp    128f <main+0x10f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    11e2 <main+0x62>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
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)
movaps %xmm0,(%rsp)
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe1e(%rip),%r14
lea    0xe3a(%rip),%r15
jmp    11fa <main+0x6a>
nopl   0x0(%rax,%rax,1)
mov    $0x3c,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
call   1080 <get_wlan0_channel@plt>
test   %eax,%eax
je     11f0 <main+0x60>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <get_wlan1_channel@plt>
test   %eax,%eax
je     11f0 <main+0x60>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <get_wifi_client_status@plt>
test   %rax,%rax
je     11f0 <main+0x60>
cmp    %ebx,%ebp
je     11f0 <main+0x60>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
jmp    11f0 <main+0x60>

LLVM IR (-O0):
@.str = [35 x i8] c"wlan0_channel=%d,wlan1_channel=%d\0A\00"
@.str.1 = [24 x i8] c"iw wlan0 set channel %d\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = bitcast [128 x i8]* %11 to i8*
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 128)
br label %15
15: ; preds = %2, %42
%16 = call i32 (...) @get_wlan0_channel()
store i32 %16, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = call i32 (...) @get_wlan1_channel()
store i32 %19, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = call i64 (...) @get_wifi_client_status()
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %21
store i32 1, i32* %10
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %41
28: ; preds = %24
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%33 = load i32, i32* %7
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%36 = call i32 @system(i8* %35)
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 128)
br label %41
41: ; preds = %28, %24
br label %42
42: ; preds = %41, %21, %18, %15
%43 = load i32, i32* %8
store i32 %43, i32* %9
%44 = call i32 @sleep(i32 60)
br label %15
}

LLVM IR (-O2):
@.str = [35 x i8] c"wlan0_channel=%d,wlan1_channel=%d\0A\00"
@.str.1 = [24 x i8] c"iw wlan0 set channel %d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
br label %6
6: ; preds = %23, %2
%7 = call i32 (...) @get_wlan0_channel()
%8 = icmp eq i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = call i32 (...) @get_wlan1_channel()
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = call i64 (...) @get_wifi_client_status()
%14 = icmp eq i64 %13, 0
%15 = icmp eq i32 %7, %10
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%20 = call i32 @system(i8* %4)
%21 = call i32 @puts(i8* %4)
%22 = call i32 @memset(i8* %4, i32 0, i32 128)
br label %23
23: ; preds = %17, %12, %9, %6
%24 = call i32 @sleep(i32 60)
br label %6
}