#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ serialRead(int, unsigned char *);
int expectSTX(int fd) {
  unsigned char b;
  serialRead(fd, &b);
  if (b == 0x0F) {
    printf("<STX>");
    return 1;
  } else {
    printf("\n[ERROR, expected STX, got 0x%02x]\n", b);
    close(fd);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<expectSTX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
call   1030 <serialRead@plt>
movzbl -0x5(%rbp),%eax
cmp    $0xf,%eax
jne    117d <expectSTX+0x3d>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret
movzbl -0x5(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<expectSTX>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xf(%rsp),%rsi
call   1030 <serialRead@plt>
movzbl 0xf(%rsp),%esi
cmp    $0xf,%esi
jne    1174 <expectSTX+0x34>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"<STX>\00"
@.str.1 = [36 x i8] c"\0A[ERROR, expected STX, got 0x%02x]\0A\00"
define i32 @expectSTX(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @serialRead(i32 %4, i8* %3)
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp eq i32 %7, 15
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret i32 1
11: ; preds = %1
%12 = load i8, i8* %3
%13 = zext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
%17 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"<STX>\00"
@.str.1 = [36 x i8] c"\0A[ERROR, expected STX, got 0x%02x]\0A\00"
define i32 @expectSTX(i32 %0) {
%2 = alloca i8
%3 = call i32 @serialRead(i32 %0, i8* %2)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 15
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret i32 1
8: ; preds = %1
%9 = zext i8 %4 to i32
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @close(i32 %0)
%12 = call i32 @exit(i32 -1)
unreachable
}