#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 */
scalar_t__ readAck(int);
int write(int, unsigned char *, int);
int sendLength(int fd, unsigned len) {
  unsigned char data[2];
  if ((len < 1) || (len > 256))
    return -1;
  len--;
  data[0] = len;
  data[1] = len ^ 0xFF;
  if (write(fd, data, 2) != 2)
    return -1;
  if (readAck(fd))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<sendLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jb     1145 <sendLength+0x25>
cmpl   $0x100,-0xc(%rbp)
jbe    1151 <sendLength+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <sendLength+0x96>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
xor    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1191 <sendLength+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <sendLength+0x96>
mov    -0x8(%rbp),%edi
call   1040 <readAck@plt>
cmp    $0x0,%rax
je     11af <sendLength+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <sendLength+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendLength>:
push   %rbp
push   %rbx
push   %rax
lea    -0x101(%rsi),%eax
mov    $0xffffffff,%ebx
cmp    $0xffffff00,%eax
jb     1166 <sendLength+0x46>
mov    %edi,%ebp
lea    -0x1(%rsi),%eax
mov    %al,0x6(%rsp)
neg    %sil
mov    %sil,0x7(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    1166 <sendLength+0x46>
mov    %ebp,%edi
call   1040 <readAck@plt>
neg    %rax
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sendLength(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp ugt i32 %10, 256
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 -1, i32* %3
br label %34
13: ; preds = %9
%14 = load i32, i32* %5
%15 = add i32 %14, -1
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %17, i8* %18
%19 = load i32, i32* %5
%20 = xor i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %21, i8* %22
%23 = load i32, i32* %4
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%25 = call i32 @write(i32 %23, i8* %24, i32 2)
%26 = icmp ne i32 %25, 2
br i1 %26, label %27, label %28
27: ; preds = %13
store i32 -1, i32* %3
br label %34
28: ; preds = %13
%29 = load i32, i32* %4
%30 = call i64 @readAck(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %3
br label %34
33: ; preds = %28
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %27, %12
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @sendLength(i32 %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = add i32 %1, -257
%6 = icmp ult i32 %5, -256
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = trunc i32 %1 to i8
%9 = add i8 %8, -1
store i8 %9, i8* %4
%10 = sub i8 0, %8
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %10, i8* %11
%12 = call i32 @write(i32 %0, i8* %4, i32 2)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = tail call i64 @readAck(i32 %0)
%16 = icmp ne i64 %15, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %7, %2
%19 = phi i32 [ -1, %2 ], [ -1, %7 ], [ %17, %14 ]
ret i32 %19
}