#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 sendAddress(int fd, unsigned addr) {
  unsigned char data[5];
  data[0] = addr >> 24;
  data[1] = addr >> 16;
  data[2] = addr >> 8;
  data[3] = addr;
  data[4] = data[0] ^ data[1] ^ data[2] ^ data[3];
  if (write(fd, data, 5) != 5)
    return -1;
  if (readAck(fd))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<sendAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x11(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
mov    %al,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xe(%rbp)
movzbl -0x11(%rbp),%eax
movzbl -0x10(%rbp),%ecx
xor    %ecx,%eax
movzbl -0xf(%rbp),%ecx
xor    %ecx,%eax
movzbl -0xe(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
cmp    $0x5,%eax
je     118e <sendAddress+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <sendAddress+0x93>
mov    -0x8(%rbp),%edi
call   1040 <readAck@plt>
cmp    $0x0,%rax
je     11ac <sendAddress+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <sendAddress+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendAddress>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,%eax
shr    $0x18,%eax
mov    %al,0xb(%rsp)
mov    %esi,%ecx
shr    $0x10,%ecx
mov    %cl,0xc(%rsp)
mov    %esi,%edx
shr    $0x8,%edx
mov    %dl,0xd(%rsp)
mov    %sil,0xe(%rsp)
xor    %esi,%ecx
xor    %eax,%edx
xor    %ecx,%edx
mov    %dl,0xf(%rsp)
lea    0xb(%rsp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x5,%ecx
jne    1178 <sendAddress+0x58>
mov    %ebx,%edi
call   1040 <readAck@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @sendAddress(i32 %0, i32 %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = lshr i32 %1, 24
%6 = trunc i32 %5 to i8
store i8 %6, i8* %4
%7 = lshr i32 %1, 16
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
store i8 %8, i8* %9
%10 = lshr i32 %1, 8
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
store i8 %11, i8* %12
%13 = trunc i32 %1 to i8
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
store i8 %13, i8* %14
%15 = xor i32 %7, %1
%16 = xor i32 %15, %5
%17 = xor i32 %16, %10
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
store i8 %18, i8* %19
%20 = call i32 @write(i32 %0, i8* %4, i32 5)
%21 = icmp eq i32 %20, 5
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = tail call i64 @readAck(i32 %0)
%24 = icmp ne i64 %23, 0
%25 = sext i1 %24 to i32
br label %26
26: ; preds = %22, %2
%27 = phi i32 [ -1, %2 ], [ %25, %22 ]
ret i32 %27
}