#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_corr(int fd, int channel, int value) {
  unsigned char message[6];
  int n;
  message[0] = 3;
  message[1] = value & 0xFF;
  message[2] = (value >> 8) & 0xFF;
  message[3] = (value >> 16) & 0xFF;
  message[4] = value >> 24;
  message[5] = channel;
  write(fd, message, 6);
  usleep(100000);
  n = read(fd, message, 1);
  return n != 1 || message[0] != 'k';
}


x86 assembly (clang, -O0):
<set_corr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movb   $0x3,-0x12(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0xd(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jne    11c6 <set_corr+0x96>
movzbl -0x12(%rbp),%eax
cmp    $0x6b,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_corr>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x3,0x2(%rsp)
mov    %dl,0x3(%rsp)
mov    %dh,0x4(%rsp)
mov    %edx,%eax
shr    $0x10,%eax
mov    %al,0x5(%rsp)
shr    $0x18,%edx
mov    %dl,0x6(%rsp)
mov    %sil,0x7(%rsp)
lea    0x2(%rsp),%r14
mov    %r14,%rsi
mov    $0x6,%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,0x2(%rsp)
setne  %cl
or     %al,%cl
movzbl %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @set_corr(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [6 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
store i8 3, i8* %9
%10 = load i32, i32* %6
%11 = and i32 %10, 255
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 1
store i8 %12, i8* %13
%14 = load i32, i32* %6
%15 = ashr i32 %14, 8
%16 = and i32 %15, 255
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 2
store i8 %17, i8* %18
%19 = load i32, i32* %6
%20 = ashr i32 %19, 16
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 3
store i8 %22, i8* %23
%24 = load i32, i32* %6
%25 = ashr i32 %24, 24
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 4
store i8 %26, i8* %27
%28 = load i32, i32* %5
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 5
store i8 %29, i8* %30
%31 = load i32, i32* %4
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 6)
%34 = call i32 @usleep(i32 100000)
%35 = load i32, i32* %4
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%37 = call i32 @read(i32 %35, i8* %36, i32 1)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 1
br i1 %39, label %45, label %40
40: ; preds = %3
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp ne i32 %43, 107
br label %45
45: ; preds = %40, %3
%46 = phi i1 [ true, %3 ], [ %44, %40 ]
%47 = zext i1 %46 to i32
ret i32 %47
}

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