#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 */
unsigned char crc8(char const *, unsigned char);
char getHexOfNibble(unsigned char);
int /*<<< orphan*/ memcpy(char *, char const *, long);
long strlen(char const *);
void sendTagCellShield(char *mem, const char *tag, const char *data) {
  long int tsize = strlen(tag);
  long int dsize = strlen(data);
  unsigned char checksum = crc8(tag, 0);
  checksum = crc8(data, checksum);
  char hex1 = getHexOfNibble(checksum >> 4);
  char hex2 = getHexOfNibble(checksum);
  memcpy(mem, tag, strlen(tag));
  mem[tsize] = '^';
  memcpy(mem + tsize + 1, data, dsize);
  mem[tsize + 1 + dsize] = ':';
  mem[tsize + 2 + dsize] = hex1;
  mem[tsize + 3 + dsize] = hex2;
}


x86 assembly (clang, -O0):
<sendTagCellShield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <crc8@plt>
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
movzbl -0x29(%rbp),%esi
call   1060 <crc8@plt>
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
sar    $0x4,%eax
movzbl %al,%edi
call   1030 <getHexOfNibble@plt>
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%edi
call   1030 <getHexOfNibble@plt>
mov    %al,-0x2b(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x5e,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
add    -0x28(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x2a(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x2,%rcx
add    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2b(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x3,%rcx
add    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendTagCellShield>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <crc8@plt>
movzbl %al,%esi
mov    %r14,%rdi
call   1060 <crc8@plt>
mov    %eax,%ebp
shr    $0x4,%al
movzbl %al,%edi
call   1030 <getHexOfNibble@plt>
mov    %al,0x7(%rsp)
movzbl %bpl,%edi
call   1030 <getHexOfNibble@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
movb   $0x5e,(%r12,%r15,1)
lea    (%r12,%r15,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
add    %r15,%rbx
movb   $0x3a,0x1(%r12,%rbx,1)
mov    0x7(%rsp),%al
mov    %al,0x2(%r12,%rbx,1)
mov    %bpl,0x3(%r12,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sendTagCellShield(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %8
%16 = load i8*, i8** %5
%17 = call zeroext i8 @crc8(i8* %16, i8 zeroext 0)
store i8 %17, i8* %9
%18 = load i8*, i8** %6
%19 = load i8, i8* %9
%20 = call zeroext i8 @crc8(i8* %18, i8 zeroext %19)
store i8 %20, i8* %9
%21 = load i8, i8* %9
%22 = zext i8 %21 to i32
%23 = ashr i32 %22, 4
%24 = trunc i32 %23 to i8
%25 = call signext i8 @getHexOfNibble(i8 zeroext %24)
store i8 %25, i8* %10
%26 = load i8, i8* %9
%27 = call signext i8 @getHexOfNibble(i8 zeroext %26)
store i8 %27, i8* %11
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i8*, i8** %5
%31 = call i64 @strlen(i8* %30)
%32 = call i32 @memcpy(i8* %28, i8* %29, i64 %31)
%33 = load i8*, i8** %4
%34 = load i64, i64* %7
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 94, i8* %35
%36 = load i8*, i8** %4
%37 = load i64, i64* %7
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8*, i8** %6
%41 = load i64, i64* %8
%42 = call i32 @memcpy(i8* %39, i8* %40, i64 %41)
%43 = load i8*, i8** %4
%44 = load i64, i64* %7
%45 = add nsw i64 %44, 1
%46 = load i64, i64* %8
%47 = add nsw i64 %45, %46
%48 = getelementptr inbounds i8, i8* %43, i64 %47
store i8 58, i8* %48
%49 = load i8, i8* %10
%50 = load i8*, i8** %4
%51 = load i64, i64* %7
%52 = add nsw i64 %51, 2
%53 = load i64, i64* %8
%54 = add nsw i64 %52, %53
%55 = getelementptr inbounds i8, i8* %50, i64 %54
store i8 %49, i8* %55
%56 = load i8, i8* %11
%57 = load i8*, i8** %4
%58 = load i64, i64* %7
%59 = add nsw i64 %58, 3
%60 = load i64, i64* %8
%61 = add nsw i64 %59, %60
%62 = getelementptr inbounds i8, i8* %57, i64 %61
store i8 %56, i8* %62
ret void
}

LLVM IR (-O2):
define void @sendTagCellShield(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = tail call zeroext i8 @crc8(i8* %1, i8 zeroext 0)
%7 = tail call zeroext i8 @crc8(i8* %2, i8 zeroext %6)
%8 = lshr i8 %7, 4
%9 = tail call signext i8 @getHexOfNibble(i8 zeroext %8)
%10 = tail call signext i8 @getHexOfNibble(i8 zeroext %7)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%12 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 94, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = tail call i32 @memcpy(i8* %14, i8* %2, i64 %5)
%16 = add i64 %5, %4
%17 = add i64 %16, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 58, i8* %18
%19 = add i64 %16, 2
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 %9, i8* %20
%21 = add i64 %16, 3
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %10, i8* %22
ret void
}