#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*/ HekrSendByte(unsigned char);
unsigned char SumCalculate(unsigned char *);
void HekrSendFrame(unsigned char *data) {
  unsigned char len = data[1];
  unsigned char i = 0;
  data[len - 1] = SumCalculate(data);
  for (i = 0; i < len; i++) {
    HekrSendByte(data[i]);
  }
}


x86 assembly (clang, -O0):
<HekrSendFrame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <SumCalculate@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0x9(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    1188 <HekrSendFrame+0x68>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
movzbl (%rax,%rcx,1),%edi
call   1030 <HekrSendByte@plt>
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    115a <HekrSendFrame+0x3a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HekrSendFrame>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movzbl 0x1(%rdi),%r14d
call   1040 <SumCalculate@plt>
mov    %al,-0x1(%r14,%r15,1)
test   %r14,%r14
je     1153 <HekrSendFrame+0x33>
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%edi
call   1030 <HekrSendByte@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <HekrSendFrame+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @HekrSendFrame(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
store i8 %7, i8* %3
store i8 0, i8* %4
%8 = load i8*, i8** %2
%9 = call zeroext i8 @SumCalculate(i8* %8)
%10 = load i8*, i8** %2
%11 = load i8, i8* %3
%12 = zext i8 %11 to i32
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 %9, i8* %15
store i8 0, i8* %4
br label %16
16: ; preds = %29, %1
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = load i8, i8* %3
%20 = zext i8 %19 to i32
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = load i8, i8* %4
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @HekrSendByte(i8 zeroext %27)
br label %29
29: ; preds = %22
%30 = load i8, i8* %4
%31 = add i8 %30, 1
store i8 %31, i8* %4
br label %16
32: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @HekrSendFrame(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = tail call zeroext i8 @SumCalculate(i8* %0)
%5 = zext i8 %3 to i64
%6 = add nsw i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %4, i8* %7
%8 = icmp eq i8 %3, 0
br i1 %8, label %16, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %14, %9 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @HekrSendByte(i8 zeroext %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %9
16: ; preds = %9, %1
ret void
}