#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 /*<<< orphan*/ printf(char *);
int readPacket(int, char, char *);
int /*<<< orphan*/ writePacket(int, char, char *, int);
void acquireSynchronization(int fd, char control) {
  int sync = 0;
  char buf;
  int size;
  while (!sync) {
    size = readPacket(fd, control, &buf);
    if (size == 0) {
      writePacket(fd, control, &buf, size);
    } else if (size == 1 && buf == 1) {
      printf("Sending confirmation packet.\n");
      sync = 1;
      writePacket(fd, control, &buf, size);
    }
  }
}


x86 assembly (clang, -O0):
<acquireSynchronization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115e <acquireSynchronization+0x2e>
jmp    11de <acquireSynchronization+0xae>
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rdx
movsbl -0x5(%rbp),%esi
call   1030 <readPacket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1195 <acquireSynchronization+0x65>
mov    -0x4(%rbp),%edi
mov    -0x5(%rbp),%al
mov    -0x14(%rbp),%ecx
lea    -0xd(%rbp),%rdx
movsbl %al,%esi
call   1050 <writePacket@plt>
jmp    11d9 <acquireSynchronization+0xa9>
cmpl   $0x1,-0x14(%rbp)
jne    11d4 <acquireSynchronization+0xa4>
movsbl -0xd(%rbp),%eax
cmp    $0x1,%eax
jne    11d4 <acquireSynchronization+0xa4>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x5(%rbp),%al
mov    -0x14(%rbp),%ecx
lea    -0xd(%rbp),%rdx
movsbl %al,%esi
call   1050 <writePacket@plt>
jmp    11d9 <acquireSynchronization+0xa9>
jmp    1148 <acquireSynchronization+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acquireSynchronization>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movsbl %sil,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <readPacket@plt>
test   %eax,%eax
je     1170 <acquireSynchronization+0x40>
cmp    $0x1,%eax
jne    1150 <acquireSynchronization+0x20>
cmpb   $0x1,0xf(%rsp)
jne    1150 <acquireSynchronization+0x20>
jmp    1180 <acquireSynchronization+0x50>
xchg   %ax,%ax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <writePacket@plt>
jmp    1150 <acquireSynchronization+0x20>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rdx
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x1,%ecx
call   1050 <writePacket@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Sending confirmation packet.\0A\00"
define void @acquireSynchronization(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %5
br label %8
8: ; preds = %37, %2
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i32, i32* %3
%14 = load i8, i8* %4
%15 = call i32 @readPacket(i32 %13, i8 signext %14, i8* %6)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* %3
%20 = load i8, i8* %4
%21 = load i32, i32* %7
%22 = call i32 @writePacket(i32 %19, i8 signext %20, i8* %6, i32 %21)
br label %37
23: ; preds = %12
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i8, i8* %6
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
%32 = load i32, i32* %3
%33 = load i8, i8* %4
%34 = load i32, i32* %7
%35 = call i32 @writePacket(i32 %32, i8 signext %33, i8* %6, i32 %34)
br label %36
36: ; preds = %30, %26, %23
br label %37
37: ; preds = %36, %18
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
@str = [29 x i8] c"Sending confirmation packet.\00"
define void @acquireSynchronization(i32 %0, i8 signext %1) {
%3 = alloca i8
br label %4
4: ; preds = %14, %2
%5 = call i32 @readPacket(i32 %0, i8 signext %1, i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = call i32 @writePacket(i32 %0, i8 signext %1, i8* %3, i32 0)
br label %14
9: ; preds = %4
%10 = icmp eq i32 %5, 1
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 1
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %15, label %14
14: ; preds = %9, %7
br label %4
15: ; preds = %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%17 = call i32 @writePacket(i32 %0, i8 signext %1, i8* %3, i32 1)
ret void
}