#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 */
char crc8(char const *, char, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *createProtocolMessage(char *message, const char *tag, const char *data,
                            int len) {
  char checksum = crc8(tag, 0, 2);
  checksum = crc8(data, checksum, len);
  memcpy(message, tag, 2);
  memcpy(message + 2, data, len);
  sprintf(message + 2 + len, ":%.2x", (unsigned char)checksum);
  return message;
}


x86 assembly (clang, -O0):
<createProtocolMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <crc8@plt>
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1d(%rbp),%al
mov    -0x1c(%rbp),%edx
movsbl %al,%esi
call   1040 <crc8@plt>
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe55(%rip),%rsi
movzbl -0x1d(%rbp),%edx
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createProtocolMessage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <crc8@plt>
movsbl %al,%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <crc8@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
lea    0x2(%rbx),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <memcpy@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
movzbl %r12b,%edx
lea    0xe6a(%rip),%rsi
call   1050 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c":%.2x\00"
define i8* @createProtocolMessage(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %6
%11 = call signext i8 @crc8(i8* %10, i8 signext 0, i32 2)
store i8 %11, i8* %9
%12 = load i8*, i8** %7
%13 = load i8, i8* %9
%14 = load i32, i32* %8
%15 = call signext i8 @crc8(i8* %12, i8 signext %13, i32 %14)
store i8 %15, i8* %9
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 @memcpy(i8* %16, i8* %17, i32 2)
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %9
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %29)
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
@.str = [6 x i8] c":%.2x\00"
define i8* @createProtocolMessage(i8* returned %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call signext i8 @crc8(i8* %1, i8 signext 0, i32 2)
%6 = tail call signext i8 @crc8(i8* %2, i8 signext %5, i32 %3)
%7 = tail call i32 @memcpy(i8* %0, i8* %1, i32 2)
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = tail call i32 @memcpy(i8* %8, i8* %2, i32 %3)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %6)
ret i8* %0
}