#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int CheckSum(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ UARTReceive(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ UARTSend(int /*<<< orphan*/ *, int);
int SendPacket(uint8_t *pui8Data, uint32_t ui32Size) {
  uint32_t ui32Temp;
  ui32Temp = CheckSum(pui8Data, ui32Size);
  ui32Size += 2;
  UARTSend((uint8_t *)&ui32Size, 1);
  UARTSend((uint8_t *)&ui32Temp, 1);
  UARTSend(pui8Data, ui32Size - 2);
  ui32Temp = 0;
  while (ui32Temp == 0) {
    UARTReceive((uint8_t *)&ui32Temp, 1);
  }
  if (ui32Temp != 0xcc) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<SendPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <CheckSum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
mov    $0x1,%esi
call   1030 <UARTSend@plt>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <UARTSend@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
call   1030 <UARTSend@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a6 <SendPacket+0x76>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <UARTReceive@plt>
jmp    1189 <SendPacket+0x59>
cmpl   $0xcc,-0x18(%rbp)
je     11bf <SendPacket+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <SendPacket+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendPacket>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1050 <CheckSum@plt>
mov    %eax,(%rsp)
add    $0x2,%ebx
mov    %ebx,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
call   1030 <UARTSend@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <UARTSend@plt>
mov    0x4(%rsp),%esi
add    $0xfffffffe,%esi
mov    %r14,%rdi
call   1030 <UARTSend@plt>
movl   $0x0,(%rsp)
xor    %eax,%eax
test   %eax,%eax
jne    11a4 <SendPacket+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <UARTReceive@plt>
mov    (%rsp),%eax
test   %eax,%eax
je     1190 <SendPacket+0x60>
cmp    $0xcc,%eax
jne    11af <SendPacket+0x7f>
xor    %eax,%eax
jmp    11b4 <SendPacket+0x84>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @SendPacket(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %5
%9 = call i32 @CheckSum(i32* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 2
store i32 %11, i32* %5
%12 = call i32 @UARTSend(i32* %5, i32 1)
%13 = call i32 @UARTSend(i32* %6, i32 1)
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 2
%17 = call i32 @UARTSend(i32* %14, i32 %16)
store i32 0, i32* %6
br label %18
18: ; preds = %21, %2
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @UARTReceive(i32* %6, i32 1)
br label %18
23: ; preds = %18
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 204
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 -1, i32* %3
br label %28
27: ; preds = %23
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @SendPacket(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @CheckSum(i32* %0, i32 %1)
store i32 %6, i32* %4
%7 = add nsw i32 %1, 2
store i32 %7, i32* %3
%8 = call i32 @UARTSend(i32* %3, i32 1)
%9 = call i32 @UARTSend(i32* %4, i32 1)
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -2
%12 = call i32 @UARTSend(i32* %0, i32 %11)
store i32 0, i32* %4
br label %13
13: ; preds = %15, %2
%14 = phi i32 [ %17, %15 ], [ 0, %2 ]
switch i32 %14, label %18 [
i32 0, label %15
i32 204, label %19
]
15: ; preds = %13
%16 = call i32 @UARTReceive(i32* %4, i32 1)
%17 = load i32, i32* %4
br label %13
18: ; preds = %13
br label %19
19: ; preds = %13, %18
%20 = phi i32 [ -1, %18 ], [ 0, %13 ]
ret i32 %20
}