#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ freq;
};
struct iwreq {
  TYPE_1__ u;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCSIWFREQ;
int /*<<< orphan*/ channel_to_iwfreq(int /*<<< orphan*/ *, int const);
scalar_t__ ioctl(int const, int /*<<< orphan*/, struct iwreq *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int channel_set(const int socket, const char *device_name, const int channel) {
  struct iwreq wrq;
  strncpy(wrq.ifr_name, device_name, IFNAMSIZ);
  channel_to_iwfreq(&wrq.u.freq, channel);
  if (ioctl(socket, SIOCSIWFREQ, &wrq) < 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<channel_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
lea    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <channel_to_iwfreq@plt>
mov    -0x8(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    118e <channel_set+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    1195 <channel_set+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<channel_set>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %edi,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <channel_to_iwfreq@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
shr    $0x3f,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFNAMSIZ = global i32 0
@SIOCSIWFREQ = global i32 0
define i32 @channel_set(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.iwreq
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = load i8*, i8** %6
%12 = load i32, i32* @IFNAMSIZ
%13 = call i32 @strncpy(i32 %10, i8* %11, i32 %12)
%14 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %8, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %7
%17 = call i32 @channel_to_iwfreq(i32* %15, i32 %16)
%18 = load i32, i32* %5
%19 = load i32, i32* @SIOCSIWFREQ
%20 = call i64 @ioctl(i32 %18, i32 %19, %struct.iwreq* %8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %3
store i32 1, i32* %4
br label %24
23: ; preds = %3
store i32 0, i32* %4
br label %24
24: ; preds = %23, %22
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFNAMSIZ = global i32 0
@SIOCSIWFREQ = global i32 0
define i32 @channel_set(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.iwreq
%5 = bitcast %struct.iwreq* %4 to i8*
%6 = load i32, i32* @IFNAMSIZ
%7 = tail call i32 @strncpy(i32 undef, i8* %1, i32 %6)
%8 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0
%9 = call i32 @channel_to_iwfreq(i32* %8, i32 %2)
%10 = load i32, i32* @SIOCSIWFREQ
%11 = call i64 @ioctl(i32 %0, i32 %10, %struct.iwreq* %4)
%12 = lshr i64 %11, 63
%13 = trunc i64 %12 to i32
ret i32 %13
}