#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*/ BootActivate();
int UartReceiveByte(unsigned char *);
void BootComUartCheckActivationRequest(void) {
  static unsigned char xcpCtoReqPacket[(64) + 1];
  static unsigned char xcpCtoRxLength;
  static unsigned char xcpCtoRxInProgress = 0;
  if (xcpCtoRxInProgress == 0) {
    if (UartReceiveByte(&xcpCtoReqPacket[0]) == 1) {
      xcpCtoRxInProgress = 1;
      xcpCtoRxLength = 0;
    }
  } else {
    if (UartReceiveByte(&xcpCtoReqPacket[xcpCtoRxLength + 1]) == 1) {
      xcpCtoRxLength++;
      if (xcpCtoRxLength == xcpCtoReqPacket[0]) {
        xcpCtoRxInProgress = 0;
        if ((xcpCtoReqPacket[1] == 0xff) && (xcpCtoReqPacket[2] == 0x00)) {
          BootActivate();
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<BootComUartCheckActivationRequest>:
push   %rbp
mov    %rsp,%rbp
movzbl 0x2f57(%rip),%eax
cmp    $0x0,%eax
jne    115c <BootComUartCheckActivationRequest+0x3c>
lea    0x2f05(%rip),%rdi
call   1040 <UartReceiveByte@plt>
cmp    $0x1,%eax
jne    1157 <BootComUartCheckActivationRequest+0x37>
movb   $0x1,0x2f32(%rip)
movb   $0x0,0x2f2a(%rip)
jmp    11e3 <BootComUartCheckActivationRequest+0xc3>
movzbl 0x2f1e(%rip),%eax
add    $0x1,%eax
cltq
lea    0x2ed1(%rip),%rdi
add    %rax,%rdi
call   1040 <UartReceiveByte@plt>
cmp    $0x1,%eax
jne    11de <BootComUartCheckActivationRequest+0xbe>
mov    0x2efb(%rip),%al
add    $0x1,%al
mov    %al,0x2ef3(%rip)
movzbl 0x2eec(%rip),%eax
movzbl 0x2ea4(%rip),%ecx
cmp    %ecx,%eax
jne    11d9 <BootComUartCheckActivationRequest+0xb9>
movb   $0x0,0x2ed7(%rip)
movzbl 0x2e8f(%rip),%eax
cmp    $0xff,%eax
jne    11d4 <BootComUartCheckActivationRequest+0xb4>
movzbl 0x2e7e(%rip),%eax
cmp    $0x0,%eax
jne    11d4 <BootComUartCheckActivationRequest+0xb4>
mov    $0x0,%al
call   1030 <BootActivate@plt>
jmp    11d9 <BootComUartCheckActivationRequest+0xb9>
jmp    11de <BootComUartCheckActivationRequest+0xbe>
jmp    11e3 <BootComUartCheckActivationRequest+0xc3>
pop    %rbp
ret

x86 assembly (clang, -O2):
<BootComUartCheckActivationRequest>:
push   %rax
cmpb   $0x0,0x2f5a(%rip)
je     1181 <BootComUartCheckActivationRequest+0x61>
movzbl 0x2f50(%rip),%eax
lea    0x2f08(%rip),%rcx
lea    (%rax,%rcx,1),%rdi
add    $0x1,%rdi
call   1040 <UartReceiveByte@plt>
cmp    $0x1,%eax
jne    11a0 <BootComUartCheckActivationRequest+0x80>
mov    0x2f31(%rip),%al
add    $0x1,%al
mov    %al,0x2f29(%rip)
cmp    0x2ee2(%rip),%al
jne    11a0 <BootComUartCheckActivationRequest+0x80>
movb   $0x0,0x2f1b(%rip)
cmpb   $0xff,0x2ed3(%rip)
jne    11a0 <BootComUartCheckActivationRequest+0x80>
cmpb   $0x0,0x2ecb(%rip)
jne    11a0 <BootComUartCheckActivationRequest+0x80>
xor    %eax,%eax
pop    %rcx
jmp    1030 <BootActivate@plt>
lea    0x2eb8(%rip),%rdi
call   1040 <UartReceiveByte@plt>
cmp    $0x1,%eax
jne    11a0 <BootComUartCheckActivationRequest+0x80>
movb   $0x1,0x2ee9(%rip)
movb   $0x0,0x2ee1(%rip)
pop    %rax
ret

LLVM IR (-O0):
@BootComUartCheckActivationRequest.xcpCtoReqPacket = internal global [65 x i8] zeroinitializer
@BootComUartCheckActivationRequest.xcpCtoRxLength = internal global i8 0
@BootComUartCheckActivationRequest.xcpCtoRxInProgress = internal global i8 0
define void @BootComUartCheckActivationRequest() {
%1 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
%2 = zext i8 %1 to i32
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = call i32 @UartReceiveByte(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 0))
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %8
7: ; preds = %4
store i8 1, i8* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
store i8 0, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
br label %8
8: ; preds = %7, %4
br label %38
9: ; preds = %0
%10 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%11 = zext i8 %10 to i32
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 %13
%15 = call i32 @UartReceiveByte(i8* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %37
17: ; preds = %9
%18 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%19 = add i8 %18, 1
store i8 %19, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%20 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%21 = zext i8 %20 to i32
%22 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 0)
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %36
25: ; preds = %17
store i8 0, i8* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
%26 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 1)
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 255
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 2)
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (...) @BootActivate()
br label %35
35: ; preds = %33, %29, %25
br label %36
36: ; preds = %35, %17
br label %37
37: ; preds = %36, %9
br label %38
38: ; preds = %37, %8
ret void
}

LLVM IR (-O2):
@BootComUartCheckActivationRequest.xcpCtoReqPacket = internal global [65 x i8] zeroinitializer
@BootComUartCheckActivationRequest.xcpCtoRxLength = internal unnamed_addr global i8 0
@BootComUartCheckActivationRequest.xcpCtoRxInProgress = internal unnamed_addr global i1 false
define void @BootComUartCheckActivationRequest() {
%1 = load i1, i1* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
br i1 %1, label %6, label %2
2: ; preds = %0
%3 = tail call i32 @UartReceiveByte(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 0))
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %26
5: ; preds = %2
store i1 true, i1* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
store i8 0, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
br label %26
6: ; preds = %0
%7 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%8 = zext i8 %7 to i64
%9 = add nuw nsw i64 %8, 1
%10 = getelementptr inbounds [65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 %9
%11 = tail call i32 @UartReceiveByte(i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %26
13: ; preds = %6
%14 = load i8, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%15 = add i8 %14, 1
store i8 %15, i8* @BootComUartCheckActivationRequest.xcpCtoRxLength
%16 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 0)
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %13
store i1 false, i1* @BootComUartCheckActivationRequest.xcpCtoRxInProgress
%19 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 1)
%20 = icmp eq i8 %19, -1
%21 = load i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @BootComUartCheckActivationRequest.xcpCtoReqPacket, i64 0, i64 2)
%22 = icmp eq i8 %21, 0
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 (...) @BootActivate()
br label %26
26: ; preds = %6, %18, %24, %13, %2, %5
ret void
}