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


x86 assembly (clang, -O0):
<sendCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-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     1165 <sendCommand+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <sendCommand+0x6a>
mov    -0x8(%rbp),%edi
call   1040 <readAck@plt>
cmp    $0x0,%rax
je     1183 <sendCommand+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <sendCommand+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendCommand>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %sil,0xe(%rsp)
not    %sil
mov    %sil,0xf(%rsp)
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
jne    115b <sendCommand+0x3b>
mov    %ebx,%edi
call   1040 <readAck@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @sendCommand(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 = trunc i32 %7 to i8
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %8, i8* %9
%10 = load i32, i32* %5
%11 = xor i32 %10, 255
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %12, i8* %13
%14 = load i32, i32* %4
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 2)
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %25
19: ; preds = %2
%20 = load i32, i32* %4
%21 = call i64 @readAck(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %3
br label %25
24: ; preds = %19
store i32 0, i32* %3
br label %25
25: ; preds = %24, %23, %18
%26 = load i32, i32* %3
ret i32 %26
}

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