#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 */
struct iio_channel {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ iio_channel_is_enabled(struct iio_channel const *);
scalar_t__ local_write_chn_attr(struct iio_channel const *, char *, char *,
                                int);
int channel_write_state(const struct iio_channel *chn) {
  char *en = iio_channel_is_enabled(chn) ? "1" : "0";
  ssize_t ret = local_write_chn_attr(chn, "en", en, 2);
  if (ret < 0)
    return (int)ret;
  else
    return 0;
}


x86 assembly (clang, -O0):
<channel_write_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <iio_channel_is_enabled@plt>
mov    %rax,%rdx
lea    0xec3(%rip),%rax
lea    0xeba(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xea3(%rip),%rsi
mov    $0x2,%ecx
call   1040 <local_write_chn_attr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1186 <channel_write_state+0x66>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    118d <channel_write_state+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<channel_write_state>:
push   %rbx
mov    %rdi,%rbx
call   1030 <iio_channel_is_enabled@plt>
test   %rax,%rax
lea    0xecf(%rip),%rax
lea    0xec6(%rip),%rdx
cmove  %rax,%rdx
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%ecx
call   1040 <local_write_chn_attr@plt>
mov    %rax,%rcx
sar    $0x3f,%rcx
and    %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.iio_channel = type { i32 }
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"en\00"
define i32 @channel_write_state(%struct.iio_channel* %0) {
%2 = alloca i32
%3 = alloca %struct.iio_channel*
%4 = alloca i8*
%5 = alloca i64
store %struct.iio_channel* %0, %struct.iio_channel** %3
%6 = load %struct.iio_channel*, %struct.iio_channel** %3
%7 = call i64 @iio_channel_is_enabled(%struct.iio_channel* %6)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
store i8* %10, i8** %4
%11 = load %struct.iio_channel*, %struct.iio_channel** %3
%12 = load i8*, i8** %4
%13 = call i64 @local_write_chn_attr(%struct.iio_channel* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 2)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i64, i64* %5
%18 = trunc i64 %17 to i32
store i32 %18, i32* %2
br label %20
19: ; preds = %1
store i32 0, i32* %2
br label %20
20: ; preds = %19, %16
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.iio_channel = type { i32 }
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"en\00"
define i32 @channel_write_state(%struct.iio_channel* %0) {
%2 = tail call i64 @iio_channel_is_enabled(%struct.iio_channel* %0)
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%5 = tail call i64 @local_write_chn_attr(%struct.iio_channel* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 2)
%6 = icmp slt i64 %5, 0
%7 = select i1 %6, i64 %5, i64 0
%8 = trunc i64 %7 to i32
ret i32 %8
}