#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 crc8(unsigned char const *, unsigned char);
int /*<<< orphan*/ printf(char *, unsigned char const, ...);
void test(unsigned const char *buf, unsigned char len) {
  unsigned char i;
  for (i = 0; i < len - 1; ++i)
    printf("%02x ", buf[i]);
  printf("(%02x) - %02x\n", buf[len - 1], crc8(buf, len));
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0x9(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1170 <test+0x50>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
lea    0xea8(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1136 <test+0x16>
mov    -0x8(%rbp),%rax
movzbl -0x9(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   1040 <crc8@plt>
mov    %eax,%edx
mov    -0xb(%rbp),%al
lea    0xe69(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    %esi,%r15d
add    $0xffffffffffffffff,%r15
cmp    $0x2,%r14b
jb     1169 <test+0x49>
mov    %r15d,%ebp
lea    0xeb8(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <test+0x30>
movzbl 0x0(%r13,%r15,1),%ebp
movzbl %r14b,%esi
mov    %r13,%rdi
call   1040 <crc8@plt>
lea    0xe84(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [15 x i8] c"(%02x) - %02x\0A\00"
define void @test(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
store i8 0, i8* %5
br label %6
6: ; preds = %20, %2
%7 = load i8, i8* %5
%8 = zext i8 %7 to i32
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %8, %11
br i1 %12, label %13, label %23
13: ; preds = %6
%14 = load i8*, i8** %3
%15 = load i8, i8* %5
%16 = zext i8 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %18)
br label %20
20: ; preds = %13
%21 = load i8, i8* %5
%22 = add i8 %21, 1
store i8 %22, i8* %5
br label %6
23: ; preds = %6
%24 = load i8*, i8** %3
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %3
%32 = load i8, i8* %4
%33 = call i32 @crc8(i8* %31, i8 zeroext %32)
%34 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %30, i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [15 x i8] c"(%02x) - %02x\0A\00"
define void @test(i8* %0, i8 zeroext %1) {
%3 = zext i8 %1 to i32
%4 = add nsw i32 %3, -1
%5 = icmp ugt i8 %1, 1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %2
%16 = sext i32 %4 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @crc8(i8* %0, i8 zeroext %1)
%20 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %18, i32 %19)
ret void
}