#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*/ printf(char *, ...);
void print_hex(unsigned char *data) {
  unsigned bytes = data[0] + 4;
  unsigned char sum = 0;
  unsigned i;
  printf(":");
  for (i = 0; i < bytes; ++i) {
    printf("%02x", data[i]);
    sum -= data[i];
  }
  printf("%02x\n", sum);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1189 <print_hex+0x79>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%ecx
movzbl -0xd(%rbp),%eax
sub    %ecx,%eax
mov    %al,-0xd(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <print_hex+0x32>
movzbl -0xd(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
movzbl (%rdi),%r15d
mov    $0x3a,%edi
call   1030 <putchar@plt>
add    $0x4,%r15
lea    0xebc(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%eax
sub    %eax,%ebp
add    $0x1,%rbx
movzbl %bpl,%ebp
cmp    %rbx,%r15
jne    1150 <print_hex+0x30>
lea    0xe8b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

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