#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 */
typedef struct TYPE_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int m;
};
struct TYPE_4__ {
  char *pointer;
  int length;
  scalar_t__ flags;
};
struct TYPE_5__ {
  TYPE_3__ freq;
  TYPE_1__ data;
};
struct iwreq {
  TYPE_2__ u;
  int /*<<< orphan*/ ifr_name;
};
struct iw_range {
  int num_frequency;
  TYPE_3__ *freq;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIWRANGE;
int /*<<< orphan*/ SIOCSIWFREQ;
int /*<<< orphan*/ bzero(char *, int);
int ioctl(int const, int /*<<< orphan*/, struct iwreq *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
void channel_traverse(const int socket, const char *device_name) {
  struct iwreq wrq;
  char buf[sizeof(struct iw_range) * 2];
  int ret;
  bzero(buf, sizeof(buf));
  wrq.u.data.pointer = buf;
  wrq.u.data.length = sizeof(buf);
  wrq.u.data.flags = 0;
  strncpy(wrq.ifr_name, device_name, IFNAMSIZ);
  if ((ret = ioctl(socket, SIOCGIWRANGE, &wrq)) >= 0) {
    struct iw_range *range = (struct iw_range *)buf;
    int k;
    for (k = 0; k < range->num_frequency; k++) {
      wrq.u.freq = range->freq[k];
      ioctl(socket, SIOCSIWFREQ, &wrq);
      printf("%d\n", range->freq[k].m);
      usleep(500000);
    }
  }
}


x86 assembly (clang, -O0):
<channel_traverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x20,%esi
call   1060 <bzero@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x20,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jl     123a <channel_traverse+0xea>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    -0x70(%rbp),%rcx
cmp    (%rcx),%eax
jge    1235 <channel_traverse+0xe5>
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1070 <usleep@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11cc <channel_traverse+0x7c>
jmp    123a <channel_traverse+0xea>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<channel_traverse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1060 <bzero@plt>
mov    %r15,0x30(%rsp)
movl   $0x20,0x38(%rsp)
movq   $0x0,0x40(%rsp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %eax,%eax
js     1211 <channel_traverse+0xc1>
cmpl   $0x0,(%rsp)
jle    1211 <channel_traverse+0xc1>
xor    %ebx,%ebx
mov    0x2e10(%rip),%r12
lea    0x28(%rsp),%r14
lea    0xe34(%rip),%r15
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%eax
mov    %eax,0x28(%rsp)
mov    (%r12),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1070 <usleep@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <channel_traverse+0x80>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_4__ = type { i8*, i32, i64 }
%struct.iw_range = type { i32, %struct.TYPE_6__* }
@IFNAMSIZ = global i32 0
@SIOCGIWRANGE = global i32 0
@SIOCSIWFREQ = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define void @channel_traverse(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.iwreq
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca %struct.iw_range*
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%11 = call i32 @bzero(i8* %10, i32 32)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %5, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %14, i32 0, i32 0
store i8* %12, i8** %15
%16 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %5, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %16, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 1
store i32 32, i32* %18
%19 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %5, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %19, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 2
store i64 0, i64* %21
%22 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %5, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %4
%25 = load i32, i32* @IFNAMSIZ
%26 = call i32 @strncpy(i32 %23, i8* %24, i32 %25)
%27 = load i32, i32* %3
%28 = load i32, i32* @SIOCGIWRANGE
%29 = call i32 @ioctl(i32 %27, i32 %28, %struct.iwreq* %5)
store i32 %29, i32* %7
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %2
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%33 = bitcast i8* %32 to %struct.iw_range*
store %struct.iw_range* %33, %struct.iw_range** %8
store i32 0, i32* %9
br label %34
34: ; preds = %64, %31
%35 = load i32, i32* %9
%36 = load %struct.iw_range*, %struct.iw_range** %8
%37 = getelementptr inbounds %struct.iw_range, %struct.iw_range* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = icmp slt i32 %35, %38
br i1 %39, label %40, label %67
40: ; preds = %34
%41 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %5, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %41, i32 0, i32 0
%43 = load %struct.iw_range*, %struct.iw_range** %8
%44 = getelementptr inbounds %struct.iw_range, %struct.iw_range* %43, i32 0, i32 1
%45 = load %struct.TYPE_6__*, %struct.TYPE_6__** %44
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %45, i64 %47
%49 = bitcast %struct.TYPE_6__* %42 to i8*
%50 = bitcast %struct.TYPE_6__* %48 to i8*
%51 = load i32, i32* %3
%52 = load i32, i32* @SIOCSIWFREQ
%53 = call i32 @ioctl(i32 %51, i32 %52, %struct.iwreq* %5)
%54 = load %struct.iw_range*, %struct.iw_range** %8
%55 = getelementptr inbounds %struct.iw_range, %struct.iw_range* %54, i32 0, i32 1
%56 = load %struct.TYPE_6__*, %struct.TYPE_6__** %55
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %56, i64 %58
%60 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %61)
%63 = call i32 @usleep(i32 500000)
br label %64
64: ; preds = %40
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %34
67: ; preds = %34
br label %68
68: ; preds = %67, %2
ret void
}

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { %struct.TYPE_6__, %struct.TYPE_4__ }
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_4__ = type { i8*, i32, i64 }
@IFNAMSIZ = global i32 0
@SIOCGIWRANGE = global i32 0
@SIOCSIWFREQ = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define void @channel_traverse(i32 %0, i8* %1) {
%3 = alloca %struct.iwreq
%4 = alloca [32 x i8]
%5 = bitcast %struct.iwreq* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 32)
%8 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i64 0, i32 0, i32 1, i32 0
store i8* %6, i8** %8
%9 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i64 0, i32 0, i32 1, i32 1
store i32 32, i32* %9
%10 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i64 0, i32 0, i32 1, i32 2
store i64 0, i64* %10
%11 = load i32, i32* @IFNAMSIZ
%12 = call i32 @strncpy(i32 undef, i8* %1, i32 %11)
%13 = load i32, i32* @SIOCGIWRANGE
%14 = call i32 @ioctl(i32 %0, i32 %13, %struct.iwreq* %3)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %40
16: ; preds = %2
%17 = bitcast [32 x i8]* %4 to i32*
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 8
%22 = bitcast i8* %21 to %struct.TYPE_6__**
%23 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %3, i64 0, i32 0, i32 0, i32 0
br label %24
24: ; preds = %20, %24
%25 = phi i64 [ 0, %20 ], [ %36, %24 ]
%26 = load %struct.TYPE_6__*, %struct.TYPE_6__** %22
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %26, i64 %25, i32 0
%28 = load i32, i32* %27
store i32 %28, i32* %23
%29 = load i32, i32* @SIOCSIWFREQ
%30 = call i32 @ioctl(i32 %0, i32 %29, %struct.iwreq* %3)
%31 = load %struct.TYPE_6__*, %struct.TYPE_6__** %22
%32 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %31, i64 %25, i32 0
%33 = load i32, i32* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = call i32 @usleep(i32 500000)
%36 = add nuw nsw i64 %25, 1
%37 = load i32, i32* %17
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %24, label %40
40: ; preds = %24, %16, %2
ret void
}