#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*/ getSync(int, char);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ readSerial(int, char *, char);
int readPacket(int fd, char control, char *data) {
  char sizeByte, tempByte;
  read(fd, &tempByte, 1);
  if (tempByte != control) {
    getSync(fd, control);
    sizeByte = -1;
  } else {
    readSerial(fd, &sizeByte, 1);
    readSerial(fd, data, sizeByte);
  }
  return sizeByte;
}


x86 assembly (clang, -O0):
<readPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl -0x12(%rbp),%eax
movsbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
je     117b <readPacket+0x4b>
mov    -0x4(%rbp),%edi
movsbl -0x5(%rbp),%esi
call   1050 <getSync@plt>
movb   $0xff,-0x11(%rbp)
jmp    119c <readPacket+0x6c>
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <readSerial@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1040 <readSerial@plt>
movsbl -0x11(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readPacket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    %bpl,0xf(%rsp)
jne    117c <readPacket+0x4c>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <readSerial@plt>
movsbl 0xe(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <readSerial@plt>
movsbl 0xe(%rsp),%eax
jmp    118c <readPacket+0x5c>
movsbl %bpl,%esi
mov    %ebx,%edi
call   1050 <getSync@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readPacket(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = call i32 @read(i32 %9, i8* %8, i32 1)
%11 = load i8, i8* %8
%12 = sext i8 %11 to i32
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* %4
%18 = load i8, i8* %5
%19 = call i32 @getSync(i32 %17, i8 signext %18)
store i8 -1, i8* %7
br label %27
20: ; preds = %3
%21 = load i32, i32* %4
%22 = call i32 @readSerial(i32 %21, i8* %7, i8 signext 1)
%23 = load i32, i32* %4
%24 = load i8*, i8** %6
%25 = load i8, i8* %7
%26 = call i32 @readSerial(i32 %23, i8* %24, i8 signext %25)
br label %27
27: ; preds = %20, %16
%28 = load i8, i8* %7
%29 = sext i8 %28 to i32
ret i32 %29
}

LLVM IR (-O2):
define i32 @readPacket(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = call i32 @read(i32 %0, i8* %5, i32 1)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, %1
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @getSync(i32 %0, i8 signext %1)
br label %17
11: ; preds = %3
%12 = call i32 @readSerial(i32 %0, i8* %4, i8 signext 1)
%13 = load i8, i8* %4
%14 = call i32 @readSerial(i32 %0, i8* %2, i8 signext %13)
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
br label %17
17: ; preds = %11, %9
%18 = phi i32 [ %16, %11 ], [ -1, %9 ]
ret i32 %18
}