#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*/ eeprom_put_char(unsigned int, unsigned char);
void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source,
                                    unsigned int size) {
  unsigned char checksum = 0;
  for (; size > 0; size--) {
    checksum = (checksum << 1) || (checksum >> 7);
    checksum += *source;
    eeprom_put_char(destination++, *(source++));
  }
  eeprom_put_char(destination, checksum);
}


x86 assembly (clang, -O0):
<memcpy_to_eeprom_with_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    11a0 <memcpy_to_eeprom_with_checksum+0x90>
movzbl -0x15(%rbp),%ecx
shl    $0x1,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x16(%rbp)
jne    1155 <memcpy_to_eeprom_with_checksum+0x45>
movzbl -0x15(%rbp),%eax
sar    $0x7,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
movzbl -0x15(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1030 <eeprom_put_char@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <memcpy_to_eeprom_with_checksum+0x16>
mov    -0x4(%rbp),%edi
movzbl -0x15(%rbp),%esi
call   1030 <eeprom_put_char@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy_to_eeprom_with_checksum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
test   %edx,%edx
je     1156 <memcpy_to_eeprom_with_checksum+0x46>
mov    %rsi,%r15
mov    %edx,%r12d
mov    %r14d,%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
nop
lea    (%rbx,%r13,1),%edi
movzbl (%r15,%rbx,1),%esi
cmp    $0x1,%bpl
mov    %esi,%ebp
sbb    $0xff,%bpl
call   1030 <eeprom_put_char@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <memcpy_to_eeprom_with_checksum+0x20>
add    %ebx,%r14d
jmp    1158 <memcpy_to_eeprom_with_checksum+0x48>
xor    %ebp,%ebp
movzbl %bpl,%esi
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <eeprom_put_char@plt>

LLVM IR (-O0):
define void @memcpy_to_eeprom_with_checksum(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8 0, i8* %7
br label %8
8: ; preds = %38, %3
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = load i8, i8* %7
%13 = zext i8 %12 to i32
%14 = shl i32 %13, 1
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8, i8* %7
%18 = zext i8 %17 to i32
%19 = ashr i32 %18, 7
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ true, %11 ], [ %20, %16 ]
%23 = zext i1 %22 to i32
%24 = trunc i32 %23 to i8
store i8 %24, i8* %7
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8, i8* %7
%29 = zext i8 %28 to i32
%30 = add nsw i32 %29, %27
%31 = trunc i32 %30 to i8
store i8 %31, i8* %7
%32 = load i32, i32* %4
%33 = add i32 %32, 1
store i32 %33, i32* %4
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8, i8* %34
%37 = call i32 @eeprom_put_char(i32 %32, i8 zeroext %36)
br label %38
38: ; preds = %21
%39 = load i32, i32* %6
%40 = add i32 %39, -1
store i32 %40, i32* %6
br label %8
41: ; preds = %8
%42 = load i32, i32* %4
%43 = load i8, i8* %7
%44 = call i32 @eeprom_put_char(i32 %42, i8 zeroext %43)
ret void
}

LLVM IR (-O2):
define void @memcpy_to_eeprom_with_checksum(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3, %5
%6 = phi i8 [ %13, %5 ], [ 0, %3 ]
%7 = phi i32 [ %17, %5 ], [ %2, %3 ]
%8 = phi i8* [ %15, %5 ], [ %1, %3 ]
%9 = phi i32 [ %14, %5 ], [ %0, %3 ]
%10 = icmp ne i8 %6, 0
%11 = load i8, i8* %8
%12 = zext i1 %10 to i8
%13 = add i8 %11, %12
%14 = add i32 %9, 1
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = tail call i32 @eeprom_put_char(i32 %9, i8 zeroext %11)
%17 = add i32 %7, -1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %5, %3
%20 = phi i32 [ %0, %3 ], [ %14, %5 ]
%21 = phi i8 [ 0, %3 ], [ %13, %5 ]
%22 = tail call i32 @eeprom_put_char(i32 %20, i8 zeroext %21)
ret void
}