#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_bytes2(char *bytes, int len) {
  unsigned char i;
  for (i = 0; i < len; i++) {
    if (i < len - 1)
      printf("%02x:", bytes[i] & 0xff);
    else
      printf("%02x", bytes[i] & 0xff);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bytes2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <print_bytes2+0x89>
movzbl -0xd(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1167 <print_bytes2+0x57>
mov    -0x8(%rbp),%rax
movzbl -0xd(%rbp),%ecx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1187 <print_bytes2+0x77>
mov    -0x8(%rbp),%rax
movzbl -0xd(%rbp),%ecx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118c <print_bytes2+0x7c>
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
jmp    1123 <print_bytes2+0x13>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bytes2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1172 <print_bytes2+0x52>
mov    %esi,%r13d
mov    %rdi,%r14
lea    -0x1(%r13),%ebp
lea    0xec0(%rip),%r15
lea    0xebf(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
cmp    %ebx,%ebp
mov    %ebx,%eax
movzbl (%r14,%rax,1),%esi
mov    %r12,%rdi
cmovg  %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
movzbl %bl,%ebx
cmp    %r13d,%ebx
jl     1150 <print_bytes2+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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