#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 addrParity(unsigned char);
unsigned char dataChecksumLin(unsigned char *, unsigned char, unsigned char);
void linSend(unsigned char *buffer, unsigned char addr, unsigned char *message,
             unsigned char nBytes, unsigned char proto) {
  unsigned char addrbyte = (addr & 0x3f) | addrParity(addr);
  unsigned char cksum = dataChecksumLin(message, nBytes, addrbyte);
  short p = 0;
  buffer[0] = 0x00;
  buffer[1] = 0x01;
  buffer[2] = 0x55;
  buffer[3] = addrbyte;
  for (p = 0; p < nBytes; p++) {
    buffer[p + 4] = message[p];
  }
  buffer[nBytes + 4] = cksum;
}


x86 assembly (clang, -O0):
<linSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %sil,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0x24(%rbp)
movzbl -0x9(%rbp),%edi
call   1030 <addrParity@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movzbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x1b(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x19(%rbp),%al
movzbl %al,%esi
movzbl -0x1b(%rbp),%edx
call   1040 <dataChecksumLin@plt>
mov    %al,-0x1c(%rbp)
movw   $0x0,-0x1e(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x1,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x55,0x2(%rax)
mov    -0x1b(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
movw   $0x0,-0x1e(%rbp)
movswl -0x1e(%rbp),%eax
movzbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jge    11de <linSend+0xbe>
mov    -0x18(%rbp),%rax
movswq -0x1e(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movswl -0x1e(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1e(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1e(%rbp)
jmp    11a0 <linSend+0x80>
mov    -0x1c(%rbp),%dl
mov    -0x8(%rbp),%rax
movzbl -0x19(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linSend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %esi,%r15d
and    $0x3f,%r15b
mov    %esi,%edi
call   1030 <addrParity@plt>
or     %r15b,%al
movzbl %al,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1040 <dataChecksumLin@plt>
movw   $0x100,(%rbx)
movb   $0x55,0x2(%rbx)
mov    %r15b,0x3(%rbx)
test   %ebp,%ebp
je     1186 <linSend+0x66>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ecx,%rcx
movzbl (%r14,%rcx,1),%edx
mov    %dl,0x4(%rcx,%rbx,1)
add    $0x1,%ecx
movswl %cx,%ecx
cmp    %ebp,%ecx
jl     1170 <linSend+0x50>
movzbl %bpl,%ecx
mov    %al,0x4(%rcx,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @linSend(i8* %0, i8 zeroext %1, i8* %2, i8 zeroext %3, i8 zeroext %4) {
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i16
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i8 %3, i8* %9
store i8 %4, i8* %10
%14 = load i8, i8* %7
%15 = zext i8 %14 to i32
%16 = and i32 %15, 63
%17 = load i8, i8* %7
%18 = call zeroext i8 @addrParity(i8 zeroext %17)
%19 = zext i8 %18 to i32
%20 = or i32 %16, %19
%21 = trunc i32 %20 to i8
store i8 %21, i8* %11
%22 = load i8*, i8** %8
%23 = load i8, i8* %9
%24 = load i8, i8* %11
%25 = call zeroext i8 @dataChecksumLin(i8* %22, i8 zeroext %23, i8 zeroext %24)
store i8 %25, i8* %12
store i16 0, i16* %13
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 0, i8* %27
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 1, i8* %29
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 2
store i8 85, i8* %31
%32 = load i8, i8* %11
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8 %32, i8* %34
store i16 0, i16* %13
br label %35
35: ; preds = %53, %5
%36 = load i16, i16* %13
%37 = sext i16 %36 to i32
%38 = load i8, i8* %9
%39 = zext i8 %38 to i32
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %56
41: ; preds = %35
%42 = load i8*, i8** %8
%43 = load i16, i16* %13
%44 = sext i16 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = load i8*, i8** %6
%48 = load i16, i16* %13
%49 = sext i16 %48 to i32
%50 = add nsw i32 %49, 4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
store i8 %46, i8* %52
br label %53
53: ; preds = %41
%54 = load i16, i16* %13
%55 = add i16 %54, 1
store i16 %55, i16* %13
br label %35
56: ; preds = %35
%57 = load i8, i8* %12
%58 = load i8*, i8** %6
%59 = load i8, i8* %9
%60 = zext i8 %59 to i32
%61 = add nsw i32 %60, 4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %58, i64 %62
store i8 %57, i8* %63
ret void
}

LLVM IR (-O2):
define void @linSend(i8* nocapture writeonly %0, i8 zeroext %1, i8* %2, i8 zeroext %3, i8 zeroext %4) {
%6 = and i8 %1, 63
%7 = tail call zeroext i8 @addrParity(i8 zeroext %1)
%8 = or i8 %7, %6
%9 = tail call zeroext i8 @dataChecksumLin(i8* %2, i8 zeroext %3, i8 zeroext %8)
store i8 0, i8* %0
%10 = getelementptr inbounds i8, i8* %0, i64 1
store i8 1, i8* %10
%11 = getelementptr inbounds i8, i8* %0, i64 2
store i8 85, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %8, i8* %12
%13 = zext i8 %3 to i32
%14 = icmp eq i8 %3, 0
br i1 %14, label %27, label %15
15: ; preds = %5, %15
%16 = phi i32 [ %25, %15 ], [ 0, %5 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %2, i64 %17
%19 = load i8, i8* %18
%20 = add nsw i32 %16, 4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %19, i8* %22
%23 = shl nsw i32 %16, 16
%24 = add i32 %23, 65536
%25 = ashr exact i32 %24, 16
%26 = icmp slt i32 %25, %13
br i1 %26, label %15, label %27
27: ; preds = %15, %5
%28 = add nuw nsw i32 %13, 4
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 %9, i8* %30
ret void
}