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

/* Variables and functions */
int read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int set_load(int fd, int channel, int value) {
  unsigned char message[3];
  int n;
  message[0] = 7;
  message[1] = value;
  message[2] = channel;
  write(fd, message, 3);
  usleep(100000);
  n = read(fd, message, 1);
  return n != 1 || message[0] != 'k';
}


x86 assembly (clang, -O0):
<set_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movb   $0x7,-0xf(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0xd(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jne    119c <set_load+0x6c>
movzbl -0xf(%rbp),%eax
cmp    $0x6b,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_load>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x7,0x5(%rsp)
mov    %dl,0x6(%rsp)
mov    %sil,0x7(%rsp)
lea    0x5(%rsp),%r14
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
setne  %al
cmpb   $0x6b,0x5(%rsp)
setne  %cl
or     %al,%cl
movzbl %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @set_load(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
store i8 7, i8* %9
%10 = load i32, i32* %6
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
store i8 %11, i8* %12
%13 = load i32, i32* %5
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2
store i8 %14, i8* %15
%16 = load i32, i32* %4
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 3)
%19 = call i32 @usleep(i32 100000)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 1)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 1
br i1 %24, label %30, label %25
25: ; preds = %3
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %28, 107
br label %30
30: ; preds = %25, %3
%31 = phi i1 [ true, %3 ], [ %29, %25 ]
%32 = zext i1 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
define i32 @set_load(i32 %0, i32 %1, i32 %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
store i8 7, i8* %5
%6 = trunc i32 %2 to i8
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %6, i8* %7
%8 = trunc i32 %1 to i8
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 %8, i8* %9
%10 = call i32 @write(i32 %0, i8* %5, i32 3)
%11 = tail call i32 @usleep(i32 100000)
%12 = call i32 @read(i32 %0, i8* %5, i32 1)
%13 = icmp ne i32 %12, 1
%14 = load i8, i8* %5
%15 = icmp ne i8 %14, 107
%16 = select i1 %13, i1 true, i1 %15
%17 = zext i1 %16 to i32
ret i32 %17
}